Provide better formatting for the import statistics

Also fix concatenation bug.
This commit is contained in:
Nick Hall 2021-06-05 18:31:59 +01:00
parent 72220a5038
commit e0cb1125f2

View File

@ -241,92 +241,87 @@ class ImportInfo:
Extract info from obj about 'merge-candidate', Key is one of the Extract info from obj about 'merge-candidate', Key is one of the
predefined keys. predefined keys.
""" """
key2string = {
FAMILY_KEY : _('Family'),
SOURCE_KEY : _('Source'),
EVENT_KEY : _('Event'),
MEDIA_KEY : _('Media Object'),
PLACE_KEY : _('Place'),
REPOSITORY_KEY : _('Repository'),
NOTE_KEY : _('Note'),
CITATION_KEY : _('Citation'),
}
if key == PERSON_KEY: if key == PERSON_KEY:
return _(" %(id)s - %(text)s with %(id2)s\n") % { return _(" {id1} - {text} with {id2}").format(
'id': obj.gramps_id, id1=obj.gramps_id,
'text' : name_displayer.display(obj), text=name_displayer.display(obj),
'id2': sec_obj.gramps_id id2=sec_obj.gramps_id)
}
elif key == FAMILY_KEY :
return _(" Family %(id)s with %(id2)s\n") % {
'id': obj.gramps_id, 'id2': sec_obj.gramps_id}
elif key == SOURCE_KEY:
return _(" Source %(id)s with %(id2)s\n") % {
'id': obj.gramps_id, 'id2': sec_obj.gramps_id}
elif key == EVENT_KEY:
return _(" Event %(id)s with %(id2)s\n") % {
'id': obj.gramps_id, 'id2': sec_obj.gramps_id}
elif key == MEDIA_KEY:
return _(" Media Object %(id)s with %(id2)s\n") % {
'id': obj.gramps_id, 'id2': sec_obj.gramps_id}
elif key == PLACE_KEY:
return _(" Place %(id)s with %(id2)s\n") % {
'id': obj.gramps_id, 'id2': sec_obj.gramps_id}
elif key == REPOSITORY_KEY:
return _(" Repository %(id)s with %(id2)s\n") % {
'id': obj.gramps_id, 'id2': sec_obj.gramps_id}
elif key == NOTE_KEY:
return _(" Note %(id)s with %(id2)s\n") % {
'id': obj.gramps_id, 'id2': sec_obj.gramps_id}
elif key == TAG_KEY: elif key == TAG_KEY:
pass # Tags can't be merged pass # Tags can't be merged
elif key == CITATION_KEY: else:
return _(" Citation %(id)s with %(id2)s\n") % { return _(" {obj} {id1} with {id2}").format(
'id': obj.gramps_id, 'id2': sec_obj.gramps_id} obj=key2string[key],
id1=obj.gramps_id,
id2=sec_obj.gramps_id)
def info_text(self): def info_text(self):
""" """
Construct an info message from the data in the class. Construct an info message from the data in the class.
""" """
key2string = { key2string = {
PERSON_KEY : _(' People: %d\n'), PERSON_KEY : _('People'),
FAMILY_KEY : _(' Families: %d\n'), FAMILY_KEY : _('Families'),
SOURCE_KEY : _(' Sources: %d\n'), SOURCE_KEY : _('Sources'),
EVENT_KEY : _(' Events: %d\n'), EVENT_KEY : _('Events'),
MEDIA_KEY : _(' Media Objects: %d\n'), MEDIA_KEY : _('Media Objects'),
PLACE_KEY : _(' Places: %d\n'), PLACE_KEY : _('Places'),
REPOSITORY_KEY : _(' Repositories: %d\n'), REPOSITORY_KEY : _('Repositories'),
NOTE_KEY : _(' Notes: %d\n'), NOTE_KEY : _('Notes'),
TAG_KEY : _(' Tags: %d\n'), TAG_KEY : _('Tags'),
CITATION_KEY : _(' Citations: %d\n'), CITATION_KEY : _('Citations'),
} }
txt = _("Number of new objects imported:\n") txt = [_("Number of new objects imported:")]
table = []
for key in self.keyorder: for key in self.keyorder:
label = _('%s:') % key2string[key]
new = '%d' % self.data_newobject[self.key2data[key]]
if any(self.data_unknownobject): if any(self.data_unknownobject):
strng = key2string[key][0:-1] + ' (%d)\n' unknown = '(%d)' % self.data_unknownobject[self.key2data[key]]
txt += strng % (self.data_newobject[self.key2data[key]], table.append([label, new, unknown])
self.data_unknownobject[self.key2data[key]])
else: else:
txt += key2string[key] % self.data_newobject[self.key2data[key]] table.append([label, new])
txt.append(table)
if any(self.data_unknownobject): if any(self.data_unknownobject):
txt += _("\nThe imported file was not self-contained.\n" txt.append(
"To correct for that, %(new)d objects were created and\n" _("\nThe imported file was not self-contained.\n"
"their typifying attribute was set to 'Unknown'.\n" "To correct for that, %(new)d objects were created and\n"
"The breakdown per category is depicted by the\n" "their typifying attribute was set to 'Unknown'.\n"
"number in parentheses. Where possible these\n" "The breakdown per category is depicted by the\n"
"'Unknown' objects are referenced by note %(unknown)s.\n" "number in parentheses. Where possible these\n"
) % {'new': sum(self.data_unknownobject), 'unknown': self.expl_note} "'Unknown' objects are referenced by note %(unknown)s."
) % {'new': sum(self.data_unknownobject),
'unknown': self.expl_note})
if self.data_relpath: if self.data_relpath:
txt += _("\nMedia objects with relative paths have been\n" txt.append(
"imported. These paths are considered relative to\n" _("\nMedia objects with relative paths have been\n"
"the media directory you can set in the preferences,\n" "imported. These paths are considered relative to\n"
"or, if not set, relative to the user's directory.\n" "the media directory you can set in the preferences,\n"
) "or, if not set, relative to the user's directory."))
merge = False merge = False
for key in self.keyorder: for key in self.keyorder:
if self.data_mergecandidate[self.key2data[key]]: if self.data_mergecandidate[self.key2data[key]]:
merge = True merge = True
break break
if merge: if merge:
txt += _("\nObjects that are candidates to be merged:\n") txt.append(_("\nObjects that are candidates to be merged:"))
for key in self.keyorder: for key in self.keyorder:
datakey = self.key2data[key] datakey = self.key2data[key]
for handle in list(self.data_mergecandidate[datakey].keys()): for handle in list(self.data_mergecandidate[datakey].keys()):
txt += self.data_mergecandidate[datakey][handle] txt.append(self.data_mergecandidate[datakey][handle])
if self.data_families: if self.data_families:
txt += "\n\n" txt.append(self.data_families)
txt += self.data_families
return txt return txt