2332: Allow reorder of Data in the Data tab of Source: make Data SourceAttribute, which have sourcetype,
link with GEPS 018: Evidence This is step 1 needed for GEPS 018. All types are defined needed to evidence style references This commit also contains fix for 6777: Crash on export to GEDCOM when there are addresses svn: r22423
This commit is contained in:
19
data/evidencestyle/README
Normal file
19
data/evidencestyle/README
Normal file
@@ -0,0 +1,19 @@
|
||||
* Original evidence_style downloaded from
|
||||
http://jytangledweb.org/genealogy/evidencestyle/ which are given there
|
||||
for use in genealogy programs
|
||||
|
||||
* Several fixes done in the csv file which I believe were errors
|
||||
|
||||
* Run
|
||||
|
||||
$ python evidencefield.py
|
||||
|
||||
to generate two files with python code usable in srcattrtype.py in Gramps.
|
||||
|
||||
* If in the future one wants to insert _NEW_ evidence styles, add them at the
|
||||
bottom of the csv file, generate the data, and copy to srcattrtype.py
|
||||
|
||||
* CAREFUL: When adding or changing things, DON'T change the type of already
|
||||
released versions in Gramps! That means the integer indexes used must remain
|
||||
the same! If only styles are added at the bottom and no lines removed,
|
||||
this should not be a problem.
|
3154
data/evidencestyle/evidence_style.csv
Normal file
3154
data/evidencestyle/evidence_style.csv
Normal file
File diff suppressed because it is too large
Load Diff
180
data/evidencestyle/evidencefieldgenerator.py
Normal file
180
data/evidencestyle/evidencefieldgenerator.py
Normal file
@@ -0,0 +1,180 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2013 Benny Malengier
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# $Id$
|
||||
|
||||
"""
|
||||
This module parses the evidence csv file and generates the code we need in
|
||||
Gramps to use the evidence style.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Standard Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import csv
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Code
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
csvfilename = "evidence_style.csv"
|
||||
NRCOL = 0
|
||||
CATCOL = 1
|
||||
CATTYPECOL = 2
|
||||
TYPECOL = 3
|
||||
DESCRCOL= 4
|
||||
CITETYPECOL = 5
|
||||
IDENTCOL = 6
|
||||
LDELCOL = 7 # left delimiter
|
||||
FIELDCOL = 8
|
||||
RDELCOL = 9 # right delimiter
|
||||
STYLECOL = 10
|
||||
PRIVACYCOL = 11
|
||||
OPTCOL = 12
|
||||
|
||||
nr = -1
|
||||
cat = ''
|
||||
cattype = ''
|
||||
type = ''
|
||||
descr = ''
|
||||
cite_type = ''
|
||||
ident = ''
|
||||
|
||||
TYPE2CITEMAP = {}
|
||||
FIELDTYPEMAP = {}
|
||||
index = 10
|
||||
indexval = 10
|
||||
first = True
|
||||
|
||||
with open(csvfilename, 'rb') as csvfile:
|
||||
reader = csv.reader(csvfile, delimiter=',')
|
||||
for row in reader:
|
||||
if first:
|
||||
#skip first row with headers
|
||||
first=False
|
||||
continue
|
||||
|
||||
if row[CATCOL]:
|
||||
cat = row[CATCOL]
|
||||
cattype = row[CATTYPECOL]
|
||||
type = row[TYPECOL]
|
||||
descr = row[DESCRCOL]
|
||||
source_type = row[IDENTCOL]
|
||||
if descr:
|
||||
source_descr = '%s - %s - %s (%s)' % (type, cattype, cat, descr)
|
||||
source_descr_code = "_('%(first)s - %(sec)s - %(third)s (%(fourth)s)') % { "\
|
||||
" 'first': _('" + type + "'),"\
|
||||
" 'sec': _('" + cattype + "'),"\
|
||||
" 'third': _('" + cat + "'),"\
|
||||
" 'fourth': _('" + descr + "')}"
|
||||
else:
|
||||
source_descr = '%s - %s - %s' % (type, cattype, cat)
|
||||
source_descr_code = "_('%(first)s - %(sec)s - %(third)s') % { "\
|
||||
" 'first': _('" + type + "'),"\
|
||||
" 'sec': _('" + cattype + "'),"\
|
||||
" 'third': _('" + cat + "')}"
|
||||
if source_type in TYPE2CITEMAP:
|
||||
assert TYPE2CITEMAP[source_type] ['descr'] == source_descr, source_type + ' ' + TYPE2CITEMAP[source_type] ['descr'] + ' NOT ' + source_descr
|
||||
else:
|
||||
TYPE2CITEMAP[source_type] = {'L': [], 'F': [], 'S': [],
|
||||
'i': indexval, 'descr': source_descr,
|
||||
'descrcode': source_descr_code}
|
||||
indexval += 1
|
||||
|
||||
|
||||
if row[CITETYPECOL]:
|
||||
#new citation type,
|
||||
cite_type = row[CITETYPECOL]
|
||||
#add field for template to evidence style
|
||||
field = row[FIELDCOL]
|
||||
field_type = field.replace(' ', '_').replace("'","")\
|
||||
.replace('&','AND').replace('(', '6').replace(')','9')\
|
||||
.replace('[', '').replace(']','').replace('/', '_OR_')\
|
||||
.replace(',', '').replace('.', '').replace(':', '')\
|
||||
.replace('-', '_')
|
||||
field_descr = field.replace('[', '').replace(']','').lower().capitalize()
|
||||
if field_type in FIELDTYPEMAP:
|
||||
assert field_descr == FIELDTYPEMAP[field_type][1], 'Problem %s %s %s' % (field_type, field_descr, FIELDTYPEMAP[field_type][1])
|
||||
else:
|
||||
FIELDTYPEMAP[field_type] = (index, field_descr)
|
||||
index += 1
|
||||
fielddata = []
|
||||
private = 'False'
|
||||
if row[PRIVACYCOL]:
|
||||
private = 'True'
|
||||
optional = 'False'
|
||||
if row[OPTCOL]:
|
||||
optional = 'True'
|
||||
TYPE2CITEMAP[source_type][cite_type] += [(row[LDELCOL], field_type,
|
||||
row[RDELCOL], row[STYLECOL], private, optional)]
|
||||
|
||||
#now generate the python code we need in source attr types
|
||||
code = ""
|
||||
datamap = "\n _DATAMAP += [\n"
|
||||
allkeys = sorted(FIELDTYPEMAP.keys())
|
||||
for field_type in allkeys:
|
||||
code += " " + field_type + ' = %d\n' % FIELDTYPEMAP[field_type][0]
|
||||
datamap += ' (' + field_type + ', _("' + FIELDTYPEMAP[field_type][1] \
|
||||
+'"), "' + FIELDTYPEMAP[field_type][1] + '"),\n'
|
||||
|
||||
code += '\n' + datamap + ' ]\n'
|
||||
|
||||
with open('srcattrtype_extra.py', 'wb') as srcattrfile:
|
||||
srcattrfile.write(code)
|
||||
|
||||
#now generate the python code we need in evidencestyle
|
||||
# we have predefined sourcetypes, and these have a template for formatting
|
||||
#
|
||||
|
||||
#first an English to internationalized map
|
||||
code = " #SRCTYPE has some predefined values which map to citation styles\n"
|
||||
|
||||
datamap = " _SRCTYPEVAL_MAP = [\n"
|
||||
allkeys = sorted(TYPE2CITEMAP.keys())
|
||||
for source_type in allkeys:
|
||||
code += " " + source_type + ' = %d\n' % TYPE2CITEMAP[source_type]['i']
|
||||
# we use descrcode in to translate string to reduce work for translators
|
||||
datamap += ' (' + source_type + ', ' + TYPE2CITEMAP[source_type]['descrcode'] \
|
||||
+', "' + TYPE2CITEMAP[source_type]['descr'] + '"),\n'
|
||||
|
||||
code += '\n # Localization of the different source types\n'\
|
||||
+ datamap + ' ]\n'
|
||||
|
||||
code += "\n #templates for the source types defined\n"
|
||||
code += ' EVIDENCETEMPLATES = {\n'
|
||||
for source_type in allkeys:
|
||||
code += " '" + source_type + "': {\n"
|
||||
for val in ['F', 'L', 'S']:
|
||||
code += " '" + val + "': [\n"
|
||||
for field in TYPE2CITEMAP[source_type][val]:
|
||||
# field is tuple (row[LDELCOL], field_type, row[RDELCOL], row[STYLECOL]
|
||||
# , private, optional)
|
||||
code += " ('"+ field[0] + "', " + field[1] + ", '" + field[2] + \
|
||||
"', '" + field[3] + "', " + field[4] + ", " + field[5] + "),\n"
|
||||
code += " ],\n"
|
||||
code += " },\n"
|
||||
code += " }\n"
|
||||
|
||||
with open('srcattrtype_extraevidence.py', 'wb') as srcattrfile:
|
||||
srcattrfile.write(code)
|
@@ -230,7 +230,7 @@ SOURCES
|
||||
|
||||
<!ELEMENT sources (source)*>
|
||||
<!ELEMENT source (stitle?, sauthor?, spubinfo?, sabbrev?,
|
||||
noteref*, objref*, data_item*, reporef*, tagref*)>
|
||||
noteref*, objref*, srcattribute*, reporef*, tagref*)>
|
||||
<!ATTLIST source
|
||||
id CDATA #IMPLIED
|
||||
handle ID #REQUIRED
|
||||
@@ -369,7 +369,7 @@ CITATIONS
|
||||
<!ELEMENT citations (citation)*>
|
||||
|
||||
<!ELEMENT citation ((daterange|datespan|dateval|datestr)?, page?, confidence?,
|
||||
noteref*, objref*, data_item*, sourceref, tagref*)>
|
||||
noteref*, objref*, srcattribute*, sourceref, tagref*)>
|
||||
<!ATTLIST citation
|
||||
id CDATA #IMPLIED
|
||||
handle ID #REQUIRED
|
||||
@@ -494,6 +494,13 @@ SHARED ELEMENTS
|
||||
value CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT srcattribute EMPTY>
|
||||
<!ATTLIST srcattribute
|
||||
priv (0|1) #IMPLIED
|
||||
type CDATA #REQUIRED
|
||||
value CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT place EMPTY>
|
||||
<!ATTLIST place hlink IDREF #REQUIRED>
|
||||
|
||||
|
@@ -438,9 +438,8 @@
|
||||
<zeroOrMore><element name="objref">
|
||||
<ref name="objref-content"/>
|
||||
</element></zeroOrMore>
|
||||
<zeroOrMore><element name="data_item">
|
||||
<attribute name="key"><text/></attribute>
|
||||
<attribute name="value"><text/></attribute>
|
||||
<zeroOrMore><element name="srcattribute">
|
||||
<ref name="srcattribute-content"/>
|
||||
</element></zeroOrMore>
|
||||
<element name="sourceref">
|
||||
<ref name="sourceref-content"/>
|
||||
@@ -459,9 +458,8 @@
|
||||
<zeroOrMore><element name="objref">
|
||||
<ref name="objref-content"/>
|
||||
</element></zeroOrMore>
|
||||
<zeroOrMore><element name="data_item">
|
||||
<attribute name="key"><text/></attribute>
|
||||
<attribute name="value"><text/></attribute>
|
||||
<zeroOrMore><element name="srcattribute">
|
||||
<ref name="srcattribute-content"/>
|
||||
</element></zeroOrMore>
|
||||
<zeroOrMore><element name="reporef">
|
||||
<ref name="reporef-content"/>
|
||||
@@ -671,6 +669,14 @@
|
||||
<ref name="noteref-content"/>
|
||||
</element></zeroOrMore>
|
||||
</define>
|
||||
|
||||
<define name="srcattribute-content">
|
||||
<optional><attribute name="priv">
|
||||
<ref name="priv-content"/>
|
||||
</attribute></optional>
|
||||
<attribute name="type"><text/></attribute>
|
||||
<attribute name="value"><text/></attribute>
|
||||
</define>
|
||||
|
||||
<define name="url-content">
|
||||
<optional><attribute name="priv">
|
||||
|
Reference in New Issue
Block a user