diff --git a/ChangeLog b/ChangeLog index 9b25bdfab..f079b7cc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,37 @@ 2007-02-19 Zsolt Foldvari * src/GrampsWidgets.py (IconEntry): apply latest fixes from kiwi r5889 +2007-02-19 Alex Roitman + * src/GrampsDbUtils/_ReadXML.py (start_note, stop_note): Parse + legacy notes. + * src/GrampsDb/_GrampsDbBase.py (commit_note): Typo. + * src/RelLib/_SourceRef.py (get_referenced_handles): Include notes. + * src/RelLib/_Source.py (get_referenced_handles): Include notes. + * src/RelLib/_Repository.py (get_referenced_handles): Include notes. + * src/RelLib/_RepoRef.py (get_referenced_handles): Include notes. + * src/RelLib/_Place.py (get_referenced_handles): Include notes. + * src/RelLib/_PersonRef.py (get_referenced_handles): Include notes. + * src/RelLib/_Person.py (get_referenced_handles): Include notes. + * src/RelLib/_Name.py (get_referenced_handles): Include notes. + * src/RelLib/_MediaRef.py (get_referenced_handles): Include notes. + * src/RelLib/_MediaObject.py (get_referenced_handles): Include notes. + * src/RelLib/_EventRef.py (get_referenced_handles): Include notes. + * src/RelLib/_LdsOrd.py (get_referenced_handles): Incclude notes. + * src/RelLib/_Family.py (get_referenced_handles): Include notes. + * src/RelLib/_Event.py (get_referenced_handles): Include notes. + * src/RelLib/_Address.py (get_referenced_handles): Include notes. + * src/RelLib/_Attribute.py (get_referenced_handles): Include notes. + * src/RelLib/_ChildRef.py (get_referenced_handles): Include notes. + * src/RelLib/_NoteBase.py (get_referenced_note_handles): Add method; + (set_note_list, get_note_list, remove_note, add_note): Add methods; + (__init__): Rewrite to support note list. + +2007-02-19 Don Allingham + * src/GrampsDbUtils/_GedcomParse.py: fix PLAC/ADDR mappings + +2007-02-19 Zsolt Foldvari + * src/GrampsWidgets.py (IconEntry): apply latest fixes from kiwi r5889 + 2007-02-18 Don Allingham * src/GrampsDbUtils/_GedcomUtils.py: Add IdMapper class * src/GrampsDbUtils/_GedcomParser.py: refactoring @@ -21,18 +52,26 @@ 2007-02-18 Don Allingham * src/GrampsDbUtils/_GedcomParse.py: more refactoring -2007-02-18 Martin Hawlisch - * src/GrampsDbUtils/_GedcomParse.py: Work around some Tracebacks - -2007-02-16 Zsolt Foldvari - * src/DisplayTabs/_NoteTab.py: accelerators replaced with key-press - signal handler. - * src/DisplayTabs/_ButtonTab.py: accelerators removed; wrong concept. - * src/DisplayTabs/_GrampsTab.py: accelerators removed; wrong concept. - * src/Editors/_EditPrimary.py: accelerators removed; wrong concept. - * src/Editors/_EditSecondary.py: accelerators removed; wrong concept. - * src/Editors/_EditReference.py: accelerators removed; wrong concept. - * src/ManagedWindow.py: accelerators removed; wrong concept. +2007-02-18 Alex Roitman + * src/Editors/_EditAttribute.py (EditAttribute): Correct constant + names. + * src/Editors/_EditAddress.py (EditAddress): Correct constant + names. + * src/Config/_GrampsConfigKeys.py: Regenerate file. + * src/Config/gen_schema_keys.py (copy): Update comments. + * data/gramps.schemas.in: Add config for notes prefix. + * src/RelLib/_PrimaryObject.py: Change to derive from the + BasicPrimaryObject class. + * src/RelLib/_BasicPrimaryObject.py: Add new base class. + * src/GrampsDb/_GrampsBSDDB.py: Add map and methods for Notes. + * src/GrampsDb/_GrampsInMemDB.py: Add map and methods for Notes. + * src/GrampsDb/_GrampsDbBase.py: Add map and methods for Notes. + * src/GrampsDb/_GrampsDbConst.py: Add Note's constants. + * src/RelLib/_NoteType.py: Add note types. + * src/RelLib/_Note.py: Rewrite as a primary object. + * src/RelLib/_Repository.py (has_source_reference, + remove_source_references, replace_source_references): Remove + redundant methods. 2007-02-17 Richard Taylor * src/GrampsDb/_GrampsDbWriteXML.py: add non-gtk xml writer diff --git a/data/gramps.schemas.in b/data/gramps.schemas.in index 55776b07d..d64255e78 100644 --- a/data/gramps.schemas.in +++ b/data/gramps.schemas.in @@ -601,6 +601,19 @@ + + /schemas/apps/gramps/preferences/nprefix + /apps/gramps/preferences/nprefix + gramps + string + N%04d + + Default note GRAMPS ID pattern + The new GRAMPS IDs for the notes are generated according + to this format string. + + + /schemas/apps/gramps/preferences/iprefix /apps/gramps/preferences/iprefix diff --git a/src/Config/_GrampsConfigKeys.py b/src/Config/_GrampsConfigKeys.py index d833985aa..e329668e0 100644 --- a/src/Config/_GrampsConfigKeys.py +++ b/src/Config/_GrampsConfigKeys.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2006 Donald N. Allingham +# Copyright (C) 2006-2007 Donald N. Allingham # # 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 @@ -20,6 +20,11 @@ # $Id$ +# NOTE: This file is autogenerated by gen_schema_keys.py script +# from the data/gramps.schemas.in file. To generate, run: +# python gen_schema_keys.py ../../data/gramps.schemas.in +# in the src/Config directory. + DEFAULT_SOURCE = ('preferences','default-source', 0) RELATION_SHADE = ('preferences','relation-shade', 0) ONLINE_MAPS = ('preferences','online-maps', 0) @@ -30,10 +35,10 @@ CUSTOM_MARKER_COLOR = ('preferences','custom-marker-color', 2) FAMILY_WARN = ('preferences','family-warn', 0) HIDE_EP_MSG = ('preferences','hide-ep-msg', 0) LAST_VIEW = ('preferences','last-view', 1) -USE_LAST_VIEW = ('preferences','use-last-view', 1) +USE_LAST_VIEW = ('preferences','use-last-view', 0) FAMILY_SIBLINGS = ('preferences','family-siblings', 0) -ENABLE_AUTOBACKUP = ('behavior','enable-autobackup', 1) AUTOLOAD = ('behavior','autoload', 0) +ENABLE_AUTOBACKUP = ('behavior','enable-autobackup', 0) SPELLCHECK = ('behavior','spellcheck', 0) BETAWARN = ('behavior','betawarn', 0) WELCOME = ('behavior','welcome', 1) @@ -49,38 +54,27 @@ EVENT_HEIGHT = ('interface','event-height', 1) EVENT_WIDTH = ('interface','event-width', 1) EVENT_REF_HEIGHT = ('interface','event-ref-height', 1) EVENT_REF_WIDTH = ('interface','event-ref-width', 1) -SOURCE_HEIGHT = ('interface','source-height', 1) -SOURCE_WIDTH = ('interface','source-width', 1) -SOURCE_REF_HEIGHT = ('interface','source-ref-height', 1) -SOURCE_REF_WIDTH = ('interface','source-ref-width', 1) -PERSON_REF_HEIGHT = ('interface','person-ref-height', 1) -PERSON_REF_WIDTH = ('interface','person-ref-width', 1) -REPO_REF_HEIGHT = ('interface','repo-ref-height', 1) -REPO_REF_WIDTH = ('interface','repo-ref-width', 1) PLACE_HEIGHT = ('interface','place-height', 1) PLACE_WIDTH = ('interface','place-width', 1) REPO_HEIGHT = ('interface','repo-height', 1) REPO_WIDTH = ('interface','repo-width', 1) -LDS_HEIGHT = ('interface','lds-height', 1) -LDS_WIDTH = ('interface','lds-width', 1) -URL_WIDTH = ('interface','url-width', 1) -URL_HEIGHT = ('interface','url-height', 1) -LOCATION_HEIGHT = ('interface','location-height', 1) -LOCATION_WIDTH = ('interface','location-width', 1) MEDIA_HEIGHT = ('interface','media-height', 1) MEDIA_WIDTH = ('interface','media-width', 1) -MEDIA_REF_HEIGHT = ('interface','media-ref-height', 1) -MEDIA_REF_WIDTH = ('interface','media-ref-width', 1) -ADDR_HEIGHT = ('interface','address-height', 1) -ADDR_WIDTH = ('interface','address-width', 1) -ATTR_HEIGHT = ('interface','attribute-height', 1) -ATTR_WIDTH = ('interface','attribute-width', 1) +ADDRESS_HEIGHT = ('interface','address-height', 1) +ADDRESS_WIDTH = ('interface','address-width', 1) +ATTRIBUTE_HEIGHT = ('interface','attribute-height', 1) +ATTRIBUTE_WIDTH = ('interface','attribute-width', 1) NAME_HEIGHT = ('interface','name-height', 1) NAME_WIDTH = ('interface','name-width', 1) +SOURCE_HEIGHT = ('interface','source-height', 1) +SOURCE_WIDTH = ('interface','source-width', 1) +SOURCE_REF_HEIGHT = ('interface','source-ref-height', 1) +SOURCE_REF_WIDTH = ('interface','source-ref-width', 1) FILTER = ('interface','filter', 0) FPREFIX = ('preferences','fprefix', 2) EPREFIX = ('preferences','eprefix', 2) RPREFIX = ('preferences','rprefix', 2) +NPREFIX = ('preferences','nprefix', 2) IPREFIX = ('preferences','iprefix', 2) OPREFIX = ('preferences','oprefix', 2) PPREFIX = ('preferences','pprefix', 2) @@ -113,12 +107,22 @@ SIDEBAR_TEXT = ('interface','sidebar-text', 0) WEBSITE_DIRECTORY = ('paths','website-directory', 2) PORT_WARN = ('preferences','port-warn', 0) TRANSACTIONS = ('behavior','transactions', 0) -RELEDITBTN = ('interface','editbutton', 1) -OWNER_WARN = ('preferences','owner-warn', 0) +LDS_HEIGHT = ('interface','lds-height', 1) +LDS_WIDTH = ('interface','lds-width', 1) +LOCATION_HEIGHT = ('interface','location-height', 1) +LOCATION_WIDTH = ('interface','location-width', 1) +MEDIA_REF_HEIGHT = ('interface','media-ref-height', 1) +MEDIA_REF_WIDTH = ('interface','media-ref-width', 1) +URL_HEIGHT = ('interface','url-height', 1) +URL_WIDTH = ('interface','url-width', 1) +PERSON_REF_HEIGHT = ('interface','person-ref-height', 1) +PERSON_REF_WIDTH = ('interface','person-ref-width', 1) +REPO_REF_HEIGHT = ('interface','repo-ref-height', 1) +REPO_REF_WIDTH = ('interface','repo-ref-width', 1) +OWNER_WARN = ('behavior','owner-warn', 0) default_value = { - RELEDITBTN : False, DEFAULT_SOURCE : False, RELATION_SHADE : True, ONLINE_MAPS : False, @@ -148,38 +152,27 @@ default_value = { EVENT_WIDTH : 600, EVENT_REF_HEIGHT : 450, EVENT_REF_WIDTH : 600, - SOURCE_HEIGHT : 450, - SOURCE_WIDTH : 600, - LDS_HEIGHT : 450, - LDS_WIDTH : 600, - URL_HEIGHT : 150, - URL_WIDTH : 600, - LOCATION_HEIGHT : 250, - LOCATION_WIDTH : 550, - SOURCE_REF_HEIGHT : 450, - SOURCE_REF_WIDTH : 600, - PERSON_REF_HEIGHT : 350, - PERSON_REF_WIDTH : 600, - REPO_REF_HEIGHT : 450, - REPO_REF_WIDTH : 600, PLACE_HEIGHT : 450, PLACE_WIDTH : 650, REPO_HEIGHT : 450, REPO_WIDTH : 650, MEDIA_HEIGHT : 450, MEDIA_WIDTH : 650, - MEDIA_REF_HEIGHT : 450, - MEDIA_REF_WIDTH : 650, - ADDR_HEIGHT : 450, - ADDR_WIDTH : 650, - ATTR_HEIGHT : 350, - ATTR_WIDTH : 600, - NAME_HEIGHT : 400, + ADDRESS_HEIGHT : 450, + ADDRESS_WIDTH : 650, + ATTRIBUTE_HEIGHT : 350, + ATTRIBUTE_WIDTH : 600, + NAME_HEIGHT : 350, NAME_WIDTH : 600, + SOURCE_HEIGHT : 450, + SOURCE_WIDTH : 600, + SOURCE_REF_HEIGHT : 450, + SOURCE_REF_WIDTH : 600, FILTER : False, FPREFIX : 'F%04d', EPREFIX : 'E%04d', RPREFIX : 'R%04d', + NPREFIX : 'N%04d', IPREFIX : 'I%04d', OPREFIX : 'O%04d', PPREFIX : 'P%04d', @@ -212,5 +205,17 @@ default_value = { WEBSITE_DIRECTORY : './', PORT_WARN : False, TRANSACTIONS : True, + LDS_HEIGHT : 450, + LDS_WIDTH : 600, + LOCATION_HEIGHT : 250, + LOCATION_WIDTH : 600, + MEDIA_REF_HEIGHT : 450, + MEDIA_REF_WIDTH : 600, + URL_HEIGHT : 150, + URL_WIDTH : 600, + PERSON_REF_HEIGHT : 350, + PERSON_REF_WIDTH : 600, + REPO_REF_HEIGHT : 450, + REPO_REF_WIDTH : 600, OWNER_WARN : False, } diff --git a/src/Config/gen_schema_keys.py b/src/Config/gen_schema_keys.py index b9b98f872..389c6bdb7 100644 --- a/src/Config/gen_schema_keys.py +++ b/src/Config/gen_schema_keys.py @@ -1,7 +1,7 @@ copy = """# # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2006 Donald N. Allingham +# Copyright (C) 2006-2007 Donald N. Allingham # # 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 @@ -20,6 +20,11 @@ copy = """# # $Id$ +# NOTE: This file is autogenerated by gen_schema_keys.py script +# from the data/gramps.schemas.in file. To generate, run: +# python gen_schema_keys.py ../../data/gramps.schemas.in +# in the src/Config directory. + """ from xml.parsers.expat import ExpatError, ParserCreate diff --git a/src/DbState.py b/src/DbState.py index 078ccc734..211a80b48 100644 --- a/src/DbState.py +++ b/src/DbState.py @@ -72,7 +72,8 @@ class DbState(GrampsDBCallback): Config.get(Config.SPREFIX), Config.get(Config.PPREFIX), Config.get(Config.EPREFIX), - Config.get(Config.RPREFIX)) + Config.get(Config.RPREFIX), + Config.get(Config.NPREFIX) ) self.active = None self.open = True diff --git a/src/Editors/_EditAddress.py b/src/Editors/_EditAddress.py index 57194962f..45e1e02f2 100644 --- a/src/Editors/_EditAddress.py +++ b/src/Editors/_EditAddress.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -61,8 +61,8 @@ class EditAddress(EditSecondary): Displays a dialog that allows the user to edit an address. """ - WIDTH_KEY = Config.ADDR_WIDTH - HEIGHT_KEY = Config.ADDR_HEIGHT + WIDTH_KEY = Config.ADDRESS_WIDTH + HEIGHT_KEY = Config.ADDRESS_HEIGHT def __init__(self, dbstate, uistate, track, addr, callback): """ diff --git a/src/Editors/_EditAttribute.py b/src/Editors/_EditAttribute.py index a9daa6c29..6dbd38606 100644 --- a/src/Editors/_EditAttribute.py +++ b/src/Editors/_EditAttribute.py @@ -64,8 +64,8 @@ class EditAttribute(EditSecondary): Displays a dialog that allows the user to edit an attribute. """ - WIDTH_KEY = Config.ATTR_WIDTH - HEIGHT_KEY = Config.ATTR_HEIGHT + WIDTH_KEY = Config.ATTRIBUTE_WIDTH + HEIGHT_KEY = Config.ATTRIBUTE_HEIGHT def __init__(self, state, uistate, track, attrib, title, data_list, callback): """ diff --git a/src/GrampsDb/_GrampsBSDDB.py b/src/GrampsDb/_GrampsBSDDB.py index 44d7e7130..761f2b587 100644 --- a/src/GrampsDb/_GrampsBSDDB.py +++ b/src/GrampsDb/_GrampsBSDDB.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -191,6 +191,9 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): def get_repository_cursor(self): return GrampsBSDDBCursor(self.repository_map,self.txn) + def get_note_cursor(self): + return GrampsBSDDBCursor(self.note_map,self.txn) + def has_person_handle(self,handle): """ returns True if the handle exists in the current Person database. @@ -215,6 +218,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): """ return self.repository_map.get(str(handle),txn=self.txn) != None + def has_note_handle(self,handle): + """ + returns True if the handle exists in the current Note database. + """ + return self.note_map.get(str(handle),txn=self.txn) != None + def has_event_handle(self,handle): """ returns True if the handle exists in the current Repository database. @@ -254,6 +263,9 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): def get_raw_repository_data(self,handle): return self.repository_map.get(str(handle),txn=self.txn) + def get_raw_note_data(self,handle): + return self.note_map.get(str(handle),txn=self.txn) + # cursors for lookups in the reference_map for back reference # lookups. The reference_map has three indexes: # the main index: a tuple of (primary_handle,referenced_handle) @@ -403,6 +415,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.event_map = self.open_table(self.full_name, "events") self.person_map = self.open_table(self.full_name, "person") self.repository_map = self.open_table(self.full_name, "repository") + self.note_map = self.open_table(self.full_name, "note") self.reference_map = self.open_table(self.full_name, "reference_map", dbtype=db.DB_BTREE) callback(37) @@ -513,6 +526,8 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.name_types = set(self.metadata.get('name_types',default=[])) self.repository_types = set(self.metadata.get('repo_types', default=[])) + self.note_types = set(self.metadata.get('note_types', + default=[])) self.source_media_types = set(self.metadata.get('sm_types', default=[])) self.url_types = set(self.metadata.get('url_types',default=[])) @@ -583,6 +598,11 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.rid_trans.open(self.full_name, "ridtrans", db.DB_HASH, flags=table_flags) + self.nid_trans = db.DB(self.env) + self.nid_trans.set_flags(db.DB_DUP) + self.nid_trans.open(self.full_name, "nidtrans", + db.DB_HASH, flags=table_flags) + self.reference_map_primary_map = db.DB(self.env) self.reference_map_primary_map.set_flags(db.DB_DUP) self.reference_map_primary_map.open(self.full_name, @@ -602,6 +622,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.event_map.associate(self.eid_trans, find_idmap, table_flags) self.repository_map.associate(self.rid_trans, find_idmap, table_flags) + self.note_map.associate(self.nid_trans, find_idmap, table_flags) self.place_map.associate(self.pid_trans, find_idmap, table_flags) self.media_map.associate(self.oid_trans, find_idmap, table_flags) self.source_map.associate(self.sid_trans, find_idmap, table_flags) @@ -620,7 +641,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.lmap_index = len(self.place_map) self.omap_index = len(self.media_map) self.rmap_index = len(self.repository_map) - + self.nmap_index = len(self.note_map) def rebuild_secondary(self,callback): if self.readonly: @@ -675,22 +696,28 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): junk.remove(self.full_name,"ridtrans") callback(8) + # Repair secondary indices related to note_map + self.nid_trans.close() + junk = db.DB(self.env) + junk.remove(self.full_name,"nidtrans") + callback(9) + # Repair secondary indices related to reference_map self.reference_map_primary_map.close() junk = db.DB(self.env) junk.remove(self.full_name,"reference_map_primary_map") - callback(9) + callback(10) self.reference_map_referenced_map.close() junk = db.DB(self.env) junk.remove(self.full_name,"reference_map_referenced_map") - callback(10) + callback(11) # Set flag saying that we have removed secondary indices # and then call the creating routine self.secondary_connected = False self.connect_secondary() - callback(11) + callback(12) def find_backlink_handles(self, handle, include_classes=None): """ @@ -946,6 +973,8 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): 'class_func': MediaObject}, 'Repository': {'cursor_func': self.get_repository_cursor, 'class_func': Repository}, + 'Note': {'cursor_func': self.get_note_cursor, + 'class_func': Note}, } transaction = self.transaction_begin(batch=True,no_magic=True) @@ -1046,6 +1075,8 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): txn=the_txn) self.metadata.put('repo_types',list(self.repository_types), txn=the_txn) + self.metadata.put('note_types',list(self.note_types), + txn=the_txn) self.metadata.put('sm_types',list(self.source_media_types), txn=the_txn) self.metadata.put('url_types',list(self.url_types), @@ -1093,6 +1124,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.fid_trans.close() self.eid_trans.close() self.rid_trans.close() + self.nid_trans.close() self.oid_trans.close() self.sid_trans.close() self.pid_trans.close() @@ -1105,6 +1137,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.person_map.close() self.family_map.close() self.repository_map.close() + self.note_map.close() self.place_map.close() self.source_map.close() self.media_map.close() @@ -1129,6 +1162,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.person_map = None self.family_map = None self.repository_map = None + self.note_map = None self.place_map = None self.source_map = None self.media_map = None @@ -1176,6 +1210,11 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): if not self.UseTXN: self.repository_map.sync() + def _del_note(self,handle): + self.note_map.delete(str(handle),txn=self.txn) + if not self.UseTXN: + self.note_map.sync() + def _del_place(self,handle): self.place_map.delete(str(handle),txn=self.txn) if not self.UseTXN: @@ -1300,11 +1339,19 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): def get_repository_from_gramps_id(self,val): """ Finds a Repository in the database from the passed gramps' ID. - If no such MediaObject exists, None is returned. + If no such Repository exists, None is returned. """ return self._get_obj_from_gramps_id(val,self.rid_trans,Repository, self.repository_map) + def get_note_from_gramps_id(self,val): + """ + Finds a Note in the database from the passed gramps' ID. + If no such Note exists, None is returned. + """ + return self._get_obj_from_gramps_id(val,self.nid_trans,Note, + self.note_map) + def _commit_base(self, obj, data_map, key, update_list, add_list, transaction, change_time): """ diff --git a/src/GrampsDb/_GrampsDbBase.py b/src/GrampsDb/_GrampsDbBase.py index 7d116d2c8..96e3a38d4 100644 --- a/src/GrampsDb/_GrampsDbBase.py +++ b/src/GrampsDb/_GrampsDbBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -76,7 +76,8 @@ CLASS_TO_KEY_MAP = {Person.__name__: PERSON_KEY, Event.__name__: EVENT_KEY, MediaObject.__name__: MEDIA_KEY, Place.__name__: PLACE_KEY, - Repository.__name__:REPOSITORY_KEY} + Repository.__name__:REPOSITORY_KEY, + Note.__name__: NOTE_KEY} KEY_TO_CLASS_MAP = {PERSON_KEY: Person.__name__, FAMILY_KEY: Family.__name__, @@ -84,10 +85,11 @@ KEY_TO_CLASS_MAP = {PERSON_KEY: Person.__name__, EVENT_KEY: Event.__name__, MEDIA_KEY: MediaObject.__name__, PLACE_KEY: Place.__name__, - REPOSITORY_KEY: Repository.__name__} + REPOSITORY_KEY: Repository.__name__, + NOTE_KEY: Note.__name__} _sigbase = ('person', 'family', 'source', 'event', - 'media', 'place', 'repository') + 'media', 'place', 'repository','note') class GrampsCursor: """ @@ -205,6 +207,10 @@ class GrampsDbBase(GrampsDBCallback): 'repository-update' : (list, ), 'repository-delete' : (list, ), 'repository-rebuild' : None, + 'note-add' : (list, ), + 'note-update' : (list, ), + 'note-delete' : (list, ), + 'note-rebuild' : None, 'long-op-start' : (object, ), 'long-op-heartbeat' : None, 'long-op-end' : None @@ -234,6 +240,7 @@ class GrampsDbBase(GrampsDBCallback): self.set_place_id_prefix('P%04d') self.set_event_id_prefix('E%04d') self.set_repository_id_prefix('R%04d') + self.set_note_id_prefix('N%04d') self.readonly = False self.rand = random.Random(time.time()) @@ -244,6 +251,7 @@ class GrampsDbBase(GrampsDBCallback): self.lmap_index = 0 self.omap_index = 0 self.rmap_index = 0 + self.nmap_index = 0 self.db_is_open = False self.family_event_names = set() @@ -256,6 +264,7 @@ class GrampsDbBase(GrampsDBCallback): self.event_role_names = set() self.name_types = set() self.repository_types = set() + self.note_types = set() self.source_media_types = set() self.url_types = set() self.media_attributes = set() @@ -270,6 +279,7 @@ class GrampsDbBase(GrampsDBCallback): self.sid_trans = None self.oid_trans = None self.rid_trans = None + self.nid_trans = None self.eid_trans = None self.env = None self.person_map = None @@ -277,6 +287,7 @@ class GrampsDbBase(GrampsDBCallback): self.place_map = None self.source_map = None self.repository_map = None + self.note_map = None self.media_map = None self.event_map = None self.metadata = None @@ -304,7 +315,8 @@ class GrampsDbBase(GrampsDBCallback): self.name_group = {} self.surname_list = [] - def set_prefixes(self, person, media, family, source, place, event, repository): + def set_prefixes(self, person, media, family, source, place, event, + repository, note): self.iprefix = person self.oprefix = media self.fprefix = family @@ -312,6 +324,7 @@ class GrampsDbBase(GrampsDBCallback): self.pprefix = place self.eprefix = event self.rprefix = repository + self.nprefix = note def rebuild_secondary(self, callback): pass @@ -335,6 +348,9 @@ class GrampsDbBase(GrampsDBCallback): def _del_repository(self, handle): pass + def _del_note(self, handle): + pass + def _del_place(self, handle): pass @@ -393,6 +409,12 @@ class GrampsDbBase(GrampsDBCallback): def get_repository_cursor_iter(self, msg=_("Processing Repository records")): return CursorIterator(self, self.get_repository_cursor(), msg) + def get_note_cursor(self): + assert False, "Needs to be overridden in the derived class" + + def get_note_cursor_iter(self, msg=_("Processing Note records")): + return CursorIterator(self, self.get_note_cursor(), msg) + def open_undodb(self): if not self.readonly: self.undolog = "%s.undo" % self.full_name @@ -447,6 +469,7 @@ class GrampsDbBase(GrampsDBCallback): self.emit('media-rebuild') self.emit('event-rebuild') self.emit('repository-rebuild') + self.emit('note-rebuild') def _commit_base(self, obj, data_map, key, update_list, add_list, transaction, change_time): @@ -662,6 +685,20 @@ class GrampsDbBase(GrampsDBCallback): self.url_types.update([str(url.type) for url in repository.urls if url.type.is_custom()]) + def commit_note(self, note, transaction, change_time=None): + """ + Commits the specified Note to the database, storing the changes + as part of the transaction. + """ + + self._commit_base(note, self.note_map, NOTE_KEY, + transaction.note_update, + transaction.note_add, + transaction, change_time) + + if note.type.is_custom(): + self.note_types.add(str(note.type)) + def find_next_person_gramps_id(self): """ Returns the next available GRAMPS' ID for a Person object based @@ -746,6 +783,18 @@ class GrampsDbBase(GrampsDBCallback): self.rmap_index += 1 return index + def find_next_note_gramps_id(self): + """ + Returns the next available GRAMPS' ID for a Note object based + off the repository ID prefix. + """ + index = self.nprefix % self.nmap_index + while self.nid_trans.has_key(str(index)): + self.nmap_index += 1 + index = self.nprefix % self.nmap_index + self.nmap_index += 1 + return index + def _get_from_handle(self, handle, class_type, data_map): if not data_map: return @@ -805,6 +854,13 @@ class GrampsDbBase(GrampsDBCallback): """ return self._get_from_handle(handle, Repository, self.repository_map) + def get_note_from_handle(self, handle): + """ + Finds a Note in the database from the passed gramps' ID. + If no such Note exists, None is returned. + """ + return self._get_from_handle(handle, Note, self.note_map) + def _find_from_handle(self, handle, transaction, class_type, dmap, add_func): obj = class_type() @@ -880,6 +936,14 @@ class GrampsDbBase(GrampsDBCallback): return self._find_from_handle(handle, transaction, Repository, self.repository_map, self.add_repository) + def find_note_from_handle(self, handle, transaction): + """ + Finds a Note in the database from the passed handle. + If no such Note exists, a new Note is added to the database. + """ + return self._find_from_handle(handle, transaction, Note, + self.note_map, self.add_note) + def check_person_from_handle(self, handle, transaction): """ Checks whether a Person with the passed handle exists in the database. @@ -939,6 +1003,15 @@ class GrampsDbBase(GrampsDBCallback): self._check_from_handle(handle, transaction, Repository, self.repository_map, self.add_repository) + def check_note_from_handle(self, handle, transaction): + """ + Checks whether a Note with the passed handle exists in the + database. If no such Note exists, a new Note is added + to the database. + """ + self._check_from_handle(handle, transaction, Note, + self.note_map, self.add_note) + def get_person_from_gramps_id(self, val): """ Finds a Person in the database from the passed GRAMPS ID. @@ -996,7 +1069,16 @@ class GrampsDbBase(GrampsDBCallback): def get_repository_from_gramps_id(self, val): """ Finds a Repository in the database from the passed gramps' ID. - If no such MediaObject exists, None is returned. + If no such Repository exists, None is returned. + + Needs to be overridden by the derrived class. + """ + assert False, "Needs to be overridden in the derived class" + + def get_note_from_gramps_id(self, val): + """ + Finds a Note in the database from the passed gramps' ID. + If no such Note exists, None is returned. Needs to be overridden by the derrived class. """ @@ -1093,6 +1175,15 @@ class GrampsDbBase(GrampsDBCallback): self.find_next_repository_gramps_id, self.commit_repository) + def add_note(self, obj, transaction): + """ + Adds a Note to the database, assigning internal IDs if they have + not already been defined. + """ + return self._add_object(obj, transaction, + self.find_next_note_gramps_id, + self.commit_note) + def get_name_group_mapping(self, name): """ Returns the default grouping name for a surname @@ -1157,6 +1248,12 @@ class GrampsDbBase(GrampsDBCallback): """ return len(self.repository_map) + def get_number_of_notes(self): + """ + Returns the number of notes currently in the databse. + """ + return len(self.note_map) + def _all_handles(self, table): return table.keys() @@ -1254,6 +1351,15 @@ class GrampsDbBase(GrampsDBCallback): return self._all_handles(self.repository_map) return [] + def get_note_handles(self): + """ + Returns a list of database handles, one handle for each Note in + the database. + """ + if self.db_is_open: + return self._all_handles(self.note_map) + return [] + def get_gramps_ids(self, obj_key): key2table = { PERSON_KEY: self.id_trans, @@ -1263,6 +1369,7 @@ class GrampsDbBase(GrampsDBCallback): MEDIA_KEY: self.oid_trans, PLACE_KEY: self.pid_trans, REPOSITORY_KEY: self.rid_trans, + NOTE_KEY: self.nid_trans, } table = key2table[obj_key] @@ -1277,6 +1384,7 @@ class GrampsDbBase(GrampsDBCallback): MEDIA_KEY: self.oid_trans, PLACE_KEY: self.pid_trans, REPOSITORY_KEY: self.rid_trans, + NOTE_KEY: self.nid_trans, } table = key2table[obj_key] @@ -1369,6 +1477,15 @@ class GrampsDbBase(GrampsDBCallback): """ self.rprefix = self._validated_id_prefix(val, "R") + def set_note_id_prefix(self, val): + """ + Sets the naming template for GRAMPS Note ID values. The string is + expected to be in the form of a simple text string, or in a format + that contains a C/Python style format string using %d, such as N%d + or N%04d. + """ + self.nprefix = self._validated_id_prefix(val, "N") + def transaction_begin(self, msg="",batch=False,no_magic=False): """ Creates a new Transaction tied to the current UNDO database. The @@ -1423,6 +1540,7 @@ class GrampsDbBase(GrampsDBCallback): event_add = self._do_commit(transaction.event_add, self.event_map) repository_add= self._do_commit(transaction.repository_add, self.repository_map) + note_add = self._do_commit(transaction.note_add, self.note_map) person_upd = self._do_commit(transaction.person_update, self.person_map) @@ -1438,6 +1556,8 @@ class GrampsDbBase(GrampsDBCallback): self.event_map) repository_upd= self._do_commit(transaction.repository_update, self.repository_map) + note_upd = self._do_commit(transaction.note_update, + self.note_map) self._do_emit('person', person_add, person_upd, transaction.person_del) self._do_emit('family', family_add, family_upd, transaction.family_del) @@ -1447,6 +1567,7 @@ class GrampsDbBase(GrampsDBCallback): self._do_emit('media', media_add, media_upd, transaction.media_del) self._do_emit('repository', repository_add, repository_upd, transaction.repository_del) + self._do_emit('note', note_add, note_upd, transaction.note_del) self._do_del(transaction.person_del, self._del_person) self._do_del(transaction.family_del, self._del_family) @@ -1455,6 +1576,7 @@ class GrampsDbBase(GrampsDBCallback): self._do_del(transaction.event_del, self._del_event) self._do_del(transaction.media_del, self._del_media) self._do_del(transaction.repository_del, self._del_repository) + self._do_del(transaction.note_del, self._del_note) if self.undo_callback: self.undo_callback(_("_Undo %s") % transaction.get_description()) @@ -1512,7 +1634,7 @@ class GrampsDbBase(GrampsDBCallback): mapbase = (self.person_map, self.family_map, self.source_map, self.event_map, self.media_map, self.place_map, - self.repository_map) + self.repository_map, self.note_map) self.undoindex -= 1 subitems = transaction.get_recnos() @@ -1556,7 +1678,7 @@ class GrampsDbBase(GrampsDBCallback): transaction = self.translist[self.undoindex] mapbase = (self.person_map, self.family_map, self.source_map, self.event_map, self.media_map, self.place_map, - self.repository_map) + self.repository_map, self.note_map) subitems = transaction.get_recnos() for record_id in subitems: @@ -1678,6 +1800,10 @@ class GrampsDbBase(GrampsDBCallback): """returns the list of Person handles in the bookmarks""" return self.repo_bookmarks + def get_note_bookmarks(self): + """returns the list of Note handles in the bookmarks""" + return self.note_bookmarks + def set_researcher(self, owner): """sets the information about the owner of the database""" self.owner.set(owner.get_name(), owner.get_address(), @@ -1772,6 +1898,11 @@ class GrampsDbBase(GrampsDBCallback): Repository instances in the database""" return list(self.repository_types) + def get_note_types(self): + """returns a list of all custom note types assocated with + Note instances in the database""" + return list(self.note_types) + def get_source_media_types(self): """returns a list of all custom source media types assocated with Source instances in the database""" @@ -1810,6 +1941,7 @@ class GrampsDbBase(GrampsDBCallback): MEDIA_KEY: self._del_media, PLACE_KEY: self._del_place, REPOSITORY_KEY: self._del_repository, + NOTE_KEY: self._del_note, } return key2del[key] @@ -1881,6 +2013,15 @@ class GrampsDbBase(GrampsDBCallback): self._do_remove_object(handle, transaction, self.repository_map, REPOSITORY_KEY, transaction.repository_del) + def remove_note(self, handle, transaction): + """ + Removes the Note specified by the database handle from the + database, preserving the change in the passed transaction. This + method must be overridden in the derived class. + """ + self._do_remove_object(handle, transaction, self.note_map, + NOTE_KEY, transaction.note_del) + def get_raw_person_data(self, handle): return self.person_map.get(str(handle)) @@ -1902,6 +2043,9 @@ class GrampsDbBase(GrampsDBCallback): def get_raw_repository_data(self, handle): return self.repository_map.get(str(handle)) + def get_raw_note_data(self, handle): + return self.note_map.get(str(handle)) + def has_person_handle(self, handle): """ returns True if the handle exists in the current Person database. @@ -1944,6 +2088,12 @@ class GrampsDbBase(GrampsDBCallback): """ return self.repository_map.has_key(str(handle)) + def has_note_handle(self, handle): + """ + returns True if the handle exists in the current Note database. + """ + return self.note_map.has_key(str(handle)) + def _sortbyplace(self, first, second): return locale.strcoll(self.place_map.get(str(first))[2], self.place_map.get(str(second))[2]) @@ -2018,6 +2168,13 @@ class GrampsDbBase(GrampsDBCallback): """ self._set_column_order(col_list, REPOSITORY_COL_KEY) + def set_note_column_order(self, col_list): + """ + Stores the Note display common information in the + database's metadata. + """ + self._set_column_order(col_list, NOTE_COL_KEY) + def _get_column_order(self, name, default): if self.metadata == None: return default @@ -2116,6 +2273,16 @@ class GrampsDbBase(GrampsDBCallback): (0, 8, 100), (0, 9, 100), (0, 10, 100)] return self._get_columns(REPOSITORY_COL_KEY, default) + def get_note_column_order(self): + """ + Returns the Note display common information stored in the + database's metadata. + """ + # FIXME: These are copied from Event, must be changed + default = [(1, 0, 200), (1, 1, 75), (1, 2, 100), (1, 3, 150), + (1, 4, 200), (0, 5, 100)] + return self._get_columns(NOTE_COL_KEY, default) + def _delete_primary_from_reference_map(self, handle, transaction): """Called each time an object is removed from the database. This can be used by subclasses to update any additional index tables that might @@ -2173,7 +2340,9 @@ class GrampsDbBase(GrampsDBCallback): 'MediaObject': {'cursor_func': self.get_media_cursor, 'class_func': MediaObject}, 'Repository': {'cursor_func': self.get_repository_cursor, - 'class_func': Repository}, + 'class_func': Repository}, + 'Note': {'cursor_func': self.get_note_cursor, + 'class_func': Note}, } @@ -2269,6 +2438,10 @@ class Transaction: self.repository_del = [] self.repository_update = [] + self.note_add = [] + self.note_del = [] + self.note_update = [] + ## def set_batch(self, batch): ## self.batch = batch diff --git a/src/GrampsDb/_GrampsDbConst.py b/src/GrampsDb/_GrampsDbConst.py index e671b62e2..1a6635bff 100644 --- a/src/GrampsDb/_GrampsDbConst.py +++ b/src/GrampsDb/_GrampsDbConst.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2006 Donald N. Allingham +# Copyright (C) 2004-2007 Donald N. Allingham # # 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 @@ -20,6 +20,11 @@ # $Id: $ +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- import os #------------------------------------------------------------------------- @@ -55,6 +60,7 @@ MEDIA_KEY = 4 PLACE_KEY = 5 REPOSITORY_KEY = 6 REFERENCE_KEY = 7 +NOTE_KEY = 8 PERSON_COL_KEY = 'columns' CHILD_COL_KEY = 'child_columns' @@ -64,3 +70,4 @@ MEDIA_COL_KEY = 'media_columns' REPOSITORY_COL_KEY = 'repository_columns' EVENT_COL_KEY = 'event_columns' FAMILY_COL_KEY = 'family_columns' +NOTE_COL_KEY = 'note_columns' diff --git a/src/GrampsDb/_GrampsInMemDB.py b/src/GrampsDb/_GrampsInMemDB.py index c18dc85f8..24d0c23c0 100644 --- a/src/GrampsDb/_GrampsInMemDB.py +++ b/src/GrampsDb/_GrampsInMemDB.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -87,6 +87,7 @@ class GrampsInMemDB(GrampsDbBase): self.place_map = {} self.source_map = {} self.repository_map = {} + self.note_map = {} self.media_map = {} self.event_map = {} self.metadata = {} @@ -134,6 +135,9 @@ class GrampsInMemDB(GrampsDbBase): def get_repository_cursor(self): return GrampsInMemCursor(self.repository_map) + def get_note_cursor(self): + return GrampsInMemCursor(self.note_map) + def get_media_cursor(self): return GrampsInMemCursor(self.media_map) @@ -191,6 +195,11 @@ class GrampsInMemDB(GrampsDbBase): del self.rid_trans[repository.get_gramps_id()] del self.repository_map[str(handle)] + def _del_note(self,handle): + note = self.get_note_from_handle(str(handle)) + del self.nid_trans[note.get_gramps_id()] + del self.note_map[str(handle)] + def _del_place(self,handle): place = self.get_place_from_handle(str(handle)) del self.pid_trans[place.get_gramps_id()] @@ -225,7 +234,9 @@ class GrampsInMemDB(GrampsDbBase): 'event' : self.eid_trans, 'media' : self.oid_trans, 'place' : self.pid_trans, - 'repository': self.rid_trans} + 'repository': self.rid_trans, + 'note': self.nid_trans, + } return trans_maps[signal_root] def undo_data(self, data, handle, db_map, signal_root): @@ -299,6 +310,12 @@ class GrampsInMemDB(GrampsDbBase): return GrampsDbBase.commit_repository(self,repository,transaction,change_time) + def commit_note(self,note,transaction,change_time=None): + if not self._commit_inmem_base(note,self.note_map, + self.nid_trans): + return + GrampsDbBase.commit_note(self,note,transaction,change_time) + def get_person_from_gramps_id(self,val): handle = self.id_trans.get(str(val)) if handle: @@ -359,6 +376,16 @@ class GrampsInMemDB(GrampsDbBase): return repository return None + def get_note_from_gramps_id(self,val): + handle = self.nid_trans.get(str(val)) + if handle: + data = self.note_map[handle] + if data: + note = Note() + note.unserialize(data) + return note + return None + def get_object_from_gramps_id(self,val): handle = self.oid_trans.get(str(val)) if handle: diff --git a/src/GrampsDbUtils/_ReadXML.py b/src/GrampsDbUtils/_ReadXML.py index 5649dc810..cf7857ec7 100644 --- a/src/GrampsDbUtils/_ReadXML.py +++ b/src/GrampsDbUtils/_ReadXML.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -715,9 +715,11 @@ class GrampsParser(UpdateCallback): self.in_witness = True self.witness_comment = "" if attrs.has_key('name'): - note_text = self.event.get_note(markup=True) + "\n" + \ - _("Witness name: %s") % attrs['name'] - self.event.set_note(note_text) + note = RelLib.Note() + note.handle = Utils.create_id() + note.set(_("Witness name: %s") % attrs['name']) + self.db.add_note(note,self.trans) + self.event.add_note(note.handle) return try: @@ -1081,9 +1083,30 @@ class GrampsParser(UpdateCallback): self.name.group_as = attrs.get('group','') def start_note(self,attrs): - self.in_note = 1 - self.note = RelLib.Note() - self.note.format = int(attrs.get('format',0)) + self.in_note = 0 + if self.address or self.attribute or self.childref or self.event \ + or self.eventref or self.family or self.ord or self.object \ + or self.objref or self.name or self.person or self.personref \ + or self.placeobj or self.reporef or self.repo or self.source \ + or self.source_ref or self.photo: + # GRAMPS LEGACY: old notes that were written inside other objects + self.note = RelLib.Note() + self.note.handle = Utils.create_id() + self.note.format = int(attrs.get('format',RelLib.Note.FLOWED)) + self.db.add_note(self.note,self.trans) + else: + # This is new note, with ID and handle already existing + self.update(self.p.CurrentLineNumber) + gramps_id = self.map_eid(attrs["id"]) + try: + self.note = self.db.find_note_from_handle( + attrs['handle'].replace('_',''),self.trans) + self.note.gramps_id = gramps_id + except KeyError: + self.note = self.find_note_by_gramps_id(gramps_id) + self.note.private = bool(attrs.get("priv")) + self.note.format = int(attrs.get('format',RelLib.Note.FLOWED)) + self.note.type.set_from_xml_str(attrs['type']) def start_sourceref(self,attrs): self.source_ref = RelLib.SourceRef() @@ -1434,13 +1457,18 @@ class GrampsParser(UpdateCallback): def stop_witness(self,tag): # Parse witnesses created by older gramps if self.witness_comment: - note_text = self.event.get_note(markup=True) + "\n" + \ - _("Witness comment: %s") % self.witness_comment - self.event.set_note(note_text) + text = self.witness_comment elif tag.strip(): - note_text = self.event.get_note(markup=True) + "\n" + \ - _("Witness comment: %s") % tag - self.event.set_note(note_text) + text = tag + else: + text = None + + if text != None: + note = RelLib.Note() + note.handle = Utils.create_id() + note.set(_("Witness comment: %s") % text) + self.db.add_note(note,self.trans) + self.event.add_note(note.handle) self.in_witness = False def stop_attr_type(self,tag): @@ -1540,9 +1568,11 @@ class GrampsParser(UpdateCallback): def stop_name(self,tag): if self.in_witness: # Parse witnesses created by older gramps - note_text = self.event.get_note(markup=True) + "\n" + \ - _("Witness name: %s") % tag - self.event.set_note(note_text) + note = RelLib.Note() + note.handle = Utils.create_id() + note.set(_("Witness name: %s") % tag) + self.db.add_note(note,self.trans) + self.event.add_note(note.handle) elif self.alt_name: # former aka tag -- alternate name if self.name.get_type() == "": @@ -1681,10 +1711,14 @@ class GrampsParser(UpdateCallback): def stop_scomments(self,tag): if self.use_p: self.use_p = 0 - note = fix_spaces(self.scomments_list) + text = fix_spaces(self.scomments_list) else: - note = tag - self.source_ref.set_note(note) + text = tag + note = RelLib.Note() + note.handle = Utils.create_id() + note.set(text) + self.db.add_note(note,self.trans) + self.source_ref.add_note(note.handle) def stop_last(self,tag): if self.name: @@ -1719,39 +1753,42 @@ class GrampsParser(UpdateCallback): self.note.set(text) if self.address: - self.address.set_note_object(self.note) + self.address.add_note(self.note.handle) elif self.ord: - self.ord.set_note_object(self.note) + self.ord.add_note(self.note.handle) elif self.attribute: - self.attribute.set_note_object(self.note) + self.attribute.add_note(self.note.handle) elif self.object: - self.object.set_note_object(self.note) + self.object.add_note(self.note.handle) elif self.objref: - self.objref.set_note_object(self.note) + self.objref.add_note(self.note.handle) elif self.photo: - self.photo.set_note_object(self.note) + self.photo.add_note(self.note.handle) elif self.name: - self.name.set_note_object(self.note) + self.name.add_note(self.note.handle) elif self.source: - self.source.set_note_object(self.note) + self.source.add_note(self.note.handle) elif self.event: - self.event.set_note_object(self.note) + self.event.add_note(self.note.handle) elif self.personref: - self.personref.set_note_object(self.note) + self.personref.add_note(self.note.handle) elif self.person: - self.person.set_note_object(self.note) + self.person.add_note(self.note.handle) elif self.childref: - self.childref.set_note_object(self.note) + self.childref.add_note(self.note.handle) elif self.family: - self.family.set_note_object(self.note) + self.family.add_note(self.note.handle) elif self.placeobj: - self.placeobj.set_note_object(self.note) + self.placeobj.add_note(self.note.handle) elif self.eventref: - self.eventref.set_note_object(self.note) + self.eventref.add_note(self.note.handle) elif self.repo: - self.repo.set_note_object(self.note) + self.repo.add_note(self.note.handle) elif self.reporef: - self.reporef.set_note_object(self.note) + self.reporef.add_note(self.note.handle) + + self.db.commit_note(self.note,self.trans,self.change) + self.note = None def stop_research(self,tag): self.owner.set(self.resname, self.resaddr, self.rescity, self.resstate, diff --git a/src/RelLib/_Address.py b/src/RelLib/_Address.py index d98f53b71..a45d62aba 100644 --- a/src/RelLib/_Address.py +++ b/src/RelLib/_Address.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -71,11 +71,11 @@ class Address(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase, """ Converts a serialized tuple of data to an object """ - (privacy, source_list, note, date, location) = data + (privacy, source_list, note_list, date, location) = data PrivacyBase.unserialize(self, privacy) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) DateBase.unserialize(self, date) LocationBase.unserialize(self, location) return self @@ -96,10 +96,7 @@ class Address(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase, @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.source_list - if self.note: - check_list.append(self.note) - return check_list + return self.source_list def get_handle_referents(self): """ @@ -110,3 +107,13 @@ class Address(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase, @rtype: list """ return self.source_list + + def get_referenced_handles(self): + """ + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: List of (classname,handle) tuples for referenced objects. + @rtype: list + """ + return self.get_referenced_note_handles() diff --git a/src/RelLib/_Attribute.py b/src/RelLib/_Attribute.py index 91d2359bc..64184ae3d 100644 --- a/src/RelLib/_Attribute.py +++ b/src/RelLib/_Attribute.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -75,10 +75,10 @@ class Attribute(SecondaryObject, PrivacyBase, SourceBase, NoteBase): """ Converts a serialized tuple of data to an object """ - (privacy, source_list, note, the_type, self.value) = data + (privacy, source_list, note_list, the_type, self.value) = data PrivacyBase.unserialize(self, privacy) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) self.type.unserialize(the_type) return self @@ -98,10 +98,7 @@ class Attribute(SecondaryObject, PrivacyBase, SourceBase, NoteBase): @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.source_list - if self.note: - check_list.append(self.note) - return check_list + return self.source_list def get_handle_referents(self): """ @@ -113,6 +110,16 @@ class Attribute(SecondaryObject, PrivacyBase, SourceBase, NoteBase): """ return self.source_list + def get_referenced_handles(self): + """ + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: List of (classname,handle) tuples for referenced objects. + @rtype: list + """ + return self.get_referenced_note_handles() + def set_type(self, val): """sets the type (or key) of the Attribute instance""" self.type.set(val) diff --git a/src/RelLib/_BasicPrimaryObject.py b/src/RelLib/_BasicPrimaryObject.py new file mode 100644 index 000000000..cffc0a473 --- /dev/null +++ b/src/RelLib/_BasicPrimaryObject.py @@ -0,0 +1,213 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2007 Donald N. Allingham +# +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +""" +Basic Primary Object class for GRAMPS +""" + +__revision__ = "$Revision$" + +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- +import time +import GrampsLocale + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _BaseObject import BaseObject +from _PrivacyBase import PrivacyBase +from _MarkerType import MarkerType + +#------------------------------------------------------------------------- +# +# Localized constants +# +#------------------------------------------------------------------------- +_codeset = GrampsLocale.codeset + +#------------------------------------------------------------------------- +# +# Basic Primary Object class +# +#------------------------------------------------------------------------- +class BasicPrimaryObject(BaseObject, PrivacyBase): + """ + The BasicPrimaryObject is the base class for Note objects. + It is also the base class for the PrimaryObject class. + + The PrimaryObject is the base class for all other primary objects in the + database. Primary objects are the core objects in the database. + Each object has a database handle and a GRAMPS ID value. The database + handle is used as the record number for the database, and the GRAMPS + ID is the user visible version. + """ + + def __init__(self, source=None): + """ + Initialize a PrimaryObject. If source is None, both the ID and handle + are assigned as empty strings. If source is not None, then object + is initialized from values of the source object. + + @param source: Object used to initialize the new object + @type source: PrimaryObject + """ + BaseObject.__init__(self) + PrivacyBase.__init__(self, source) + if source: + self.gramps_id = source.gramps_id + self.handle = source.handle + self.change = source.change + self.marker = source.marker + else: + self.gramps_id = None + self.handle = None + self.change = 0 + self.marker = MarkerType() + + def get_change_time(self): + """ + Returns the time that the data was last changed. The value + in the format returned by the time.time() command. + + @returns: Time that the data was last changed. The value + in the format returned by the time.time() command. + @rtype: int + """ + return self.change + + def get_change_display(self): + """ + Returns the string representation of the last change time. + + @returns: string representation of the last change time. + @rtype: str + + """ + if self.change: + return unicode(time.strftime('%x %X', time.localtime(self.change)), + _codeset) + else: + return u'' + + def set_handle(self, handle): + """ + Sets the database handle for the primary object + + @param handle: object database handle + @type handle: str + """ + self.handle = handle + + def get_handle(self): + """ + Returns the database handle for the primary object + + @returns: database handle associated with the object + @rtype: str + """ + return self.handle + + def set_gramps_id(self, gramps_id): + """ + Sets the GRAMPS ID for the primary object + + @param gramps_id: GRAMPS ID + @type gramps_id: str + """ + self.gramps_id = gramps_id + + def get_gramps_id(self): + """ + Returns the GRAMPS ID for the primary object + + @returns: GRAMPS ID associated with the object + @rtype: str + """ + return self.gramps_id + + def has_handle_reference(self, classname, handle): + """ + Returns True if the object has reference to a given handle + of given primary object type. + + @param classname: The name of the primary object class. + @type classname: str + @param handle: The handle to be checked. + @type handle: str + @return: Returns whether the object has reference to this handle of this object type. + @rtype: bool + """ + return False + + def remove_handle_references(self, classname, handle_list): + """ + Removes all references in this object to object handles in the list. + + @param classname: The name of the primary object class. + @type classname: str + @param handle_list: The list of handles to be removed. + @type handle_list: str + """ + pass + + def replace_handle_reference(self, classname, old_handle, new_handle): + """ + Replaces all references to old handle with those to the new handle. + + @param classname: The name of the primary object class. + @type classname: str + @param old_handle: The handle to be replaced. + @type old_handle: str + @param new_handle: The handle to replace the old one with. + @type new_handle: str + """ + pass + + def set_marker(self, marker): + self.marker.set(marker) + + def get_marker(self): + return self.marker + + def has_source_reference(self, handle): + return False + + def has_media_reference(self, handle): + return False + + def remove_source_references(self, handle_list): + pass + + def remove_media_references(self, handle_list): + pass + + def replace_source_references(self, old_handle, new_handle): + pass + + def replace_media_references(self, old_handle, new_handle): + pass diff --git a/src/RelLib/_ChildRef.py b/src/RelLib/_ChildRef.py index 0d6f9bbee..7c5b58c9b 100644 --- a/src/RelLib/_ChildRef.py +++ b/src/RelLib/_ChildRef.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2006 Donald N. Allingham +# Copyright (C) 2006-2007 Donald N. Allingham # # 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 @@ -80,10 +80,10 @@ class ChildRef(SecondaryObject, PrivacyBase, SourceBase, NoteBase, RefBase): """ Converts a serialized tuple of data to an object """ - (privacy, source_list, note, ref, frel, mrel) = data + (privacy, source_list, note_list, ref, frel, mrel) = data PrivacyBase.unserialize(self, privacy) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) RefBase.unserialize(self, ref) self.frel.unserialize(frel) self.mrel.unserialize(mrel) @@ -105,23 +105,20 @@ class ChildRef(SecondaryObject, PrivacyBase, SourceBase, NoteBase, RefBase): @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.source_list - if self.note: - check_list.append(self.note) - return check_list + return self.source_list def get_referenced_handles(self): """ Returns the list of (classname,handle) tuples for all directly referenced primary objects. - @return: Returns the list of (classname,handle) tuples for referenced objects. + @return: List of (classname,handle) tuples for referenced objects. @rtype: list """ + ret = self.get_referenced_note_handles() if self.ref: - return [('Person', self.ref)] - else: - return [] + ret += [('Person', self.ref)] + return ret def get_handle_referents(self): """ diff --git a/src/RelLib/_Event.py b/src/RelLib/_Event.py index 042018c6a..1c1043f39 100644 --- a/src/RelLib/_Event.py +++ b/src/RelLib/_Event.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -114,7 +114,7 @@ class Event(SourceBase, NoteBase, MediaBase, AttributeBase, """ (self.handle, self.gramps_id, the_type, date, self.description, self.place, - source_list, note, media_list, attribute_list, + source_list, note_list, media_list, attribute_list, self.change, marker, self.private) = data self.marker.unserialize(marker) @@ -123,7 +123,7 @@ class Event(SourceBase, NoteBase, MediaBase, AttributeBase, MediaBase.unserialize(self, media_list) AttributeBase.unserialize(self, attribute_list) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) def _has_handle_reference(self, classname, handle): """ @@ -183,10 +183,7 @@ class Event(SourceBase, NoteBase, MediaBase, AttributeBase, @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.media_list + self.source_list + self.attribute_list - if self.note: - check_list.append(self.note) - return check_list + return self.media_list + self.source_list + self.attribute_list def get_sourcref_child_list(self): """ @@ -202,10 +199,10 @@ class Event(SourceBase, NoteBase, MediaBase, AttributeBase, Returns the list of (classname,handle) tuples for all directly referenced primary objects. - @return: Returns the list of (classname,handle) tuples for referenced objects. + @return: List of (classname,handle) tuples for referenced objects. @rtype: list """ - ret = [] + ret = self.get_referenced_note_handles() if self.place: ret.append(('Place', self.place)) return ret diff --git a/src/RelLib/_EventRef.py b/src/RelLib/_EventRef.py index 6b84b16bb..1aae70643 100644 --- a/src/RelLib/_EventRef.py +++ b/src/RelLib/_EventRef.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -81,9 +81,9 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase): """ Converts a serialized tuple of data to an object """ - (privacy, note, attribute_list, ref, role) = data + (privacy, note_list, attribute_list, ref, role) = data PrivacyBase.unserialize(self, privacy) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) AttributeBase.unserialize(self, attribute_list) RefBase.unserialize(self, ref) self.role.unserialize(role) @@ -105,10 +105,7 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase): @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.attribute_list[:] - if self.note: - check_list.append(self.note) - return check_list + return self.attribute_list[:] def get_sourcref_child_list(self): """ @@ -127,10 +124,10 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase): @return: Returns the list of (classname,handle) tuples for referenced objects. @rtype: list """ + ret = self.get_referenced_note_handles() if self.ref: - return [('Event', self.ref)] - else: - return [] + ret += [('Event', self.ref)] + return ret def get_role(self): """ diff --git a/src/RelLib/_Family.py b/src/RelLib/_Family.py index 53d727f4d..8ee3ce436 100644 --- a/src/RelLib/_Family.py +++ b/src/RelLib/_Family.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -130,7 +130,7 @@ class Family(SourceBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase, """ (self.handle, self.gramps_id, self.father_handle, self.mother_handle, child_ref_list, the_type, event_ref_list, media_list, - attribute_list, lds_seal_list, source_list, note, + attribute_list, lds_seal_list, source_list, note_list, self.change, marker, self.private) = data self.marker.unserialize(marker) @@ -142,7 +142,7 @@ class Family(SourceBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase, MediaBase.unserialize(self, media_list) AttributeBase.unserialize(self, attribute_list) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) LdsOrdBase.unserialize(self, lds_seal_list) def _has_handle_reference(self, classname, handle): @@ -240,8 +240,7 @@ class Family(SourceBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase, @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.lds_ord_list + [self.note] - add_list = [item for item in check_list if item] + add_list = [item for item in self.lds_ord_list if item] return self.media_list + self.attribute_list + \ self.source_list + add_list @@ -261,10 +260,10 @@ class Family(SourceBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase, Returns the list of (classname,handle) tuples for all directly referenced primary objects. - @return: Returns the list of (classname,handle) tuples for referenced objects. + @return: List of (classname,handle) tuples for referenced objects. @rtype: list """ - ret = [] + ret = self.get_referenced_note_handles() ret += [('Event', ref.ref) for ref in self.event_ref_list] ret += [('Person', handle) for handle in ([ref.ref for ref in self.child_ref_list] + diff --git a/src/RelLib/_LdsOrd.py b/src/RelLib/_LdsOrd.py index e13dc240e..0f1ae6e38 100644 --- a/src/RelLib/_LdsOrd.py +++ b/src/RelLib/_LdsOrd.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -146,10 +146,10 @@ class LdsOrd(SecondaryObject, SourceBase, NoteBase, """ Converts a serialized tuple of data to an object """ - (source_list, note, date, self.type, self.place, + (source_list, note_list, date, self.type, self.place, self.famc, self.temple, self.status) = data SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) DateBase.unserialize(self, date) return self @@ -170,23 +170,20 @@ class LdsOrd(SecondaryObject, SourceBase, NoteBase, @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.source_list - if self.note: - check_list.append(self.note) - return check_list + return self.source_list def get_referenced_handles(self): """ Returns the list of (classname,handle) tuples for all directly referenced primary objects. - @return: Returns the list of (classname,handle) tuples for referenced objects. + @return: List of (classname,handle) tuples for referenced objects. @rtype: list """ + ret = self.get_referenced_note_handles() if self.place: - return [('Place', self.place)] - else: - return [] + ret += [('Place', self.place)] + return ret def get_handle_referents(self): """ diff --git a/src/RelLib/_MediaObject.py b/src/RelLib/_MediaObject.py index 8bb8bb275..0d500b64a 100644 --- a/src/RelLib/_MediaObject.py +++ b/src/RelLib/_MediaObject.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -114,13 +114,13 @@ class MediaObject(SourceBase,NoteBase,DateBase,AttributeBase,PrimaryObject): @type data: tuple """ (self.handle, self.gramps_id, self.path, self.mime, self.desc, - attribute_list, source_list, note, self.change, + attribute_list, source_list, note_list, self.change, date, marker, self.private) = data self.marker.unserialize(marker) AttributeBase.unserialize(self, attribute_list) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) DateBase.unserialize(self, date) def get_text_data_list(self): @@ -139,10 +139,7 @@ class MediaObject(SourceBase,NoteBase,DateBase,AttributeBase,PrimaryObject): @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.attribute_list + self.source_list - if self.note: - check_list.append(self.note) - return check_list + return self.attribute_list + self.source_list def get_sourcref_child_list(self): """ @@ -153,6 +150,16 @@ class MediaObject(SourceBase,NoteBase,DateBase,AttributeBase,PrimaryObject): """ return self.attribute_list + def get_referenced_handles(self): + """ + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: List of (classname,handle) tuples for referenced objects. + @rtype: list + """ + return self.get_referenced_note_handles() + def get_handle_referents(self): """ Returns the list of child objects which may, directly or through diff --git a/src/RelLib/_MediaRef.py b/src/RelLib/_MediaRef.py index 3730ec53b..b81df5223 100644 --- a/src/RelLib/_MediaRef.py +++ b/src/RelLib/_MediaRef.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -75,10 +75,10 @@ class MediaRef(SecondaryObject, PrivacyBase, SourceBase, NoteBase, RefBase, """ Converts a serialized tuple of data to an object """ - (privacy, source_list, note, attribute_list, ref, self.rect) = data + (privacy,source_list,note_list,attribute_list,ref,self.rect) = data PrivacyBase.unserialize(self, privacy) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) AttributeBase.unserialize(self, attribute_list) RefBase.unserialize(self, ref) return self @@ -90,10 +90,7 @@ class MediaRef(SecondaryObject, PrivacyBase, SourceBase, NoteBase, RefBase, @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.attribute_list + self.source_list - if self.note: - check_list.append(self.note) - return check_list + return self.attribute_list + self.source_list def get_sourcref_child_list(self): """ @@ -109,13 +106,13 @@ class MediaRef(SecondaryObject, PrivacyBase, SourceBase, NoteBase, RefBase, Returns the list of (classname,handle) tuples for all directly referenced primary objects. - @return: Returns the list of (classname,handle) tuples for referenced objects. + @return: List of (classname,handle) tuples for referenced objects. @rtype: list """ + ret = self.get_referenced_note_handles() if self.ref: - return [('MediaObject', self.ref)] - else: - return [] + ret += [('MediaObject', self.ref)] + return ret def get_handle_referents(self): """ diff --git a/src/RelLib/_Name.py b/src/RelLib/_Name.py index a6682fa86..b089e6991 100644 --- a/src/RelLib/_Name.py +++ b/src/RelLib/_Name.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -122,14 +122,14 @@ class Name(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase): """ Converts a serialized tuple of data to an object """ - (privacy, source_list, note, date, + (privacy, source_list, note_list, date, self.first_name, self.surname, self.suffix, self.title, name_type, self.prefix, self.patronymic, self.group_as, self.sort_as, self.display_as, self.call) = data self.type.unserialize(name_type) PrivacyBase.unserialize(self, privacy) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) DateBase.unserialize(self, date) return self @@ -150,10 +150,7 @@ class Name(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase): @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.source_list - if self.note: - check_list.append(self.note) - return check_list + return self.source_list def get_handle_referents(self): """ @@ -165,6 +162,16 @@ class Name(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase): """ return self.source_list + def get_referenced_handles(self): + """ + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: List of (classname,handle) tuples for referenced objects. + @rtype: list + """ + return self.get_referenced_note_handles() + def set_group_as(self, name): """ Sets the grouping name for a person. Normally, this is the person's diff --git a/src/RelLib/_Note.py b/src/RelLib/_Note.py index ad15a8c93..241edfc1c 100644 --- a/src/RelLib/_Note.py +++ b/src/RelLib/_Note.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -26,6 +26,11 @@ Note class for GRAMPS __revision__ = "$Revision$" +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- import re #------------------------------------------------------------------------- @@ -33,14 +38,15 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -from _SecondaryObject import SecondaryObject +from _BasicPrimaryObject import BasicPrimaryObject +from _NoteType import NoteType #------------------------------------------------------------------------- # # Class for notes used throughout the majority of GRAMPS objects # #------------------------------------------------------------------------- -class Note(SecondaryObject): +class Note(BasicPrimaryObject): """ Introduction ============ @@ -49,27 +55,34 @@ class Note(SecondaryObject): to be in paragraphs, separated by newlines. """ + FLOWED = 0 + FORMATTED = 1 + def __init__(self, text = ""): """ Creates a new Note object, initializing from the passed string. """ - SecondaryObject.__init__(self) + BasicPrimaryObject.__init__(self) self.text = text - self.format = 0 + self.format = Note.FLOWED + self.type = NoteType() def serialize(self): """ Converts the object to a serialized tuple of data """ - return (self.text, self.format) + return (self.handle,self.gramps_id,self.text,self.format, + self.type.serialize(),self.marker.serialize(),self.private) def unserialize(self, data): """ Converts a serialized tuple of data to an object """ - if data: - (self.text, self.format) = data - return self + (self.handle,self.gramps_id,self.text,self.format, + the_type,the_marker,self.private) = data + + self.marker.unserialize(the_marker) + self.type.unserialize(the_type) def get_text_data_list(self): """ @@ -152,6 +165,7 @@ class Note(SecondaryObject): """ return self.format + if __name__ == "__main__": import hotshot prof = hotshot.Profile("note.profile") diff --git a/src/RelLib/_NoteBase.py b/src/RelLib/_NoteBase.py index aee4603ab..eb15ec424 100644 --- a/src/RelLib/_NoteBase.py +++ b/src/RelLib/_NoteBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -26,13 +26,6 @@ NoteBase class for GRAMPS __revision__ = "$Revision$" -#------------------------------------------------------------------------- -# -# GRAMPS modules -# -#------------------------------------------------------------------------- -from _Note import Note - #------------------------------------------------------------------------- # # NoteBase class @@ -41,6 +34,10 @@ from _Note import Note class NoteBase: """ Base class for storing notes. + + Starting in 2.3 branch, the objects may have multiple notes. + Internally, this class maintains a list of Note handles, + as a note_list attribute of the NoteBase object. """ def __init__(self, source=None): """ @@ -50,90 +47,80 @@ class NoteBase: @type source: NoteBase """ - if source and source.note: - text = source.note.get() + if source: + self.note_list = [handle for handle in source.note_list] else: - text = "" - self.note = Note(text) + self.note_list = [] def serialize(self): """ Converts the object to a serialized tuple of data """ - if self.note == None: - self.note = Note() - return self.note.serialize() + return self.note_list def unserialize(self, data): """ Converts a serialized tuple of data to an object """ - if data is not None: - self.note = Note().unserialize(data) + self.note_list = [handle for handle in data] - def set_note(self, text): + def add_note(self,handle): """ - Assigns the specified text to the associated note. + Adds the L{Note} handle to the list of note handles. - @param text: Text of the note - @type text: str - """ - if not self.note: - self.note = Note() - self.note.set(text) + @param handle: L{Note} handle to add the list of notes + @type handle: str - def get_note(self, markup=False): - """ - Returns the text of the current note. - - @returns: the text of the current note - @rtype: str - """ - if self.note: - return self.note.get(markup) - return "" - - def set_note_format(self, val): - """ - Sets the note's format to the given value. The format indicates - whether the text is flowed (wrapped) or preformatted. - - @param val: True indicates the text is flowed - @type val: bool - """ - if self.note: - self.note.set_format(val) - - def get_note_format(self): - """ - Returns the current note's format - - @returns: True indicates that the note should be flowed (wrapped) + @return: True if handle was added, False if it already was in the list @rtype: bool """ - if self.note == None: + if handle in self.note_list: return False else: - return self.note.get_format() + self.note_list.append(handle) + return True - def set_note_object(self, note_obj): + def remove_note(self,handle): """ - Replaces the current L{Note} object associated with the object + Removes the specified handle from the list of note handles. - @param note_obj: New L{Note} object to be assigned - @type note_obj: L{Note} + @param handle: L{Note} handle to remove from the list of notes + @type handle: str + + @return: True if handle was removed, False if it was not in the list + @rtype: bool """ - self.note = note_obj + if handle in self.note_list: + self.note_list.remove(handle) + return True + else: + return False - def get_note_object(self): + def get_note_list(self): """ - Returns the L{Note} instance associated with the object. + Returns the list of L{Note} handles associated with the object - @returns: L{Note} object assocated with the object - @rtype: L{Note} + @return: The list of L{Note} handles + @rtype: list """ - return self.note + return self.note_list - def unique_note(self): - """Creates a unique instance of the current note""" - self.note = Note(self.note.get()) + def set_note_list(self,note_list): + """ + Assign the passed list to be object's list of L{Note} handles. + + @param note_list: List of L{Note} handles to be set on the object + @type note_list: list + """ + self.note_list = note_list + + def get_referenced_note_handles(self): + """ + Returns the list of (classname,handle) tuples for all referenced notes. + This method should be used to get the L{Note} portion of the list + by objects that store note lists. + + @return: List of (classname,handle) tuples for referenced objects. + @rtype: list + """ + return [('Note',handle) for handle in self.note_list] diff --git a/src/RelLib/_NoteType.py b/src/RelLib/_NoteType.py new file mode 100644 index 000000000..155ce3094 --- /dev/null +++ b/src/RelLib/_NoteType.py @@ -0,0 +1,66 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2007 Donald N. Allingham +# +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +""" +Note types +""" + +__revision__ = "$Revision$" + +#------------------------------------------------------------------------- +# +# standard python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from _GrampsType import GrampsType, init_map + +class NoteType(GrampsType): + + UNKNOWN = -1 + CUSTOM = 0 + GENERAL = 1 + RESEARCH = 2 + + _CUSTOM = CUSTOM + _DEFAULT = GENERAL + + _DATAMAP = [ + (UNKNOWN, _("Unknown"), "Unknown"), + (CUSTOM, _("Custom"), "Custom"), + (GENERAL, _("General"), "General"), + (RESEARCH, _("Research"), "Research"), + ] + + _I2SMAP = init_map(_DATAMAP, 0, 1) + _S2IMAP = init_map(_DATAMAP, 1, 0) + _I2EMAP = init_map(_DATAMAP, 0, 2) + _E2IMAP = init_map(_DATAMAP, 2, 0) + + def __init__(self, value=None): + GrampsType.__init__(self, value) diff --git a/src/RelLib/_Person.py b/src/RelLib/_Person.py index 3353e190c..75eaa4d14 100644 --- a/src/RelLib/_Person.py +++ b/src/RelLib/_Person.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -175,7 +175,7 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase, urls, # 13 lds_ord_list, # 14 source_list, # 15 - note, # 16 + note_list, # 16 self.change, # 17 marker, # 18 self.private, # 19 @@ -196,7 +196,7 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase, AttributeBase.unserialize(self, attribute_list) UrlBase.unserialize(self, urls) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) def _has_handle_reference(self, classname, handle): """ @@ -321,11 +321,12 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase, Returns the list of (classname, handle) tuples for all directly referenced primary objects. - @return: Returns the list of (classname, handle) tuples for referenced objects. + @return: List of (classname, handle) tuples for referenced objects. @rtype: list """ return [('Family', handle) for handle in - (self.family_list + self.parent_family_list)] + (self.family_list + self.parent_family_list)] \ + + self.get_referenced_note_handles() def get_handle_referents(self): """ diff --git a/src/RelLib/_PersonRef.py b/src/RelLib/_PersonRef.py index 44c5f2270..ad2917666 100644 --- a/src/RelLib/_PersonRef.py +++ b/src/RelLib/_PersonRef.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2006 Donald N. Allingham +# Copyright (C) 2006-2007 Donald N. Allingham # # 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 @@ -76,10 +76,10 @@ class PersonRef(SecondaryObject, PrivacyBase, SourceBase, NoteBase, RefBase): """ Converts a serialized tuple of data to an object """ - (privacy, source_list, note, ref, self.rel) = data + (privacy, source_list, note_list, ref, self.rel) = data PrivacyBase.unserialize(self, privacy) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) RefBase.unserialize(self, ref) return self @@ -99,23 +99,20 @@ class PersonRef(SecondaryObject, PrivacyBase, SourceBase, NoteBase, RefBase): @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.source_list - if self.note: - check_list.append(self.note) - return check_list + return self.source_list def get_referenced_handles(self): """ Returns the list of (classname,handle) tuples for all directly referenced primary objects. - @return: Returns the list of (classname,handle) tuples for referenced objects. + @return: List of (classname,handle) tuples for referenced objects. @rtype: list """ + ret = self.get_referenced_note_handles() if self.ref: - return [('Person', self.ref)] - else: - return [] + ret += [('Person', self.ref)] + return ret def get_handle_referents(self): """ diff --git a/src/RelLib/_Place.py b/src/RelLib/_Place.py index d24a172ed..0d57fda34 100644 --- a/src/RelLib/_Place.py +++ b/src/RelLib/_Place.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -117,7 +117,7 @@ class Place(SourceBase, NoteBase, MediaBase, UrlBase, PrimaryObject): @type data: tuple """ (self.handle, self.gramps_id, self.title, self.long, self.lat, - main_loc, alt_loc, urls, media_list, source_list, note, + main_loc, alt_loc, urls, media_list, source_list, note_list, self.change, marker, self.private) = data if main_loc == None: @@ -129,7 +129,7 @@ class Place(SourceBase, NoteBase, MediaBase, UrlBase, PrimaryObject): UrlBase.unserialize(self, urls) MediaBase.unserialize(self, media_list) SourceBase.unserialize(self, source_list) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) def get_text_data_list(self): """ @@ -148,16 +148,16 @@ class Place(SourceBase, NoteBase, MediaBase, UrlBase, PrimaryObject): @rtype: list """ - check_list = [self.main_loc, self.note] - add_list = [item for item in check_list if item] - return self.media_list + self.source_list + self.alt_loc \ - + self.urls + add_list + ret = self.media_list + self.source_list + self.alt_loc + self.urls + if self.main_loc: + ret.append(self.main_loc) + return ret def get_sourcref_child_list(self): """ Returns the list of child secondary objects that may refer sources. - @return: Returns the list of child secondary child objects that may refer sources. + @return: List of child secondary child objects that may refer sources. @rtype: list """ return self.media_list @@ -172,6 +172,16 @@ class Place(SourceBase, NoteBase, MediaBase, UrlBase, PrimaryObject): """ return self.media_list + self.source_list + def get_referenced_handles(self): + """ + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: List of (classname,handle) tuples for referenced objects. + @rtype: list + """ + return self.get_referenced_note_handles() + def set_title(self, title): """ Sets the descriptive title of the Place object diff --git a/src/RelLib/_PrimaryObject.py b/src/RelLib/_PrimaryObject.py index 4adf88c66..c0ad0fdfe 100644 --- a/src/RelLib/_PrimaryObject.py +++ b/src/RelLib/_PrimaryObject.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -39,11 +39,9 @@ import GrampsLocale # GRAMPS modules # #------------------------------------------------------------------------- -from _BaseObject import BaseObject -from _PrivacyBase import PrivacyBase +from _BasicPrimaryObject import BasicPrimaryObject from _SourceBase import SourceBase from _MediaBase import MediaBase -from _MarkerType import MarkerType #------------------------------------------------------------------------- # @@ -57,7 +55,7 @@ _codeset = GrampsLocale.codeset # Primary Object class # #------------------------------------------------------------------------- -class PrimaryObject(BaseObject, PrivacyBase): +class PrimaryObject(BasicPrimaryObject): """ The PrimaryObject is the base class for all primary objects in the database. Primary objects are the core objects in the database. @@ -68,86 +66,14 @@ class PrimaryObject(BaseObject, PrivacyBase): def __init__(self, source=None): """ -o Initialize a PrimaryObject. If source is None, both the ID and handle + Initialize a PrimaryObject. If source is None, both the ID and handle are assigned as empty strings. If source is not None, then object is initialized from values of the source object. @param source: Object used to initialize the new object @type source: PrimaryObject """ - BaseObject.__init__(self) - PrivacyBase.__init__(self, source) - if source: - self.gramps_id = source.gramps_id - self.handle = source.handle - self.change = source.change - self.marker = source.marker - else: - self.gramps_id = None - self.handle = None - self.change = 0 - self.marker = MarkerType() - - def get_change_time(self): - """ - Returns the time that the data was last changed. The value - in the format returned by the time.time() command. - - @returns: Time that the data was last changed. The value - in the format returned by the time.time() command. - @rtype: int - """ - return self.change - - def get_change_display(self): - """ - Returns the string representation of the last change time. - - @returns: string representation of the last change time. - @rtype: str - - """ - if self.change: - return unicode(time.strftime('%x %X', time.localtime(self.change)), - _codeset) - else: - return u'' - - def set_handle(self, handle): - """ - Sets the database handle for the primary object - - @param handle: object database handle - @type handle: str - """ - self.handle = handle - - def get_handle(self): - """ - Returns the database handle for the primary object - - @returns: database handle associated with the object - @rtype: str - """ - return self.handle - - def set_gramps_id(self, gramps_id): - """ - Sets the GRAMPS ID for the primary object - - @param gramps_id: GRAMPS ID - @type gramps_id: str - """ - self.gramps_id = gramps_id - - def get_gramps_id(self): - """ - Returns the GRAMPS ID for the primary object - - @returns: GRAMPS ID associated with the object - @rtype: str - """ - return self.gramps_id + BasicPrimaryObject.__init__(self, source) def has_handle_reference(self, classname, handle): """ @@ -225,21 +151,3 @@ o Initialize a PrimaryObject. If source is None, both the ID and handle def get_marker(self): return self.marker - - def has_source_reference(self, handle): - return False - - def has_media_reference(self, handle): - return False - - def remove_source_references(self, handle_list): - pass - - def remove_media_references(self, handle_list): - pass - - def replace_source_references(self, old_handle, new_handle): - pass - - def replace_media_references(self, old_handle, new_handle): - pass diff --git a/src/RelLib/_RepoRef.py b/src/RelLib/_RepoRef.py index 110e30715..bd87d14da 100644 --- a/src/RelLib/_RepoRef.py +++ b/src/RelLib/_RepoRef.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -70,9 +70,9 @@ class RepoRef(SecondaryObject, NoteBase, RefBase): """ Converts a serialized tuple of data to an object """ - (note, ref, self.call_number, media_type) = data + (note_list, ref, self.call_number, media_type) = data self.media_type.unserialize(media_type) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) RefBase.unserialize(self, ref) return self @@ -85,29 +85,18 @@ class RepoRef(SecondaryObject, NoteBase, RefBase): """ return [self.call_number, str(self.media_type)] - def get_text_data_child_list(self): - """ - Returns the list of child objects that may carry textual data. - - @return: Returns the list of child objects that may carry textual data. - @rtype: list - """ - if self.note: - return [self.note] - return [] - def get_referenced_handles(self): """ Returns the list of (classname,handle) tuples for all directly referenced primary objects. - @return: Returns the list of (classname,handle) tuples for referenced objects. + @return: List of (classname,handle) tuples for referenced objects. @rtype: list """ + ret = self.get_referenced_note_handles() if self.ref: - return [('Repository', self.ref)] - else: - return [] + ret += [('Repository', self.ref)] + return ret def set_call_number(self, number): self.call_number = number diff --git a/src/RelLib/_Repository.py b/src/RelLib/_Repository.py index 2f0ded2bd..9fc7ecae8 100644 --- a/src/RelLib/_Repository.py +++ b/src/RelLib/_Repository.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -70,12 +70,12 @@ class Repository(NoteBase, AddressBase, UrlBase, PrimaryObject): Converts the data held in a tuple created by the serialize method back into the data in an Repository structure. """ - (self.handle, self.gramps_id, the_type, self.name, note, + (self.handle, self.gramps_id, the_type, self.name, note_list, address_list, urls, marker, self.private) = data self.marker.unserialize(marker) self.type.unserialize(the_type) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) AddressBase.unserialize(self, address_list) UrlBase.unserialize(self, urls) @@ -95,44 +95,17 @@ class Repository(NoteBase, AddressBase, UrlBase, PrimaryObject): @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.address_list + self.urls - if self.note: - check_list.append(self.note) - return check_list + return self.address_list + self.urls - def has_source_reference(self, src_handle) : + def get_referenced_handles(self): """ - Returns True if any of the child objects has reference - to this source handle. - - @param src_handle: The source handle to be checked. - @type src_handle: str - @return: Returns whether any of it's child objects has reference to this source handle. - @rtype: bool + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: List of (classname,handle) tuples for referenced objects. + @rtype: list """ - return False - - def remove_source_references(self, src_handle_list): - """ - Removes references to all source handles in the list - in all child objects. - - @param src_handle_list: The list of source handles to be removed. - @type src_handle_list: list - """ - pass - - def replace_source_references(self, old_handle, new_handle): - """ - Replaces references to source handles in the list - in this object and all child objects. - - @param old_handle: The source handle to be replaced. - @type old_handle: str - @param new_handle: The source handle to replace the old one with. - @type new_handle: str - """ - pass + return self.get_referenced_note_handles() def set_type(self, the_type): """ diff --git a/src/RelLib/_Source.py b/src/RelLib/_Source.py index 722f7d7c7..30e0ddf6c 100644 --- a/src/RelLib/_Source.py +++ b/src/RelLib/_Source.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -76,12 +76,12 @@ class Source(MediaBase, NoteBase, PrimaryObject): back into the data in an Event structure. """ (self.handle, self.gramps_id, self.title, self.author, - self.pubinfo, note, media_list, + self.pubinfo, note_list, media_list, self.abbrev, self.change, self.datamap, reporef_list, marker, self.private) = data self.marker.unserialize(marker) - NoteBase.unserialize(self, note) + NoteBase.unserialize(self, note_list) MediaBase.unserialize(self, media_list) self.reporef_list = [RepoRef().unserialize(rr) for rr in reporef_list] @@ -150,10 +150,7 @@ class Source(MediaBase, NoteBase, PrimaryObject): @return: Returns the list of child objects that may carry textual data. @rtype: list """ - check_list = self.media_list + self.reporef_list - if self.note: - check_list.append(self.note) - return check_list + return self.media_list + self.reporef_list def get_sourcref_child_list(self): """ @@ -174,6 +171,16 @@ class Source(MediaBase, NoteBase, PrimaryObject): """ return self.media_list + self.reporef_list + def get_referenced_handles(self): + """ + Returns the list of (classname,handle) tuples for all directly + referenced primary objects. + + @return: List of (classname,handle) tuples for referenced objects. + @rtype: list + """ + return self.get_referenced_note_handles() + def has_source_reference(self, src_handle) : """ Returns True if any of the child objects has reference diff --git a/src/RelLib/_SourceRef.py b/src/RelLib/_SourceRef.py index 26f66f2cc..5ebb44b96 100644 --- a/src/RelLib/_SourceRef.py +++ b/src/RelLib/_SourceRef.py @@ -116,13 +116,13 @@ class SourceRef(SecondaryObject, DateBase, PrivacyBase, NoteBase, RefBase): Returns the list of (classname,handle) tuples for all directly referenced primary objects. - @return: Returns the list of (classname,handle) tuples for referenced objects. + @return: List of (classname,handle) tuples for referenced objects. @rtype: list """ + ret = self.get_referenced_note_handles() if self.ref: - return [('Source', self.ref)] - else: - return [] + ret += [('Source', self.ref)] + return ret def set_confidence_level(self, val): """Sets the confidence level"""