예제 #1
0
    def get_filter(self):
        gid = str(self.filter_id.get_text()).strip()
        name = str(self.filter_name.get_text()).strip()
        ptype = self.filter_place.get_type().xml_str()
        code = str(self.filter_code.get_text()).strip()
        enclosed = str(self.filter_enclosed.get_text()).strip()
        note = str(self.filter_note.get_text()).strip()
        within = self.filter_within.get_value()
        regex = self.filter_regex.get_active()
        tag = self.tag.get_active() > 0
        gen = self.generic.get_active() > 0

        empty = not (gid or name or ptype or code or enclosed or note or regex
                     or within or tag or gen)
        if empty:
            generic_filter = None
        else:
            generic_filter = GenericPlaceFilter()
            if gid:
                rule = RegExpIdOf([gid], use_regex=regex)
                generic_filter.add_rule(rule)

            if enclosed:
                rule = IsEnclosedBy([enclosed, '0'])
                generic_filter.add_rule(rule)

            rule = HasData([name, ptype, code], use_regex=regex)
            generic_filter.add_rule(rule)

            if note:
                rule = HasNoteRegexp([note], use_regex=regex)
                generic_filter.add_rule(rule)

            if within and within[0] > 0 and self.dbstate.is_open():
                rule = WithinArea([None, within[0], within[1]])
                active_ref = self.uistate.get_active('Place')
                if active_ref:
                    place = self.dbstate.db.get_place_from_handle(active_ref)
                    gid = place.get_gramps_id()
                    rule = WithinArea([gid, within[0], within[1]])
                generic_filter.add_rule(rule)

            # check the Tag
            if tag:
                model = self.tag.get_model()
                node = self.tag.get_active_iter()
                attr = model.get_value(node, 0)
                rule = HasTag([attr])
                generic_filter.add_rule(rule)

            if self.generic.get_active() != 0:
                model = self.generic.get_model()
                node = self.generic.get_active_iter()
                obj = str(model.get_value(node, 0))
                rule = MatchesFilter([obj])
                generic_filter.add_rule(rule)

        return generic_filter
예제 #2
0
 def test_isenclosedby(self):
     """
     Test IsEnclosedBy rule.
     """
     rule = IsEnclosedBy(['P0001', '0'])
     self.assertEqual(
         self.filter_with_rule(rule),
         set([
             b'EAFKQCR0ED5QWL87EO', b'S22LQCLUZM135LVKRL',
             b'VDUJQCFP24ZV3O4ID2', b'V6ALQCZZFN996CO4D',
             b'OC6LQCXMKP6NUVYQD8', b'CUUKQC6BY5LAZXLXC6',
             b'PTFKQCKPHO2VC5SYKS', b'PHUJQCJ9R4XQO5Y0WS'
         ]))
예제 #3
0
    def get_filter(self):
        gid = str(self.filter_id.get_text()).strip()
        name = str(self.filter_name.get_text()).strip()
        ptype = self.filter_place.get_type().xml_str()
        code = str(self.filter_code.get_text()).strip()
        enclosed = str(self.filter_enclosed.get_text()).strip()
        note = str(self.filter_note.get_text()).strip()
        regex = self.filter_regex.get_active()
        tag = self.tag.get_active() > 0
        gen = self.generic.get_active() > 0

        empty = not (gid or name or ptype or code or enclosed or note or regex
                     or tag or gen)
        if empty:
            generic_filter = None
        else:
            generic_filter = GenericPlaceFilter()
            if gid:
                rule = RegExpIdOf([gid], use_regex=regex)
                generic_filter.add_rule(rule)

            if enclosed:
                rule = IsEnclosedBy([enclosed, '0'])
                generic_filter.add_rule(rule)

            rule = HasData([name, ptype, code], use_regex=regex)
            generic_filter.add_rule(rule)

            if note:
                rule = HasNoteRegexp([note], use_regex=regex)
                generic_filter.add_rule(rule)

            # check the Tag
            if tag:
                model = self.tag.get_model()
                node = self.tag.get_active_iter()
                attr = model.get_value(node, 0)
                rule = HasTag([attr])
                generic_filter.add_rule(rule)

            if self.generic.get_active() != 0:
                model = self.generic.get_model()
                node = self.generic.get_active_iter()
                obj = str(model.get_value(node, 0))
                rule = MatchesFilter([obj])
                generic_filter.add_rule(rule)

        return generic_filter