From 1f77128e56387540ada1e10992ce26a61e98e242 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 31 Mar 2006 19:46:41 +0000 Subject: [PATCH] empty object checks svn: r6243 --- gramps2/ChangeLog | 11 +++++++++++ gramps2/src/Editors/_EditEvent.py | 8 ++++++++ gramps2/src/Editors/_EditFamily.py | 17 +++++++++++++++-- gramps2/src/Editors/_EditMedia.py | 3 +++ gramps2/src/Editors/_EditPerson.py | 10 ++++++++++ gramps2/src/Editors/_EditPlace.py | 3 +++ gramps2/src/Editors/_EditPrimary.py | 17 ++++++++++++++--- gramps2/src/Editors/_EditRepository.py | 10 ++++++++++ gramps2/src/Editors/_EditSource.py | 8 ++++++++ gramps2/src/RelLib/_DateBase.py | 6 +++--- 10 files changed, 85 insertions(+), 8 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index af2bf545e..037830409 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,14 @@ +2006-03-31 Don Allingham + * src/Editors/_EditPrimary.py: check for empty objects + * src/Editors/_EditPlace.py: check for empty objects + * src/Editors/_EditSource.py: check for empty objects + * src/Editors/_EditPerson.py: check for empty objects + * src/Editors/_EditRepository.py: check for empty objects + * src/Editors/_EditMedia.py: check for empty objects + * src/Editors/_EditEvent.py: check for empty objects + * src/RelLib/_DateBase.py: fix handling of empty dates on + serialize/unserialize + 2006-03-30 Don Allingham * various: convert get_birth_handle()/get_death_handle() to ref calls diff --git a/gramps2/src/Editors/_EditEvent.py b/gramps2/src/Editors/_EditEvent.py index c8f4703bd..780609061 100644 --- a/gramps2/src/Editors/_EditEvent.py +++ b/gramps2/src/Editors/_EditEvent.py @@ -78,6 +78,9 @@ class EditEvent(EditPrimary): EditPrimary.__init__(self, dbstate, uistate, track, event, dbstate.db.get_event_from_handle) + def empty_object(self): + return RelLib.Event() + def _local_init(self): self.top = gtk.glade.XML(const.gladeFile, "event_edit","gramps") self.window = self.top.get_widget("event_edit") @@ -180,6 +183,11 @@ class EditEvent(EditPrimary): GrampsDisplay.help('adv-ev') def save(self,*obj): + if self.object_is_empty(): + ErrorDialog(_("Cannot save event"), + _("No data exists for this event. Please " + "enter data or cancel the edit.")) + return (need_new, handle) = self.place_field.get_place_info() if need_new: diff --git a/gramps2/src/Editors/_EditFamily.py b/gramps2/src/Editors/_EditFamily.py index a74ebb52d..0b3480069 100644 --- a/gramps2/src/Editors/_EditFamily.py +++ b/gramps2/src/Editors/_EditFamily.py @@ -359,6 +359,9 @@ class EditFamily(EditPrimary): else: self.add_parent = False + def empty_object(self): + return RelLib.Family() + def _local_init(self): self.build_interface() @@ -763,7 +766,8 @@ class EditFamily(EditPrimary): else: original = None - if not original: + if not original and not self.object_is_empty(): + print self.obj.serialize() trans = self.db.transaction_begin() # find the father, add the family handle to the father @@ -792,6 +796,12 @@ class EditFamily(EditPrimary): self.db.add_family(self.obj,trans) self.db.transaction_commit(trans,_("Add Family")) + elif not original and self.object_is_empty(): + from QuestionDialog import ErrorDialog + ErrorDialog(_("Cannot save family"), + _("No data exists for this family. Please " + "enter data or cancel the edit.")) + return elif cmp(original.serialize(),self.obj.serialize()): trans = self.db.transaction_begin() @@ -819,7 +829,10 @@ class EditFamily(EditPrimary): ) self.db.commit_person(person,trans) - self.db.commit_family(self.obj,trans) + if self.object_is_empty(): + self.db.remove_family(self.obj.handle,trans) + else: + self.db.commit_family(self.obj,trans) self.db.transaction_commit(trans,_("Edit Family")) self.close_window() diff --git a/gramps2/src/Editors/_EditMedia.py b/gramps2/src/Editors/_EditMedia.py index e640043da..0272da8d4 100644 --- a/gramps2/src/Editors/_EditMedia.py +++ b/gramps2/src/Editors/_EditMedia.py @@ -65,6 +65,9 @@ class EditMedia(EditPrimary): EditPrimary.__init__(self, state, uistate, track, obj, state.db.get_object_from_handle) + def empty_object(self): + return RelLib.MediaObject() + def _local_init(self): assert(self.obj) self.glade = gtk.glade.XML(const.gladeFile, diff --git a/gramps2/src/Editors/_EditPerson.py b/gramps2/src/Editors/_EditPerson.py index 1889917b5..9011fb30d 100644 --- a/gramps2/src/Editors/_EditPerson.py +++ b/gramps2/src/Editors/_EditPerson.py @@ -90,6 +90,9 @@ class EditPerson(EditPrimary): EditPrimary.__init__(self, state, uistate, track, person, state.db.get_person_from_handle, callback) + def empty_object(self): + return RelLib.Person() + def _local_init(self): self.pname = self.obj.get_primary_name() self.should_guess_gender = (not self.obj.get_gramps_id() and @@ -444,6 +447,13 @@ class EditPerson(EditPrimary): """ Save the data. """ + + if self.object_is_empty(): + ErrorDialog(_("Cannot save person"), + _("No data exists for this person. Please " + "enter data or cancel the edit.")) + return + if self._check_for_unknown_gender(): return diff --git a/gramps2/src/Editors/_EditPlace.py b/gramps2/src/Editors/_EditPlace.py index 8620ebef0..f0a87628e 100644 --- a/gramps2/src/Editors/_EditPlace.py +++ b/gramps2/src/Editors/_EditPlace.py @@ -64,6 +64,9 @@ class EditPlace(EditPrimary): EditPrimary.__init__(self, dbstate, uistate, track, place, dbstate.db.get_place_from_handle, callback) + def empty_object(self): + return RelLib.Place() + def _local_init(self): self.top = gtk.glade.XML(const.gladeFile,"place_editor","gramps") diff --git a/gramps2/src/Editors/_EditPrimary.py b/gramps2/src/Editors/_EditPrimary.py index 664fe64d0..a4b6ac720 100644 --- a/gramps2/src/Editors/_EditPrimary.py +++ b/gramps2/src/Editors/_EditPrimary.py @@ -95,6 +95,10 @@ class EditPrimary(DisplayState.ManagedWindow): def _cleanup_on_exit(self): pass + def object_is_empty(self): + return cmp(self.obj.serialize()[1:], + self.empty_object().serialize()[1:]) == 0 + def define_ok_button(self,button,function): button.connect('clicked',function) button.set_sensitive(not self.db.readonly) @@ -131,17 +135,24 @@ class EditPrimary(DisplayState.ManagedWindow): self.close_window() return False + def empty_object(self): + return None + def data_has_changed(self): if self.db.readonly: return False elif self.obj.handle: orig = self.get_from_handle(self.obj.handle) if orig: - return cmp(orig.serialize(),self.obj.serialize()) != 0 + cmp_obj = orig else: - return True + cmp_obj = self.empty_object() + return cmp(cmp_obj.serialize()[1:], + self.obj.serialize()[1:]) != 0 else: - return True + cmp_obj = self.empty_object() + return cmp(cmp_obj.serialize()[1:], + self.obj.serialize()[1:]) != 0 def save(self,*obj): pass diff --git a/gramps2/src/Editors/_EditRepository.py b/gramps2/src/Editors/_EditRepository.py index 3741e97d4..be8d07413 100644 --- a/gramps2/src/Editors/_EditRepository.py +++ b/gramps2/src/Editors/_EditRepository.py @@ -55,6 +55,9 @@ class EditRepository(EditPrimary): EditPrimary.__init__(self, dbstate, uistate, track, repository, dbstate.db.get_repository_from_handle) + def empty_object(self): + return RelLib.Repository() + def _local_init(self): self.glade = gtk.glade.XML(const.gladeFile,"repository_editor","gramps") self.define_top_level(self.glade.get_widget("repository_editor"), @@ -115,6 +118,13 @@ class EditRepository(EditPrimary): self.define_ok_button(self.glade.get_widget('ok'), self.save) def save(self,*obj): + if self.object_is_empty(): + from QuestionDialog import ErrorDialog + ErrorDialog(_("Cannot save repository"), + _("No data exists for this repository. Please " + "enter data or cancel the edit.")) + return + trans = self.db.transaction_begin() if self.obj.get_handle() == None: handle = self.db.add_repository(self.obj,trans) diff --git a/gramps2/src/Editors/_EditSource.py b/gramps2/src/Editors/_EditSource.py index 44a92fe17..ef4ebae44 100644 --- a/gramps2/src/Editors/_EditSource.py +++ b/gramps2/src/Editors/_EditSource.py @@ -66,6 +66,9 @@ class EditSource(EditPrimary): EditPrimary.__init__(self, dbstate, uistate, track, source, dbstate.db.get_source_from_handle) + def empty_object(self): + return RelLib.Source() + def _local_init(self): assert(self.obj) @@ -148,6 +151,11 @@ class EditSource(EditPrimary): self.backref_tab.close() def save(self,*obj): + if self.object_is_empty(): + ErrorDialog(_("Cannot save source"), + _("No data exists for this source. Please " + "enter data or cancel the edit.")) + return trans = self.db.transaction_begin() if self.obj.get_handle() == None: diff --git a/gramps2/src/RelLib/_DateBase.py b/gramps2/src/RelLib/_DateBase.py index bf21810d0..f49b58120 100644 --- a/gramps2/src/RelLib/_DateBase.py +++ b/gramps2/src/RelLib/_DateBase.py @@ -51,10 +51,10 @@ class DateBase: if source: self.date = Date(source.date) else: - self.date = None + self.date = Date() def serialize(self): - if self.date == None: + if self.date == None or self.date.is_empty(): date = None else: date = self.date.serialize() @@ -62,7 +62,7 @@ class DateBase: def unserialize(self,data): if data == None: - self.date = None + self.date = Date() else: self.date = Date().unserialize(data)