Skip to content

Conversation

@stevenyoungs
Copy link
Contributor

Add a rule that matches objects with a note with a specified tag.

@dsblank dsblank added this to the v6.1 milestone Jun 7, 2025
@dsblank dsblank requested a review from Copilot August 4, 2025 15:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements HasNoteTag filter rules that allow matching objects (people, families, events, places, sources, citations, media, and repositories) based on whether they have notes with a specified tag. The implementation follows a consistent pattern across all object types by inheriting from a common base class.

  • Adds HasNoteTagBase class with core logic for checking if objects have notes with specified tags
  • Creates HasNoteTag filter rule classes for all major object types in Gramps
  • Registers the new filter rules in the appropriate module exports

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

File Description
gramps/gen/filters/rules/_hasnotetagbase.py Base class implementing the core logic for note tag filtering
gramps/gen/filters/rules/*/hasnotetag.py Entity-specific implementations inheriting from HasNoteTagBase
gramps/gen/filters/rules/*/init.py Registration of HasNoteTag classes in module exports

# -------------------------------------------------------------------------
class HasNoteTagBase(Rule):
"""
Objects having a note with a particular tag..
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring has an extra period at the end. It should be 'Objects having a note with a particular tag.'

Suggested change
Objects having a note with a particular tag..
Objects having a note with a particular tag.

Copilot uses AI. Check for mistakes.

labels = [_("Tag:")]
name = _("Objects with notes with a specified tag.")
description = _("Matches notes with a specified tag ")
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description has a trailing space that should be removed. It should be 'Matches notes with a specified tag'

Suggested change
description = _("Matches notes with a specified tag ")
description = _("Matches notes with a specified tag")

Copilot uses AI. Check for mistakes.

def __init__(self, arg, use_regex=False, use_case=False):
super().__init__(arg, use_regex, use_case)
self.tag = None
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'self.tag' attribute is initialized but never used in the class. Consider removing it or implementing its intended functionality.

Suggested change
self.tag = None

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be self.tag_handle = None ?

notelist = obj.note_list
for notehandle in notelist:
note = db.get_note_from_handle(notehandle)
if self.tag_handle in note.tag_list:
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code assumes 'note.tag_list' exists but doesn't handle the case where 'note' could be None. Add a null check: 'if note and self.tag_handle in note.tag_list:'

Suggested change
if self.tag_handle in note.tag_list:
if note and self.tag_handle in note.tag_list:

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this better still:

if note is not None and self.tag_handle is not None and self.tag_handle in note.tag_list:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants