Addon Filter Rule requests

In the following request, a user wanted a rule to find Events with a precise date.

I ended up creating 3 rules:

  • find Events with precise date
  • find Events with approximated dates
  • find Events with no/blank/null dates

Before SuperTool:

sharing a new rule required creating an addon. A new addon meant figuring out how to code a “Rule” addon and its plugin registration file. When I experimented with that to build 3 Event date rules, that meant about 20 lines of code and 16 lines of registration per additional Rule. Then, it had to be submitted for approval in the Addon Manager distribution system.

Experimenting with SuperTool:

But each of my experimental filters only takes 3 lines in SuperTool. And one of those is multiline comment.

The hardest part was finding the feature that checks the Date object in the Gramps developer documentation in Sphinx. In this case, I was looking for functions related to the date object. The 2 functions that were relevant were is_regular() and is_empty()

“Menu → Save as a filter” in SuperTool makes a Custom Filter based on ‘generic rule’:

3 working fields also means just 3 fields using the SuperTool rule addon: Generic Rule.

Here’s the ‘generic rule’. In “Statements”, it sets a variable to be the Date object from the Event. Then in “Rule”, it checks if that Date object variable contains a ‘regular’ date. (A ‘regular’ date is a single exact date, i.e. not text-only, not a range or a span, not estimated/calculated, not a special calendar, not dual-dated, no special new year day, not about/before/after date. And by exact, it has a non-zero year, month, AND day.)

As a custom filter using the SuperTool Generic addon rule:

Here’s a custom_filters.xml (from the Gramps User Directory) that contains all 3 “Event” category filter rules:

<?xml version="1.0" encoding="utf-8"?>
<filters>
  <object type="Event">
    <filter name="SuperTool_RegularDates" function="and">
      <rule class="GenericFilterRule_Event" use_regex="False">
        <arg value="dateobject.is_regular()"/>
        <arg value="#  Return &quot;True&quot; if the date is a regular date.&lt;br&gt;#  The regular date is a single exact date, i.e. not text-only, not a range or a span, &lt;br&gt;#    not estimated/calculated, not about/before/after date, and having  a year, &lt;br&gt;#    month, and day all non-zero.&lt;br&gt;# see   https://gramps-project.org/docs/gen/gen_lib.html#gramps.gen.lib.date.Date.is_regular"/>
        <arg value="dateobject=self.event.get_date_object()"/>
      </rule>
    </filter>
    <filter name="SuperTool_IrregularDates" function="and">
      <rule class="GenericFilterRule_Event" use_regex="False">
        <arg value="not (event.get_date_object().is_regular() or event.get_date_object().is_empty())"/>
        <arg value="# Return True if matches events having a irregular date but not a blank date)<br># see https://gramps-project.org/docs/gen/gen_lib.html#gramps.gen.lib.date.Date.is_regular"/>
        <arg value="dateobject=self.event.get_date_object()"/>
      </rule>
    </filter>
    <filter name="SuperTool_Blank_Dates" function="and">
      <rule class="GenericFilterRule_Event" use_regex="False">
        <arg value="event.get_date_object().is_empty()"/>
        <arg value="#  Return &quot;True&quot; if the date is a blank date."/>
        <arg value="dateobject=self.event.get_date_object()"/>
      </rule>
    </filter>
  </object>
</filters>
1 Like