From 22bbe691ae4c0cfd2762fa8f98a3cfbce61efe38 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Mon, 3 May 2010 22:46:14 +0000 Subject: [PATCH] Added a display to return a string of any object; fixed a bug in gid(obj) so that it can now work for any obj svn: r15313 --- src/Simple/_SimpleAccess.py | 50 ++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Simple/_SimpleAccess.py b/src/Simple/_SimpleAccess.py index 521fd91b0..becc3ff19 100644 --- a/src/Simple/_SimpleAccess.py +++ b/src/Simple/_SimpleAccess.py @@ -173,7 +173,6 @@ class SimpleAccess(object): @return: Returns the GRAMPS Id value of the person or family @rtype: unicode """ - assert(isinstance(obj, (gen.lib.Person, gen.lib.Family, NoneType))) if obj: return obj.get_gramps_id() else: @@ -867,6 +866,55 @@ class SimpleAccess(object): assert(type(handle) in [str, unicode]) return self.dbase.get_family_from_handle(handle) + def display(self, object_class, prop, value): + """ + Given a object_class, prop, and value return a display string + describing object. + object_class is "Person", "Source", etc. + prop is "gramps_id", or "handle" + value is a gramps_id or handle. + """ + if object_class in self.dbase.get_table_names(): + obj = self.dbase.get_table_metadata(object_class)\ + [prop + "_func"](value) + if obj: + if isinstance(obj, gen.lib.Person): + return "%s: %s [%s]" % (_(object_class), + self.name(obj), + self.gid(obj)) + elif isinstance(obj, gen.lib.Event): + return "%s: %s [%s]" % (_(object_class), + self.event_type(obj), + self.gid(obj)) + elif isinstance(obj, gen.lib.Family): + return "%s: %s/%s [%s]" % (_(object_class), + self.name(self.mother(obj)), + self.name(self.father(obj)), + self.gid(obj)) + elif isinstance(obj, gen.lib.MediaObject): + return "%s: %s [%s]" % (_(object_class), + obj.desc, + self.gid(obj)) + elif isinstance(obj, gen.lib.Source): + return "%s: %s [%s]" % (_(object_class), + self.title(obj), + self.gid(obj)) + elif isinstance(obj, gen.lib.Place): + return "%s: %s [%s]" % (_(object_class), + place_name(self.dbase, + obj.handle), + self.gid(obj)) + elif isinstance(obj, gen.lib.Repository): + return "%s: %s [%s]" % (_(object_class), + obj.type, + self.gid(obj)) + elif isinstance(obj, gen.lib.Note): + return "%s: %s [%s]" % (_(object_class), + obj.type, + self.gid(obj)) + else: + return "Error: invalid object class: '%s'" % object_class + def by_date(event1, event2): """ Sort function that will compare two events by their dates.