Fixed updating notes in CSV import and fixed a bug on adding notes to marriage when only notes (no other data) and a bug in add marriage notes twice

svn: r11366
This commit is contained in:
Doug Blank 2008-11-30 01:38:15 +00:00
parent 23b0ec696a
commit 94d20c0748

View File

@ -54,6 +54,7 @@ from DateHandler import parser as _dp
from gen.plug import PluginManager, ImportPlugin from gen.plug import PluginManager, ImportPlugin
from Utils import gender as gender_map from Utils import gender as gender_map
from Utils import ProgressMeter from Utils import ProgressMeter
from Utils import create_id
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -444,7 +445,7 @@ class CSVParser:
new, marriageplace = self.get_or_create_place(marriageplace) new, marriageplace = self.get_or_create_place(marriageplace)
if marriagedate: if marriagedate:
marriagedate = _dp.parse(marriagedate) marriagedate = _dp.parse(marriagedate)
if marriagedate or marriageplace or marriagesource: if marriagedate or marriageplace or marriagesource or note:
# add, if new; replace, if different # add, if new; replace, if different
new, marriage = self.get_or_create_event(family, gen.lib.EventType.MARRIAGE, marriagedate, marriageplace, marriagesource) new, marriage = self.get_or_create_event(family, gen.lib.EventType.MARRIAGE, marriagedate, marriageplace, marriagesource)
if new: if new:
@ -453,13 +454,29 @@ class CSVParser:
family.add_event_ref(mar_ref) family.add_event_ref(mar_ref)
self.db.commit_family(family, self.trans) self.db.commit_family(family, self.trans)
# only add note to event: # only add note to event:
# append notes, if previous notes
if note: if note:
# append notes, if previous notes previous_notes_list = marriage.get_note_list()
previous_notes = marriage.get_note() updated_note = False
if previous_notes != "": for note_handle in previous_notes_list:
if note not in previous_notes: previous_note = self.db.get_note_from_handle(note_handle)
note = previous_notes + "\n" + note if previous_note.type == gen.lib.NoteType.EVENT:
marriage.set_note(note) previous_text = previous_note.get()
if note not in previous_text:
note = previous_text + "\n" + note
previous_note.set(note)
self.db.commit_note(previous_note, self.trans)
updated_note = True
break
if not updated_note:
# add new note here
new_note = gen.lib.Note()
new_note.handle = create_id()
new_note.type.set(gen.lib.NoteType.EVENT)
new_note.set(note)
self.db.add_note(new_note, self.trans)
marriage.add_note(new_note.handle)
self.db.commit_note(new_note, self.trans)
self.db.commit_event(marriage, self.trans) self.db.commit_event(marriage, self.trans)
elif "family" in header: elif "family" in header:
# family, child # family, child
@ -516,12 +533,27 @@ class CSVParser:
# put note on child # put note on child
if note: if note:
# append notes, if previous notes # append notes, if previous notes
previous_notes = child.get_note() previous_notes_list = child.get_note_list()
if self.debug: print " previous note:", previous_notes updated_note = False
if previous_notes != "": for note_handle in previous_notes_list:
if note not in previous_notes: previous_note = self.db.get_note_from_handle(note_handle)
note = previous_notes + "\n" + note if previous_note.type == gen.lib.NoteType.PERSON:
child.set_note(note) previous_text = previous_note.get()
if note not in previous_text:
note = previous_text + "\n" + note
previous_note.set(note)
self.db.commit_note(previous_note, self.trans)
updated_note = True
break
if not updated_note:
# add new note here
new_note = gen.lib.Note()
new_note.handle = create_id()
new_note.type.set(gen.lib.NoteType.PERSON)
new_note.set(note)
self.db.add_note(new_note, self.trans)
child.add_note(new_note.handle)
self.db.commit_note(new_note, self.trans)
self.db.commit_person(child, self.trans) self.db.commit_person(child, self.trans)
elif "surname" in header: # person data elif "surname" in header: # person data
# surname, and any of the following # surname, and any of the following
@ -574,11 +606,27 @@ class CSVParser:
name.set_suffix(suffix) name.set_suffix(suffix)
if note is not None: if note is not None:
# append notes, if previous notes # append notes, if previous notes
previous_notes = person.get_note() previous_notes_list = person.get_note_list()
if previous_notes != "": updated_note = False
if note not in previous_notes: for note_handle in previous_notes_list:
note = previous_notes + "\n" + note previous_note = self.db.get_note_from_handle(note_handle)
person.set_note(note) if previous_note.type == gen.lib.NoteType.PERSON:
previous_text = previous_note.get()
if note not in previous_text:
note = previous_text + "\n" + note
previous_note.set(note)
self.db.commit_note(previous_note, self.trans)
updated_note = True
break
if not updated_note:
# add new note here
new_note = gen.lib.Note()
new_note.handle = create_id()
new_note.type.set(gen.lib.NoteType.PERSON)
new_note.set(note)
self.db.add_note(new_note, self.trans)
person.add_note(new_note.handle)
self.db.commit_note(new_note, self.trans)
if grampsid is not None: if grampsid is not None:
person.gramps_id = grampsid person.gramps_id = grampsid
elif person_ref is not None: elif person_ref is not None:
@ -797,4 +845,4 @@ plugin = ImportPlugin(name = _('CSV Spreadheet'),
description = _("Import data from CSV files"), description = _("Import data from CSV files"),
import_function = importData, import_function = importData,
extension = "csv") extension = "csv")
pmgr.register_plugin(plugin) pmgr.register_plugin(plugin)