empty object checks

svn: r6243
This commit is contained in:
Don Allingham 2006-03-31 19:46:41 +00:00
parent 0bed220bfb
commit 1f77128e56
10 changed files with 85 additions and 8 deletions

View File

@ -1,3 +1,14 @@
2006-03-31 Don Allingham <don@gramps-project.org>
* 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 <don@gramps-project.org>
* various: convert get_birth_handle()/get_death_handle() to ref
calls

View File

@ -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:

View File

@ -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()

View File

@ -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,

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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)