From ce9753fe99db2417dd733be9ad0666408cde8304 Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Sun, 11 May 2014 10:33:23 -0700 Subject: [PATCH] 5690: Can create multiple events with same Gramps-ID --- po/POTFILES.in | 1 + po/POTFILES.skip | 1 - src/gui/editors/editeventref.py | 3 +++ src/gui/editors/editmediaref.py | 4 +++ src/gui/editors/editreference.py | 43 ++++++++++++++++++++++++++++++++ src/gui/editors/editreporef.py | 3 +++ 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 01ecd10ad..695838bff 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -118,6 +118,7 @@ src/gui/editors/editperson.py src/gui/editors/editpersonref.py src/gui/editors/editplace.py src/gui/editors/editprimary.py +src/gui/editors/editreference.py src/gui/editors/editreporef.py src/gui/editors/editrepository.py src/gui/editors/editsource.py diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 1d6119775..c66f388ed 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -220,7 +220,6 @@ src/gui/user.py # gui/editors - the GUI editors package src/gui/editors/__init__.py -src/gui/editors/editreference.py src/gui/editors/editsecondary.py # gui/editors/displaytabs - the GUI display tabs package diff --git a/src/gui/editors/editeventref.py b/src/gui/editors/editeventref.py index 6bf5c6bc6..7504f08c5 100644 --- a/src/gui/editors/editeventref.py +++ b/src/gui/editors/editeventref.py @@ -244,6 +244,9 @@ class EditEventRef(EditReference): def ok_clicked(self, obj): + if self.check_for_duplicate_id('Event'): + return + if self.source.handle: with DbTxn(_("Modify Event"), self.db) as trans: self.commit_event(self.source,trans) diff --git a/src/gui/editors/editmediaref.py b/src/gui/editors/editmediaref.py index fabab1c12..1c45676b6 100644 --- a/src/gui/editors/editmediaref.py +++ b/src/gui/editors/editmediaref.py @@ -655,6 +655,10 @@ class EditMediaRef(EditReference): self._setup_notebook_tabs(notebook_ref) def save(self,*obj): + + if self.check_for_duplicate_id('Media'): + return + #first save primary object if self.source.handle: with DbTxn(_("Edit Media Object (%s)") % diff --git a/src/gui/editors/editreference.py b/src/gui/editors/editreference.py index 730da2ca4..9ed8c5de6 100644 --- a/src/gui/editors/editreference.py +++ b/src/gui/editors/editreference.py @@ -3,6 +3,7 @@ # # Copyright (C) 2000-2006 Donald N. Allingham # 2009 Gary Burton +# Copyright (C) 2014 Paul Franklin # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,6 +34,8 @@ import gtk # gramps modules # #------------------------------------------------------------------------- +from gen.ggettext import gettext as _ +from QuestionDialog import ErrorDialog import ManagedWindow from displaytabs import GrampsTab import config @@ -255,3 +258,43 @@ class EditReference(ManagedWindow.ManagedWindow, DbGUIElement): of the main interface, not of the displaytabs. """ pass + + def check_for_duplicate_id(self, type): + """ + check to see if the gramps ID (if any) already exists + + type : the gramps primary object type, a string + returns : True if the gramps ID already exists, else False + + N.B. the various strings, string variables, and titles existed already + """ + new_id = self.source.get_gramps_id() + if new_id: + old_primary = self.db.get_from_name_and_gramps_id(type, new_id) + if old_primary: + if type == 'Event': + msg1 = _("Cannot save event. ID already exists.") + description = old_primary.get_description() + elif type == 'Media': + msg1 = _("Cannot save media object. ID already exists.") + description = old_primary.get_description() + elif type == 'Repository': + msg1 = _("Cannot save repository. ID already exists.") + description = old_primary.get_name() + if description: + msg2 = _("You have attempted to use the existing Gramps " + "ID with value %(id)s. This value is already " + "used by '%(prim_object)s'. Please enter a " + "different ID or leave blank to get the next " + "available ID value.") % { + 'id' : new_id, 'prim_object' : description } + else: + msg2 = _("You have attempted to use the existing Gramps " + "ID with value %(id)s. This value is already " + "used. Please enter a " + "different ID or leave blank to get the next " + "available ID value.") % { + 'id' : new_id} + ErrorDialog(msg1, msg2) + return True + return False diff --git a/src/gui/editors/editreporef.py b/src/gui/editors/editreporef.py index 686d4d6ee..135841f81 100644 --- a/src/gui/editors/editreporef.py +++ b/src/gui/editors/editreporef.py @@ -190,6 +190,9 @@ class EditRepoRef(EditReference): def ok_clicked(self, obj): + if self.check_for_duplicate_id('Repository'): + return + if self.source.handle: with DbTxn(_("Modify Repository"), self.db) as trans: self.db.commit_repository(self.source,trans)