Taapeli / isotammi-addons

Gramps addons for Isotammi project / Isotammen Gramps-lisäosia
8 stars 2 forks source link

Places in citation.citators #1

Closed patlx closed 2 years ago

patlx commented 3 years ago

Hi,

I've citations associated to places but the following little code doesn't work. It works well for Person and Event (I've not tried with Family) but It don't work for citations attached to places (this is what I'm looking for !):

[Gramps SuperTool script file]
version=1

[title]
SuperTool-Sources - Places with Source citations

[category]
Sources

[initial_statements]
print('----------------------------------------')

[statements]
for citation in citations:
    print(citation.page, ":\n", 
        '---->', [referent for referent in citation.citators if "Place" in str(referent)])

[filter]

[expressions]

[scope]
selected

[unwind_lists]
False

[commit_changes]
False

[summary_only]
False

image

Patrice

kkujansuu commented 3 years ago

Yes, "citators" is a weak spot in SuperToool :-) In the next version there will be a generic function "referrers" that would help in this - then the call citation.referrers('Place') would return a list of Place objects referring to the citation.

Now you can use this workaround: define a helper function "place_citators" as shown below and use it instead:

[initial_statements]
from supertool_engine import PlaceProxy

def place_citators(handle):
        for _, rhandle in db.find_backlink_handles(
            handle, include_classes=["Place"]
        ):
            yield PlaceProxy(db, rhandle)

[statements]
for citation in citations:
    print(citation.page, ":\n", 
        '---->', [referent for referent in place_citators(citation.handle) if "Place" in str(referent)])

Hope this helps.