Exemple #1
0
def get_person_filter(db_handle: DbReadBase,
                      args: Dict) -> Union[GenericFilter, None]:
    """Return the specified person filter."""
    if args["person"] is None:
        if args["gramps_id"] is not None or args["handle"] is not None:
            abort(422)
        return None

    if args["gramps_id"]:
        gramps_id = args["gramps_id"]
        if db_handle.get_person_from_gramps_id(gramps_id) is None:
            abort(422)
    else:
        try:
            person = db_handle.get_person_from_handle(args["handle"])
        except HandleError:
            abort(422)
        gramps_id = person.gramps_id

    person_filter = filters.GenericFilter()
    if args["person"] == "Descendants":
        person_filter.set_name(_("Descendants of %s") % gramps_id)
        person_filter.add_rule(
            filters.rules.person.IsDescendantOf([gramps_id, 1]))
    elif args["person"] == "DescendantFamilies":
        person_filter.set_name(_("Descendant Families of %s") % gramps_id)
        person_filter.add_rule(
            filters.rules.person.IsDescendantFamilyOf([gramps_id, 1]))
    elif args["person"] == "Ancestors":
        person_filter.set_name(_("Ancestors of %s") % gramps_id)
        person_filter.add_rule(
            filters.rules.person.IsAncestorOf([gramps_id, 1]))
    elif args["person"] == "CommonAncestor":
        person_filter.set_name(
            _("People with common ancestor with %s") % gramps_id)
        person_filter.add_rule(
            filters.rules.person.HasCommonAncestorWith([gramps_id]))
    else:
        person_filter = None
        filters.reload_custom_filters()
        for filter_class in filters.CustomFilters.get_filters("Person"):
            if args["person"] == filter_class.get_name():
                person_filter = filter_class
                break
    if person_filter is None:
        abort(422)
    return person_filter
Exemple #2
0
 def set_person_filter(self, name: str, gramps_id: str):
     """Add the specified person filter."""
     self.gramps_id = gramps_id
     self.pfilter = filters.GenericFilter()
     if name == "Descendants":
         self.pfilter.set_name(_("Descendants of %s") % gramps_id)
         self.pfilter.add_rule(
             filters.rules.person.IsDescendantOf([gramps_id, 1]))
     elif name == "DescendantFamilies":
         self.pfilter.set_name(_("Descendant Families of %s") % gramps_id)
         self.pfilter.add_rule(
             filters.rules.person.IsDescendantFamilyOf([gramps_id, 1]))
     elif name == "Ancestors":
         self.pfilter.set_name(_("Ancestors of %s") % gramps_id)
         self.pfilter.add_rule(
             filters.rules.person.IsAncestorOf([gramps_id, 1]))
     elif name == "CommonAncestor":
         self.pfilter.set_name(
             _("People with common ancestor with %s") % gramps_id)
         self.pfilter.add_rule(
             filters.rules.person.HasCommonAncestorWith([gramps_id]))
     else:
         self.pfilter = self.get_custom_filter(name, "Person")