Skip to content

Commit

Permalink
Show other roles for an event in the narrative web report
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Smeets authored and Nick-Hall committed Jan 7, 2025
1 parent 75c5053 commit 6f4c599
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 1 deletion.
26 changes: 26 additions & 0 deletions gramps/gen/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,32 @@ def get_source_and_citation_referents(source_handle, db):
return the_lists


def get_event_person_referents(event_handle, db):
"""
Find persons that refer to the event object.
This function finds all primary objects that refer
to the given event handle in a given database.
"""
_primaries = ("Person",)

lists = get_referents(event_handle, db, _primaries)
return [x for xs in lists for x in xs]


def get_event_family_referents(event_handle, db):
"""
Find families that refer to the event object.
This function finds all primary objects that refer
to the given event handle in a given database.
"""
_primaries = ("Family",)

lists = get_referents(event_handle, db, _primaries)
return [x for xs in lists for x in xs]


def get_media_referents(media_handle, db):
"""
Find objects that refer the media object.
Expand Down
149 changes: 148 additions & 1 deletion gramps/plugins/webreport/basepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@
from gramps.gen.display.name import displayer as _nd
from gramps.gen.display.place import displayer as _pd
from gramps.plugins.lib.libhtmlconst import _CC
from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback
from gramps.gen.utils.db import (
get_birth_or_fallback,
get_death_or_fallback,
get_event_person_referents,
get_event_family_referents,
)
from gramps.gen.datehandler import parser as _dp
from gramps.plugins.lib.libhtml import Html, xml_lang
from gramps.plugins.lib.libhtmlbackend import HtmlBackend, process_spaces
Expand Down Expand Up @@ -210,6 +215,7 @@ def __init__(self, report, the_lang, the_title, gid=None):
self.create_thumbs_index = report.options["create_thumbs_index"]
self.inc_families = report.options["inc_families"]
self.inc_events = report.options["inc_events"]
self.inc_other_roles = report.options["inc_other_roles"]
self.usecms = report.options["usecms"]
self.prevnext = report.options["prevnext"]
self.target_uri = report.options["cmsuri"]
Expand Down Expand Up @@ -841,6 +847,143 @@ def event_header_row(self):
trow += Html("/tr", close=None)
return trow

def display_event_other_person_role(
self, skip_event_ref, uplink, htmllist, refering_person
):
"""
Display the role of the refering person to this event.
Skip the role for the specified skip_event_ref because it is already
displayed with the primary role.
@param self This report page.
@param skip_event_ref This event_ref can be skipped. It is already displayed.
@param uplink If True, then "../../../" is inserted in front of the result.
@param htmllist The HTML list to which text has to be appended.
@param refering_person The person that has a role in the event.
"""
event_refs = refering_person.get_event_ref_list()
for event_ref in event_refs:
if (
event_ref.get_reference_handle()
!= skip_event_ref.get_reference_handle()
):
# Refering to an other event.
continue
elif event_ref.is_equal(skip_event_ref):
# This event_ref is already displayed.
continue
role = event_ref.get_role()
# Get the person name with a link to it.
person_name = self.new_person_link(
refering_person.get_handle(), uplink, refering_person
)
# Add the person name and role to the page.
htmllist.extend(
Html(
"p",
_("(%(str1)s) %(str2)s")
% {
"str1": Html("b", role),
"str2": person_name,
},
)
)

def display_event_other_person_roles(self, event, skip_event_ref, uplink, htmllist):
"""
Display all the other persons with their role to this event.
Skip the person with the specified skip_event_ref, because he is already
displayed with the primary role.
@param self This report page.
@param event The event that is concerned.
@param skip_event_ref This event_ref can be skipped. It is already displayed.
@param uplink If True, then "../../../" is inserted in front of the result.
@param htmllist The HTML list to which text has to be appended.
@return void
"""
refering_person_handles = get_event_person_referents(
event.get_handle(), self.r_db
)
for refering_person_handle in refering_person_handles:
refering_person = self.r_db.get_person_from_handle(refering_person_handle)
if not refering_person:
continue
self.display_event_other_person_role(
skip_event_ref, uplink, htmllist, refering_person
)

def display_event_other_family_role(
self, skip_event_ref, uplink, htmllist, refering_family
):
"""
Display the role of the refering family to this event.
Skip the role for the specified skip_event_ref because it is already
displayed with the primary role.
@param self This report page.
@param skip_event_ref This event_ref can be skipped. It is already displayed.
@param uplink If True, then "../../../" is inserted in front of the result.
@param htmllist The HTML list to which text has to be appended.
@param refering_family The family that has a role in the event.
"""
event_refs = refering_family.get_event_ref_list()
for event_ref in event_refs:
if (
event_ref.get_reference_handle()
!= skip_event_ref.get_reference_handle()
):
# Refering to an other event.
continue
elif event_ref.is_equal(skip_event_ref):
# This event_ref is already displayed.
continue
role = event_ref.get_role()
plain_family_name = self.report.get_family_name(refering_family)
family_name = self.family_link(
refering_family.get_handle(),
plain_family_name,
gid=refering_family.get_gramps_id(),
uplink=uplink,
)
# Add the family name and role to the page.
htmllist.extend(
Html(
"p",
_("(%(str1)s) %(str2)s")
% {
"str1": Html("b", role),
"str2": family_name,
},
)
)

def display_event_other_family_roles(self, event, skip_event_ref, uplink, htmllist):
"""
Display all the other families with their role to this event.
Skip the family with the specified skip_event_ref, because it is already
displayed with the primary role.
@param self This report page.
@param event The event that is concerned.
@param skip_event_ref This event_ref can be skipped. It is already displayed.
@param uplink If True, then "../../../" is inserted in front of the result.
@param htmllist The HTML list to which text has to be appended.
@return void
"""
refering_family_handles = get_event_family_referents(
event.get_handle(), self.r_db
)
for refering_family_handle in refering_family_handles:
refering_family = self.r_db.get_family_from_handle(refering_family_handle)
if not refering_family:
continue
self.display_event_other_family_role(
skip_event_ref, uplink, htmllist, refering_family
)

def display_event_row(
self, event, event_ref, place_lat_long, uplink, hyperlink, omit
):
Expand Down Expand Up @@ -934,6 +1077,10 @@ def display_event_row(
if notelist:
htmllist.extend(self.dump_notes(notelist, Event))

if self.inc_other_roles:
self.display_event_other_person_roles(event, event_ref, uplink, htmllist)
self.display_event_other_family_roles(event, event_ref, uplink, htmllist)

trow2 += Html("td", htmllist, class_="ColumnNotes", colspan=3)

trow += trow2
Expand Down
7 changes: 7 additions & 0 deletions gramps/plugins/webreport/narrativeweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def __init__(self, database, options, user):
# create an event pages or not?
self.inc_events = self.options["inc_events"]

# Include other roles to an event?
self.inc_other_roles = self.options["inc_other_roles"]

# create places pages or not?
self.inc_places = self.options["inc_places"]

Expand Down Expand Up @@ -2555,6 +2558,10 @@ def __add_advanced_options_2(self, menu):
inc_events.set_help(_("Add a complete events list and relevant pages or not"))
addopt("inc_events", inc_events)

inc_other_roles = BooleanOption(_("Include other roles"), False)
inc_other_roles.set_help(_("Include persons with other roles to an event"))
addopt("inc_other_roles", inc_other_roles)

inc_places = BooleanOption(_("Include place pages"), False)
inc_places.set_help(_("Whether or not to include the place pages."))
addopt("inc_places", inc_places)
Expand Down

0 comments on commit 6f4c599

Please sign in to comment.