GEP 18: introduce label in template, drastical reduction of number of source attributes
svn: r22514
This commit is contained in:
parent
f177537525
commit
cc839bf167
File diff suppressed because it is too large
Load Diff
@ -74,12 +74,13 @@ ident = ''
|
||||
|
||||
TYPE2CITEMAP = {}
|
||||
FIELDTYPEMAP = {}
|
||||
FIELDS_SHORT = []
|
||||
index = 100
|
||||
indexval = 10
|
||||
first = True
|
||||
|
||||
with open(csvfilename, 'rb') as csvfile:
|
||||
reader = csv.reader(csvfile, delimiter=',')
|
||||
reader = csv.reader(csvfile, delimiter=';')
|
||||
for row in reader:
|
||||
if first:
|
||||
#skip first row with headers
|
||||
@ -88,20 +89,38 @@ with open(csvfilename, 'rb') as csvfile:
|
||||
|
||||
if row[CATCOL]:
|
||||
cat = row[CATCOL].strip()
|
||||
if cat.startswith('EE '):
|
||||
cat = cat[3:]
|
||||
EE = True
|
||||
else:
|
||||
EE = False
|
||||
cattype = row[CATTYPECOL].strip()
|
||||
types = row[TYPECOL].strip()
|
||||
descr = row[DESCRCOL].strip()
|
||||
source_type = row[IDENTCOL].strip()
|
||||
if descr:
|
||||
source_descr = '%s - %s - %s (%s)' % (cat, cattype, types, descr)
|
||||
source_descr_code = "_('%(first)s - %(sec)s - %(third)s (%(fourth)s)') % { "\
|
||||
if not EE:
|
||||
source_descr_code = "_('%(first)s - %(sec)s - %(third)s (%(fourth)s)') % { "\
|
||||
" 'first': _('" + cat + "'),"\
|
||||
" 'sec': _('" + cattype + "'),"\
|
||||
" 'third': _('" + types + "'),"\
|
||||
" 'fourth': _('" + descr + "')}"
|
||||
else:
|
||||
source_descr_code = "_('EE %(first)s - %(sec)s - %(third)s (%(fourth)s)') % { "\
|
||||
" 'first': _('" + cat + "'),"\
|
||||
" 'sec': _('" + cattype + "'),"\
|
||||
" 'third': _('" + types + "'),"\
|
||||
" 'fourth': _('" + descr + "')}"
|
||||
else:
|
||||
source_descr = '%s - %s - %s' % (cat, cattype, types)
|
||||
source_descr_code = "_('%(first)s - %(sec)s - %(third)s') % { "\
|
||||
if not EE:
|
||||
source_descr_code = "_('%(first)s - %(sec)s - %(third)s') % { "\
|
||||
" 'first': _('" + cat + "'),"\
|
||||
" 'sec': _('" + cattype + "'),"\
|
||||
" 'third': _('" + types + "')}"
|
||||
else:
|
||||
source_descr_code = "_('EE %(first)s - %(sec)s - %(third)s') % { "\
|
||||
" 'first': _('" + cat + "'),"\
|
||||
" 'sec': _('" + cattype + "'),"\
|
||||
" 'third': _('" + types + "')}"
|
||||
@ -114,7 +133,6 @@ with open(csvfilename, 'rb') as csvfile:
|
||||
'descrcode': source_descr_code}
|
||||
indexval += 1
|
||||
|
||||
|
||||
if row[CITETYPECOL]:
|
||||
#new citation type,
|
||||
cite_type = row[CITETYPECOL].strip()
|
||||
@ -131,6 +149,8 @@ with open(csvfilename, 'rb') as csvfile:
|
||||
.replace(',', '').replace('.', '').replace(':', '')\
|
||||
.replace('-', '_')
|
||||
field_descr = field.replace('[', '').replace(']','').lower().capitalize()
|
||||
field_label = row[LABELCOL].strip()
|
||||
field_label = field_label.replace("'", "\\'")
|
||||
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:
|
||||
@ -148,7 +168,7 @@ with open(csvfilename, 'rb') as csvfile:
|
||||
style = STYLES.get(row[STYLECOL].strip()) or 'EMPTY'
|
||||
|
||||
TYPE2CITEMAP[source_type][cite_type] += [(row[LDELCOL], field_type,
|
||||
row[RDELCOL], style, private, optional,
|
||||
row[RDELCOL], field_label, style, private, optional,
|
||||
shorteralg, gedcommap)]
|
||||
#if shorttype, we store a type for the short version so user can store
|
||||
#this
|
||||
@ -158,6 +178,7 @@ with open(csvfilename, 'rb') as csvfile:
|
||||
pass
|
||||
else:
|
||||
FIELDTYPEMAP[field_type_short] = (index, field_descr + ' (Short)')
|
||||
FIELDS_SHORT.append(field_type_short)
|
||||
index += 1
|
||||
|
||||
#now generate the python code we need in source attr types
|
||||
@ -169,8 +190,10 @@ 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'
|
||||
code += "\n _DATAMAPIGNORE = [\n"
|
||||
for field in FIELDS_SHORT:
|
||||
code += " " + field + ',\n'
|
||||
code += ' ]\n\n' + datamap + ' ]\n'
|
||||
|
||||
with open('srcattrtype_extra.py', 'wb') as srcattrfile:
|
||||
srcattrfile.write(code)
|
||||
@ -204,11 +227,12 @@ for source_type in allkeys:
|
||||
for val in ['REF_TYPE_L', 'REF_TYPE_F', 'REF_TYPE_S']:
|
||||
code += " " + val + ": [\n"
|
||||
for field in TYPE2CITEMAP[source_type][val]:
|
||||
# field is tuple (row[LDELCOL], field_type, row[RDELCOL], row[STYLECOL]
|
||||
# field is tuple (row[LDELCOL], field_type, row[RDELCOL],
|
||||
# field_label, row[STYLECOL]
|
||||
# , private, optional, shorteralg, gedcommap)
|
||||
code += " ('"+ field[0] + "', " + field[1] + ", '"\
|
||||
+ field[2] + "', " + field[3] + ", " + field[4] + ", "\
|
||||
+ field[5] + ", " + field[6] + ", " + field[7] + "),\n"
|
||||
code += " ('"+ field[0] + "', " + field[1] + ", _('"\
|
||||
+field[3] + "'), '"+ field[2] + "', " + field[4] + ", " + field[5] + ", "\
|
||||
+ field[6] + ", " + field[7] + ", " + field[8] + "),\n"
|
||||
code += " ],\n"
|
||||
code += " },\n"
|
||||
code += " }\n"
|
||||
|
@ -81,3 +81,19 @@ class AttributeType(GrampsType):
|
||||
|
||||
def __init__(self, value=None):
|
||||
GrampsType.__init__(self, value)
|
||||
|
||||
def get_ignore_list(self, exception=None):
|
||||
"""
|
||||
Return a list of the types to ignore and not include in default lists.
|
||||
|
||||
Exception is a sublist of types that may not be ignored
|
||||
|
||||
:param exception: list of integer values corresponding with types that
|
||||
have to be excluded from the ignore list
|
||||
:type exception: list
|
||||
:returns: list of integers corresponding with the types to ignore when
|
||||
showing a list of different NoteType's
|
||||
:rtype: list
|
||||
|
||||
"""
|
||||
return []
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -250,11 +250,11 @@ class SrcTemplate(object):
|
||||
"""
|
||||
reflist = self.tempstruct[reftype]
|
||||
# reflist is typically a list like
|
||||
# [ ('', AUTHOR, ',', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# ('', TITLE, ',', STYLE_QUOTE, False, False, EMPTY, EMPTY),
|
||||
# ('', PUB_INFO, '.', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# ('', DATE, ' -', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# ('', PAGE6S9, '.', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# [ ('', AUTHOR, '', ',', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# ('', TITLE, '', ',', STYLE_QUOTE, False, False, EMPTY, EMPTY),
|
||||
# ('', PUB_INFO, '', '.', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# ('', DATE, '', ' -', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# ('', PAGE, 'Page(s)', '.', EMPTY, False, False, EMPTY, EMPTY),
|
||||
# ]
|
||||
|
||||
#set col of attrmap to use:
|
||||
@ -266,7 +266,7 @@ class SrcTemplate(object):
|
||||
COL_SHORT = 2
|
||||
ref = ['']
|
||||
fieldadded = [False]
|
||||
for (ldel, field, rdel, style, priv, opt, short, gedcom) in reflist:
|
||||
for (ldel, field, label, rdel, style, priv, opt, short, gedcom) in reflist:
|
||||
if not gedcomfield is None and gedcom != gedcomfield:
|
||||
continue
|
||||
customshort = False
|
||||
|
@ -223,14 +223,14 @@ class TemplateFields(object):
|
||||
fieldsL.append(fielddef[1])
|
||||
if self.cite is None:
|
||||
#these are source fields
|
||||
self._add_entry(row, fielddef[1], '')
|
||||
self._add_entry(row, fielddef[1], fielddef[2])
|
||||
row += 1
|
||||
|
||||
tempsattrt = SrcAttributeType()
|
||||
# now add optional short citation values
|
||||
if self.cite is None:
|
||||
fieldsS = [fielddef for fielddef in template[REF_TYPE_S]
|
||||
if fielddef[1] in fieldsL and fielddef[6]==EMPTY]
|
||||
if fielddef[1] in fieldsL and fielddef[7]==EMPTY]
|
||||
if fieldsS:
|
||||
self.gridfields.insert_row(row)
|
||||
lbl = Gtk.Label('')
|
||||
@ -240,7 +240,11 @@ class TemplateFields(object):
|
||||
self.lbls.append(lbl)
|
||||
row += 1
|
||||
for fielddef in fieldsS:
|
||||
self._add_entry(row, tempsattrt.short_version(fielddef[1]), '')
|
||||
lblval = fielddef[2]
|
||||
if lblval:
|
||||
lblval = _('%(normal_version_label)s (Short)') % {
|
||||
'normal_version_label': lblval}
|
||||
self._add_entry(row, tempsattrt.short_version(fielddef[1]), lblval)
|
||||
row += 1
|
||||
|
||||
# now add citation values (optional on source level)
|
||||
@ -255,10 +259,10 @@ class TemplateFields(object):
|
||||
self.lbls.append(lbl)
|
||||
row += 1
|
||||
for fielddef in fieldsF:
|
||||
self._add_entry(row, fielddef[1], '')
|
||||
self._add_entry(row, fielddef[1], fielddef[2])
|
||||
row += 1
|
||||
fieldsS = [fielddef for fielddef in template[REF_TYPE_S]
|
||||
if fielddef[1] not in fieldsL and fielddef[6]==EMPTY]
|
||||
if fielddef[1] not in fieldsL and fielddef[7]==EMPTY]
|
||||
if not self.cite is None:
|
||||
#we indicate with a text these are the short versions
|
||||
if fieldsS:
|
||||
@ -270,22 +274,28 @@ class TemplateFields(object):
|
||||
self.lbls.append(lbl)
|
||||
row += 1
|
||||
for fielddef in fieldsS:
|
||||
self._add_entry(row, tempsattrt.short_version(fielddef[1]), '')
|
||||
lblval = fielddef[2]
|
||||
if lblval:
|
||||
lblval = _('%(normal_version_label)s (Short)') % {
|
||||
'normal_version_label': lblval}
|
||||
self._add_entry(row, tempsattrt.short_version(fielddef[1]), lblval)
|
||||
row += 1
|
||||
|
||||
self.gridfields.show_all()
|
||||
|
||||
def _add_entry(self, row, srcattrtype, label):
|
||||
def _add_entry(self, row, srcattrtype, alt_label):
|
||||
"""
|
||||
Add an entryfield to the grid of fields at row row, to edit the given
|
||||
srcattrtype value. Use label label if given to indicate the field
|
||||
srcattrtype value. Use alt_label if given to indicate the field
|
||||
(otherwise the srcattrtype string description is used)
|
||||
Note srcattrtype should actually be the integer key of the type!
|
||||
"""
|
||||
self.gridfields.insert_row(row)
|
||||
field = srcattrtype
|
||||
#setup label
|
||||
if not label:
|
||||
if alt_label:
|
||||
label = alt_label
|
||||
else:
|
||||
srcattr = SrcAttributeType(field)
|
||||
label = str(srcattr)
|
||||
lbl = Gtk.Label(_("%s:") % label)
|
||||
|
@ -109,7 +109,8 @@ class EditAttributeRoot(EditSecondary):
|
||||
self.obj.set_type,
|
||||
self.obj.get_type,
|
||||
self.db.readonly,
|
||||
custom_values=self.alist
|
||||
custom_values=self.alist,
|
||||
ignore_values=self.obj.get_type().get_ignore_list()
|
||||
)
|
||||
|
||||
def _create_tabbed_pages(self):
|
||||
|
Loading…
Reference in New Issue
Block a user