GEPS008: Create new module for referent functions
svn: r19814
This commit is contained in:
parent
bd6478327c
commit
d3fed5963f
@ -324,6 +324,7 @@ src/gen/simple/_simpleaccess.py
|
||||
src/gen/simple/_simpletable.py
|
||||
|
||||
# gen.utils
|
||||
src/gen/utils/alive.py
|
||||
src/gen/utils/place.py
|
||||
|
||||
# gui - GUI code
|
||||
|
@ -217,6 +217,7 @@ src/gen/simple/_simpledoc.py
|
||||
src/gen/utils/__init__.py
|
||||
src/gen/utils/callback.py
|
||||
src/gen/utils/callman.py
|
||||
src/gen/utils/referent.py
|
||||
|
||||
# gui - GUI code
|
||||
src/gui/__init__.py
|
||||
|
124
src/Utils.py
124
src/Utils.py
@ -490,130 +490,6 @@ def create_uid(self, handle=None):
|
||||
uid = uuid.uuid4()
|
||||
return uid.hex.upper()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Other util functions
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def get_referents(handle, db, primary_objects):
|
||||
""" Find objects that refer to an object.
|
||||
|
||||
This function is the base for other get_<object>_referents functions.
|
||||
|
||||
"""
|
||||
# Use one pass through the reference map to grab all the references
|
||||
object_list = list(db.find_backlink_handles(handle))
|
||||
|
||||
# Then form the object-specific lists
|
||||
the_lists = ()
|
||||
|
||||
for primary in primary_objects:
|
||||
primary_list = [item[1] for item in object_list if item[0] == primary]
|
||||
the_lists = the_lists + (primary_list, )
|
||||
|
||||
return the_lists
|
||||
|
||||
def 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))
|
||||
|
||||
def 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))
|
||||
|
||||
def 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], [], [], [], [], []. [])
|
||||
)
|
||||
]
|
||||
)
|
||||
#47738: DEBUG: citationtreeview.py: line 428: source referents [(['bfe59e90dbb555d0d87'],)]
|
||||
#47743: DEBUG: citationtreeview.py: line 432: citation bfe59e90dbb555d0d87
|
||||
#47825: DEBUG: citationtreeview.py: line 435: citation_referents_list [[('bfe59e90dbb555d0d87', ([], [], ['ba77932bf0b2d59eccb'], [], [], [], []))]]
|
||||
#47827: DEBUG: citationtreeview.py: line 440: the_lists [((['bfe59e90dbb555d0d87'],), [('bfe59e90dbb555d0d87', ([], [], ['ba77932bf0b2d59eccb'], [], [], [], []))])]
|
||||
|
||||
"""
|
||||
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
|
||||
|
||||
def get_media_referents(media_handle, db):
|
||||
""" Find objects that refer the media object.
|
||||
|
||||
This function finds all primary objects that refer
|
||||
to a given media handle in a given database.
|
||||
|
||||
"""
|
||||
_primaries = ('Person', 'Family', 'Event', 'Place', 'Source', 'Citation')
|
||||
|
||||
return (get_referents(media_handle, db, _primaries))
|
||||
|
||||
def get_note_referents(note_handle, db):
|
||||
""" Find objects that refer a note object.
|
||||
|
||||
This function finds all primary objects that refer
|
||||
to a given note handle in a given database.
|
||||
|
||||
"""
|
||||
_primaries = ('Person', 'Family', 'Event', 'Place',
|
||||
'Source', 'Citation', 'MediaObject', 'Repository')
|
||||
|
||||
return (get_referents(note_handle, db, _primaries))
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -35,7 +35,7 @@ LOG = logging.getLogger(".citationfilter")
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from Utils import get_source_and_citation_referents
|
||||
from gen.utils.referent import get_source_and_citation_referents
|
||||
from gen.filters.rules import Rule
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
@ -13,7 +13,8 @@ pkgpython_PYTHON = \
|
||||
callman.py \
|
||||
configmanager.py \
|
||||
fallback.py \
|
||||
place.py
|
||||
place.py \
|
||||
referent.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/gen/utils
|
||||
|
||||
|
@ -52,7 +52,7 @@ import gtk
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from Utils import get_source_referents
|
||||
from gen.utils.referent import get_source_referents
|
||||
from gui.views.treemodels.treebasemodel import TreeBaseModel
|
||||
from gui.views.treemodels.citationbasemodel import CitationBaseModel
|
||||
|
||||
|
@ -49,7 +49,7 @@ from gui.views.treemodels.citationlistmodel import CitationListModel
|
||||
from gen.plug import CATEGORY_QR_CITATION
|
||||
import gen.lib
|
||||
from gui.views.listview import ListView
|
||||
import Utils
|
||||
from gen.utils.referent import get_citation_referents
|
||||
from gui.views.bookmarks import CitationBookmarks
|
||||
from gen.errors import WindowActiveError
|
||||
from gui.ddtargets import DdTargets
|
||||
@ -284,7 +284,7 @@ class CitationListView(ListView):
|
||||
self.remove_selected_objects()
|
||||
|
||||
def remove_object_from_handle(self, handle):
|
||||
the_lists = Utils.get_citation_referents(handle, self.dbstate.db)
|
||||
the_lists = get_citation_referents(handle, self.dbstate.db)
|
||||
object = self.dbstate.db.get_citation_from_handle(handle)
|
||||
query = DeleteCitationQuery(self.dbstate, self.uistate, object,
|
||||
the_lists)
|
||||
|
@ -50,7 +50,8 @@ from gui.views.treemodels.citationtreemodel import CitationTreeModel
|
||||
from gen.plug import CATEGORY_QR_SOURCE_OR_CITATION
|
||||
import gen.lib
|
||||
from gui.views.listview import ListView
|
||||
import Utils
|
||||
from gen.utils.referent import (get_source_and_citation_referents,
|
||||
get_citation_referents)
|
||||
from gui.views.bookmarks import CitationBookmarks
|
||||
from gen.errors import WindowActiveError
|
||||
from gui.ddtargets import DdTargets
|
||||
@ -458,14 +459,14 @@ class CitationTreeView(ListView):
|
||||
if (not source and not citation) or (source and citation):
|
||||
raise ValueError("selection must be either source or citation")
|
||||
if citation:
|
||||
the_lists = Utils.get_citation_referents(handle, self.dbstate.db)
|
||||
the_lists = get_citation_referents(handle, self.dbstate.db)
|
||||
object = self.dbstate.db.get_citation_from_handle(handle)
|
||||
query = DeleteCitationQuery(self.dbstate, self.uistate, object,
|
||||
the_lists)
|
||||
is_used = any(the_lists)
|
||||
return (query, is_used, object)
|
||||
else:
|
||||
the_lists = Utils.get_source_and_citation_referents(handle,
|
||||
the_lists = get_source_and_citation_referents(handle,
|
||||
self.dbstate.db)
|
||||
LOG.debug('the_lists %s' % [the_lists])
|
||||
|
||||
|
@ -56,6 +56,7 @@ import const
|
||||
from gen.constfunc import win
|
||||
from gen.config import config
|
||||
import Utils
|
||||
from gen.utils.referent import get_media_referents
|
||||
from gui.views.bookmarks import MediaBookmarks
|
||||
import gen.mime
|
||||
import gen.lib
|
||||
@ -356,7 +357,7 @@ class MediaView(ListView):
|
||||
Remove the selected objects from the database after getting
|
||||
user verification.
|
||||
"""
|
||||
the_lists = Utils.get_media_referents(handle, self.dbstate.db)
|
||||
the_lists = get_media_referents(handle, self.dbstate.db)
|
||||
object = self.dbstate.db.get_object_from_handle(handle)
|
||||
query = DeleteMediaQuery(self.dbstate, self.uistate, handle, the_lists)
|
||||
is_used = any(the_lists)
|
||||
|
@ -47,7 +47,7 @@ import gtk
|
||||
#-------------------------------------------------------------------------
|
||||
from gui.views.listview import ListView
|
||||
from gui.views.treemodels import NoteModel
|
||||
import Utils
|
||||
from gen.utils.referent import get_note_referents
|
||||
from gen.errors import WindowActiveError
|
||||
from gui.views.bookmarks import NoteBookmarks
|
||||
from gen.config import config
|
||||
@ -246,7 +246,7 @@ class NoteView(ListView):
|
||||
self.remove_selected_objects()
|
||||
|
||||
def remove_object_from_handle(self, handle):
|
||||
the_lists = Utils.get_note_referents(handle, self.dbstate.db)
|
||||
the_lists = get_note_referents(handle, self.dbstate.db)
|
||||
object = self.dbstate.db.get_note_from_handle(handle)
|
||||
query = DeleteNoteQuery(self.dbstate, self.uistate, object, the_lists)
|
||||
is_used = any(the_lists)
|
||||
|
@ -43,7 +43,7 @@ import gen.lib
|
||||
from gen.config import config
|
||||
from gui.views.listview import ListView
|
||||
from gui.views.treemodels import SourceModel
|
||||
import Utils
|
||||
from gen.utils.referent import get_source_and_citation_referents
|
||||
from gui.views.bookmarks import SourceBookmarks
|
||||
from gen.errors import WindowActiveError
|
||||
from gui.ddtargets import DdTargets
|
||||
@ -214,8 +214,7 @@ class SourceView(ListView):
|
||||
self.remove_selected_objects()
|
||||
|
||||
def remove_object_from_handle(self, handle):
|
||||
the_lists = Utils.get_source_and_citation_referents(handle,
|
||||
self.dbstate.db)
|
||||
the_lists = get_source_and_citation_referents(handle, self.dbstate.db)
|
||||
LOG.debug('the_lists %s' % [the_lists])
|
||||
|
||||
object = self.dbstate.db.get_source_from_handle(handle)
|
||||
|
@ -89,6 +89,7 @@ from gen.plug.report import utils as ReportUtils
|
||||
from gen.plug.report import MenuReportOptions
|
||||
|
||||
import Utils
|
||||
from gen.utils.referent import get_source_and_citation_referents
|
||||
from gen.constfunc import win
|
||||
from gui.thumbnails import get_thumbnail_path, run_thumbnailer
|
||||
import ImgManip
|
||||
@ -4514,7 +4515,7 @@ class SourcePage(BasePage):
|
||||
sourcedetail += repo_list
|
||||
|
||||
# get the Source and its Citation Referents...
|
||||
the_lists = Utils.get_source_and_citation_referents(src_handle, self.dbase_)
|
||||
the_lists = get_source_and_citation_referents(src_handle, self.dbase_)
|
||||
if the_lists:
|
||||
(citation_list, citation_referents_list) = the_lists
|
||||
if citation_referents_list:
|
||||
|
Loading…
Reference in New Issue
Block a user