From: Jérôme <rom...@ya...> - 2012-12-17 16:08:37
|
Tim, OK, but how do you read/migrate code like: Gramps 3.3.x: if death_ref: death = self.db.get_event_from_handle(death_ref.ref) source_list = death.get_source_references() for source_ref in source_list: #print "death handle:", source_ref source = self.db.get_source_from_handle(source_ref.ref) When I look at a possible patch, my first idea was to be close to previous design, something like: citation_list = death.get_citation_list() for cita in citation_list: print("death handle:", cita) citation = self.db.get_citation_from_handle(cita) if citation: src = citation.get_reference_handle() else: continue source = self.db.get_source_from_handle(src) Then to make the same type of changes for DB commit: if source: - sref = gen.lib.SourceRef() - sref.set_reference_handle(source.get_handle()) - event.add_source_reference(sref) + cit = gen.lib.Citation() + cit.set_reference_handle(source.handle) + event.add_citation(cit) + self.db.commit_citation(cit, self.trans) It is close to previous design, but partial! :( The second idea, is a rewrite. Now, it raises my limits... I thought it could be something more 'compact', by re-using existing code. eg, from gen.utils import db #trunk from Utils # gramps34 _.get_referents(handle, db, primary_objects): """ Find objects that refer to an object. This function is the base for other get_<object>_referents functions. """ ... or _.get_source_referents(source_handle, db): """ Find objects that refer the source. This function finds all primary objects that refer (directly or through secondary child-objects) to a given source handle in a given database. Only Citations can refer to sources, so that is all we need to check """ _primaries = ('Citation',) return (get_referents(source_handle, db, _primaries)) or _.get_citation_referents(citation_handle, db): """ Find objects that refer the citation. This function finds all primary objects that refer (directly or through secondary child-objects) to a given citation handle in a given database. """ _primaries = ('Person', 'Family', 'Event', 'Place', 'Source', 'MediaObject', 'Repository') return (get_referents(citation_handle, db, _primaries)) or _.get_source_and_citation_referents(source_handle, db): """ Find all citations that refer to the sources, and recursively, all objects that refer to the sources. This function finds all primary objects that refer (directly or through secondary child-objects) to a given source handle in a given database. Objects -> Citations -> Source e.g. Media object M1 -> Citation C1 -> Source S1 Media object M2 -> Citation C1 -> Source S1 Person object P1 -> Citation C2 -> Source S1 The returned structure is rather ugly, but provides all the information in a way that is consistent with the other Util functions. ( tuple of objects that refer to the source - only first element is present ([C1, C2],), list of citations with objects that refer to them [ (C1, tuple of reference lists P, F, E, Pl, S, M, R ([], [], [], [], [], [M1, M2]. []) ) (C2, tuple of reference lists P, F, E, Pl, S, M, R ([P1], [], [], [], [], []. []) ) ] ) """ the_lists = get_source_referents(source_handle, db) LOG.debug('source referents %s' % [the_lists]) # now, for each citation, get the objects that refer to that citation citation_referents_list = [] for citation in the_lists[0]: LOG.debug('citation %s' % citation) refs = get_citation_referents(citation, db) citation_referents_list += [(citation, refs)] LOG.debug('citation_referents_list %s' % [citation_referents_list]) (citation_list) = the_lists the_lists = (citation_list, citation_referents_list) LOG.debug('the_lists %s' % [the_lists]) return the_lists but now my problem is to understand these 'referents' behavior! Why .get_referents() does not use a list as _primaries (last arguments)? Where I am on the references maps??? I am willing to help with a patch or a fix for simple typo, but when we need to create a source object from an event reference, I suppose that we also need to create a citation (even empty). Dealing with db commit/tool design, I was quickly stopped, but I tried. http://www.gramps-project.org/bugs/view.php?id=6025 Jérôme Le 17/12/2012 16:27, Tim Lyons a écrit : > jerome wrote >> I could try to look at this, but I am limited on some advanced parts of >> citation object: I cannot always find the good way for migrating source >> reference (3.3) to citation(3.4) [1]! > > There is some general advice on citations as well as advice on converting > from source reference (3.3) to citation(3.4) here: > > http://www.gramps-project.org/wiki/index.php?title=GEPS_023:_Storing_data_from_large_sources#Changes_needed > > > > -- > View this message in context: http://gramps.1791082.n4.nabble.com/Re-please-help-with-this-code-tp4657646p4657656.html > Sent from the GRAMPS - Dev mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial > Remotely access PCs and mobile devices and provide instant support > Improve your efficiency, and focus on delivering more value-add services > Discover what IT Professionals Know. Rescue delivers > http://p.sf.net/sfu/logmein_12329d2d > _______________________________________________ > Gramps-devel mailing list > Gra...@li... > https://lists.sourceforge.net/lists/listinfo/gramps-devel > |