From e267893470012bcd57eec9db68d510219de62d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?syst=C3=A8me?= Date: Sun, 1 Jan 2017 10:52:17 +0100 Subject: [PATCH] 7004: Only Event and Family Editors are checking if data_has_changed tidy up and consistency between editors on save() --- gramps/gui/editors/editcitation.py | 20 ++++++++++---------- gramps/gui/editors/editevent.py | 5 ++--- gramps/gui/editors/editfamily.py | 2 +- gramps/gui/editors/editmedia.py | 19 ++++++++++--------- gramps/gui/editors/editnote.py | 19 ++++++++++--------- gramps/gui/editors/editperson.py | 24 ++++++++++++------------ gramps/gui/editors/editplace.py | 21 +++++++++++---------- gramps/gui/editors/editrepository.py | 19 ++++++++++--------- gramps/gui/editors/editsource.py | 19 ++++++++++--------- 9 files changed, 76 insertions(+), 72 deletions(-) diff --git a/gramps/gui/editors/editcitation.py b/gramps/gui/editors/editcitation.py index 98305b297..a607f8295 100644 --- a/gramps/gui/editors/editcitation.py +++ b/gramps/gui/editors/editcitation.py @@ -307,17 +307,17 @@ class EditCitation(EditPrimary): self.ok_button.set_sensitive(True) return - with DbTxn('', self.db) as trans: - if not self.obj.get_handle(): + if not self.obj.handle: + with DbTxn(_("Add Citation (%s)") % self.obj.get_page(), + self.db) as trans: self.db.add_citation(self.obj, trans) - msg = _("Add Citation (%s)") % self.obj.get_page() - else: - if not self.obj.get_gramps_id(): - self.obj.set_gramps_id( - self.db.find_next_citation_gramps_id()) - self.db.commit_citation(self.obj, trans) - msg = _("Edit Citation (%s)") % self.obj.get_page() - trans.set_description(msg) + else: + if self.data_has_changed(): + with DbTxn(_("Edit Citation (%s)") % self.obj.get_page(), + self.db) as trans: + if not self.obj.get_gramps_id(): + self.obj.set_gramps_id(self.db.find_next_citation_gramps_id()) + self.db.commit_citation(self.obj, trans) if self.callback: self.callback(self.obj.get_handle()) diff --git a/gramps/gui/editors/editevent.py b/gramps/gui/editors/editevent.py index c3e9c974e..ba8d95be0 100644 --- a/gramps/gui/editors/editevent.py +++ b/gramps/gui/editors/editevent.py @@ -269,13 +269,12 @@ class EditEvent(EditPrimary): self.db) as trans: self.db.add_event(self.obj, trans) else: - orig = self.get_from_handle(self.obj.handle) - if self.obj.serialize() != orig.serialize(): + if self.data_has_changed(): with DbTxn(_("Edit Event (%s)") % self.obj.get_gramps_id(), self.db) as trans: if not self.obj.get_gramps_id(): self.obj.set_gramps_id(self.db.find_next_event_gramps_id()) - self.commit_event(self.obj, trans) + self.db.commit_event(self.obj, trans) if self.callback: self.callback(self.obj) diff --git a/gramps/gui/editors/editfamily.py b/gramps/gui/editors/editfamily.py index a4d3171d8..5d8d5e702 100644 --- a/gramps/gui/editors/editfamily.py +++ b/gramps/gui/editors/editfamily.py @@ -1129,7 +1129,7 @@ class EditFamily(EditPrimary): self.db.commit_person(child, trans) self.db.add_family(self.obj, trans) - elif original.serialize() != self.obj.serialize(): + elif self.data_has_changed(): with DbTxn(_("Edit Family"), self.db) as trans: diff --git a/gramps/gui/editors/editmedia.py b/gramps/gui/editors/editmedia.py index bd9f1104c..fc1ccfd70 100644 --- a/gramps/gui/editors/editmedia.py +++ b/gramps/gui/editors/editmedia.py @@ -320,16 +320,17 @@ class EditMedia(EditPrimary): self.obj.set_path(path) - with DbTxn('', self.db) as trans: - if not self.obj.get_handle(): + if not self.obj.handle: + with DbTxn(_("Add Media Object (%s)") % self.obj.get_description(), + self.db) as trans: self.db.add_media(self.obj, trans) - msg = _("Add Media Object (%s)") % self.obj.get_description() - else: - if not self.obj.get_gramps_id(): - self.obj.set_gramps_id(self.db.find_next_media_gramps_id()) - self.db.commit_media(self.obj, trans) - msg = _("Edit Media Object (%s)") % self.obj.get_description() - trans.set_description(msg) + else: + if self.data_has_changed(): + with DbTxn(_("Edit Media Object (%s)") % self.obj.get_description(), + self.db) as trans: + if not self.obj.get_gramps_id(): + self.obj.set_gramps_id(self.db.find_next_media_gramps_id()) + self.db.commit_media(self.obj, trans) if self.callback: self.callback(self.obj) diff --git a/gramps/gui/editors/editnote.py b/gramps/gui/editors/editnote.py index 88467dc8f..5075879dd 100644 --- a/gramps/gui/editors/editnote.py +++ b/gramps/gui/editors/editnote.py @@ -332,16 +332,17 @@ class EditNote(EditPrimary): self.ok_button.set_sensitive(True) return - with DbTxn('', self.db) as trans: - if not self.obj.get_handle(): + if not self.obj.handle: + with DbTxn(_("Add Note"), + self.db) as trans: self.db.add_note(self.obj, trans) - msg = _("Add Note") - else: - if not self.obj.get_gramps_id(): - self.obj.set_gramps_id(self.db.find_next_note_gramps_id()) - self.db.commit_note(self.obj, trans) - msg = _("Edit Note") - trans.set_description(msg) + else: + if self.data_has_changed(): + with DbTxn(_("Edit Note"), + self.db) as trans: + if not self.obj.get_gramps_id(): + self.obj.set_gramps_id(self.db.find_next_note_gramps_id()) + self.db.commit_note(self.obj, trans) if self.callback: self.callback(self.obj.get_handle()) diff --git a/gramps/gui/editors/editperson.py b/gramps/gui/editors/editperson.py index cda18a1ec..a39eff8c0 100644 --- a/gramps/gui/editors/editperson.py +++ b/gramps/gui/editors/editperson.py @@ -856,19 +856,19 @@ class EditPerson(EditPrimary): self.db.set_birth_death_index(self.obj) - with DbTxn('', self.db) as trans: - self._update_family_ids() - if not self.obj.get_handle(): + if not self.obj.handle: + with DbTxn(_("Add Person (%s)") % \ + self.name_displayer.display(self.obj), + self.db) as trans: self.db.add_person(self.obj, trans) - msg = _("Add Person (%s)") % \ - self.name_displayer.display(self.obj) - else: - if not self.obj.get_gramps_id(): - self.obj.set_gramps_id(self.db.find_next_person_gramps_id()) - self.db.commit_person(self.obj, trans) - msg = _("Edit Person (%s)") % \ - self.name_displayer.display(self.obj) - trans.set_description(msg) + else: + if self.data_has_changed(): + with DbTxn(_("Edit Person (%s)") % \ + self.name_displayer.display(self.obj), + self.db) as trans: + if not self.obj.get_gramps_id(): + self.obj.set_gramps_id(self.db.find_next_person_gramps_id()) + self.db.commit_person(self.obj, trans) self._do_close() if self.callback: diff --git a/gramps/gui/editors/editplace.py b/gramps/gui/editors/editplace.py index 07c857ac5..985f79fef 100644 --- a/gramps/gui/editors/editplace.py +++ b/gramps/gui/editors/editplace.py @@ -301,17 +301,18 @@ class EditPlace(EditPrimary): self.ok_button.set_sensitive(True) return - with DbTxn('', self.db) as trans: - place_title = place_displayer.display(self.db, self.obj) - if not self.obj.get_handle(): + place_title = place_displayer.display(self.db, self.obj) + if not self.obj.handle: + with DbTxn(_("Add Place (%s)") % place_title, + self.db) as trans: self.db.add_place(self.obj, trans) - msg = _("Add Place (%s)") % place_title - else: - if not self.obj.get_gramps_id(): - self.obj.set_gramps_id(self.db.find_next_place_gramps_id()) - self.db.commit_place(self.obj, trans) - msg = _("Edit Place (%s)") % place_title - trans.set_description(msg) + else: + if self.data_has_changed(): + with DbTxn(_("Edit Place (%s)") % place_title, + self.db) as trans: + if not self.obj.get_gramps_id(): + self.obj.set_gramps_id(self.db.find_next_place_gramps_id()) + self.db.commit_place(self.obj, trans) self._do_close() if self.callback: diff --git a/gramps/gui/editors/editrepository.py b/gramps/gui/editors/editrepository.py index b7d5139cc..22ab313d1 100644 --- a/gramps/gui/editors/editrepository.py +++ b/gramps/gui/editors/editrepository.py @@ -195,16 +195,17 @@ class EditRepository(EditPrimary): self.ok_button.set_sensitive(True) return - with DbTxn('', self.db) as trans: - if not self.obj.get_handle(): + if not self.obj.handle: + with DbTxn(_("Add Repository (%s)") % self.obj.get_name(), + self.db) as trans: self.db.add_repository(self.obj, trans) - msg = _("Add Repository (%s)") % self.obj.get_name() - else: - if not self.obj.get_gramps_id(): - self.obj.set_gramps_id(self.db.find_next_repository_gramps_id()) - self.db.commit_repository(self.obj, trans) - msg = _("Edit Repository (%s)") % self.obj.get_name() - trans.set_description(msg) + else: + if self.data_has_changed(): + with DbTxn(_("Edit Repository (%s)") % self.obj.get_name(), + self.db) as trans: + if not self.obj.get_gramps_id(): + self.obj.set_gramps_id(self.db.find_next_repository_gramps_id()) + self.db.commit_repository(self.obj, trans) self._do_close() diff --git a/gramps/gui/editors/editsource.py b/gramps/gui/editors/editsource.py index 884933893..831001c58 100644 --- a/gramps/gui/editors/editsource.py +++ b/gramps/gui/editors/editsource.py @@ -216,16 +216,17 @@ class EditSource(EditPrimary): self.ok_button.set_sensitive(True) return - with DbTxn('', self.db) as trans: - if not self.obj.get_handle(): + if not self.obj.handle: + with DbTxn(_("Add Source (%s)") % self.obj.get_title(), + self.db) as trans: self.db.add_source(self.obj, trans) - msg = _("Add Source (%s)") % self.obj.get_title() - else: - if not self.obj.get_gramps_id(): - self.obj.set_gramps_id(self.db.find_next_source_gramps_id()) - self.db.commit_source(self.obj, trans) - msg = _("Edit Source (%s)") % self.obj.get_title() - trans.set_description(msg) + else: + if self.data_has_changed(): + with DbTxn(_("Edit Source (%s)") % self.obj.get_title(), + self.db) as trans: + if not self.obj.get_gramps_id(): + self.obj.set_gramps_id(self.db.find_next_source_gramps_id()) + self.db.commit_source(self.obj, trans) self._do_close() if self.callback: