コード例 #1
0
    def test_catalogtool_search_users_by_preferences(self):
        from eea.notifications.catalogtool import get_catalog

        events = ['modified_custom', 'deleted_custom']
        events_no = ['event 1', 'event 2']

        catalog = get_catalog()
        catalog.set_events(user_id=TEST_USER_ID, events=events)

        tags = ['subject 1', 'subject 2']
        tags_no = ['other 1', 'other 2']

        catalog.set_tags(user_id=TEST_USER_ID, tags=tags)

        users = catalog.search_users_by_preferences(
                events=events, tags=tags, mode="or")

        self.assertTrue(TEST_USER_ID in users)
        if TEST_USER_ID in users:
            log("catalogtool", "User found by preferences as expected.")
        else:
            log("catalogtool", "User not found by preferences.", "error")

        users = catalog.search_users_by_preferences(
                events=events_no, tags=tags_no, mode="or")

        self.assertTrue(TEST_USER_ID not in users)
        if TEST_USER_ID not in users:
            log("catalogtool", "Search results seems ok.")
        else:
            log("catalogtool", "Wrong search results.", "error")
コード例 #2
0
ファイル: vocabulary.py プロジェクト: eea/eea.notifications
def get_tags_vocab(context):
    global _VOCAB  # just a quick dirty cache
    catalog = get_catalog()
    res = [x[0] for x in catalog.all_tags()]

    if _VOCAB:
        return _VOCAB
    else:
        _VOCAB = vocab_from_values(res)

    return _VOCAB
コード例 #3
0
    def test_catalogtool_tags_in_user_preferences(self):
        from eea.notifications.catalogtool import get_catalog

        # Try with a single tag
        tag = "a subject I like"
        tag_no = "not important"

        catalog = get_catalog()
        catalog.set_tags(user_id=TEST_USER_ID, tags=[tag])
        selected = catalog.selected_tags(user_id=TEST_USER_ID)
        if (tag in selected) and (tag_no not in selected):
            log("catalogtool",
                "Set tags and get user selected ones is working.")
        else:
            log("catalogtool",
                "Set tags and get user selected ones is not working.",
                "error")

        self.assertTrue(tag in selected)
        self.assertTrue(tag_no not in selected)

        # Try with multiple tags
        tags = ['subject 1', 'subject 2']
        tags_no = ['other 1', 'other 2']

        catalog.set_tags(user_id=TEST_USER_ID, tags=tags)
        selected = catalog.selected_tags(user_id=TEST_USER_ID)
        ok = True
        for tag in tags:
            if tag not in selected:
                ok = False

            self.assertTrue(tag in selected)

        if ok:
            log("catalogtool",
                "Set multiple tags and get user selected ones is working.")
        else:
            log("catalogtool",
                "Set multiple tags and get user selected ones not working.",
                "error")

        ok = True
        for tag_no in tags_no:
            if tag_no in selected:
                ok = False

            self.assertTrue(tag_no not in selected)

        if ok:
            log("catalogtool", "Only set tags are present.")
        else:
            log("catalogtool", "Wrong behaviour setting tags.", "error")
コード例 #4
0
    def test_catalogtool_events_in_user_preferences(self):
        from eea.notifications.catalogtool import get_catalog

        # Try with a single event
        event = "something happened with this content"
        event_no = "something else happened"

        catalog = get_catalog()
        catalog.set_events(user_id=TEST_USER_ID, events=[event])
        selected = catalog.selected_events(user_id=TEST_USER_ID)
        if (event in selected) and (event_no not in selected):
            log("catalogtool",
                "Set events and get user selected ones is working.")
        else:
            log("catalogtool",
                "Set events and get user selected ones is not working.",
                "error")

        self.assertTrue(event in selected)
        self.assertTrue(event_no not in selected)

        # Try with multiple events
        events = ['edited_custom', 'deleted_custom']
        events_no = ['other_edited_custom', 'other_deleted_custom']

        catalog.set_events(user_id=TEST_USER_ID, events=events)
        selected = catalog.selected_events(user_id=TEST_USER_ID)
        ok = True
        for event in events:
            if event not in selected:
                ok = False

            self.assertTrue(event in selected)

        if ok:
            log("catalogtool",
                "Set multiple events and get user selected ones is working.")
        else:
            log("catalogtool",
                "Set multiple events and get user selected ones not working.",
                "error")

        ok = True
        for event_no in events_no:
            if event_no in selected:
                ok = False

            self.assertTrue(event_no not in selected)

        if ok:
            log("catalogtool", "Only set events are present.")
        else:
            log("catalogtool", "Wrong behaviour setting events.", "error")
コード例 #5
0
    def test_catalogtool(self):
        from eea.notifications.catalogtool import get_catalog
        try:
            catalog = get_catalog()
            catalog = catalog  # happy PEP
            exists = True
        except Exception:
            exists = False

        if exists:
            log("catalogtool", "Custom catalog exists.")
            self.assertTrue(exists)
        else:
            log("catalogtool", "Custom catalog is missing.", "error")
            self.assertTrue(exists)
コード例 #6
0
    def operations(message, site):
        def get_object(site, path):
            """ Return the object at given path
                or its first existing parent
            """
            obj = get_object_having_path(path)
            if obj is None:
                try:
                    path = "/".join(path.split("/")[:-1])
                    return get_object(site, path)
                except Exception:
                    return None
            else:
                if obj == site:
                    return None
                return obj
            return None

        msg = json.loads(message)
        """ This object is the object related to notification we want to send.
            Sometimes it is missing (example: on deleted items) so a parent
            will be used for that case.

            But the content_url is not changed, basically we just make sure
            the notification is sent.
        """
        obj = get_object(site, msg['path'])

        if obj is not None:
            catalog = get_catalog()
            users = catalog.search_users_by_preferences(
                tags=msg['tags'], events=[msg.get('events', '')], mode="or")
            for user_id in users:
                msg['user_id'] = user_id
                evt = SendEEANotificationEvent(obj, json.dumps(msg))
                notify(evt)
                close(evt)  # make sure it will work for multiple notify(
        else:
            LOGGER.error("Object with path {0} not found.".format(msg['path']))

        return True
コード例 #7
0
ファイル: evolve11.py プロジェクト: eea/eea.notifications
def run(context):
    """ Configure catalog
    """
    catalog = get_catalog()
    if catalog is not None:
        try:
            index = catalog._catalog.getIndex('getTags')
            index = index  # The Happy PEP
        except KeyError:

            class Empty(object):
                """ Empty """
                pass

            elem = []

            word_splitter = Empty()
            word_splitter.group = 'Word Splitter'
            word_splitter.name = 'HTML aware splitter'

            case_normalizer = Empty()
            case_normalizer.group = 'Case Normalizer'
            case_normalizer.name = 'Case Normalizer'

            stop_words = Empty()
            stop_words.group = 'Stop Words'
            stop_words.name = 'Remove listed and single char words'

            elem.append(word_splitter)
            elem.append(case_normalizer)
            elem.append(stop_words)

            catalog.manage_addProduct['ZCTextIndex'].manage_addLexicon(
                'plone_lexicon', 'Default Lexicon', elem)

            catalog.addIndex('getTags', 'KeywordIndex')
            catalog.addColumn('getTags')
            catalog.reindexIndex(('getTags'), REQUEST=None)
            LOGGER.info("Added 'getTags' to eea_notifications_catalog.")

            catalog.addIndex('getUserTags', 'KeywordIndex')
            catalog.addColumn('getUserTags')
            catalog.reindexIndex(('getUserTags'), REQUEST=None)
            LOGGER.info("Added 'getUserTags' to eea_notifications_catalog.")

            atct = api.portal.get_tool(name="portal_atct")
            atct.updateIndex('getTags',
                             friendlyName='getTags',
                             description='getTags',
                             enabled=True,
                             criteria='ATSimpleIntCriterion')
            atct.updateMetadata('getTags',
                                friendlyName='getTags',
                                description='getTags',
                                enabled=True)

            atct.updateIndex('getUserTags',
                             friendlyName='getUserTags',
                             description='getUserTags',
                             enabled=True,
                             criteria='ATSimpleIntCriterion')
            atct.updateMetadata('getUserTags',
                                friendlyName='getUserTags',
                                description='getUserTags',
                                enabled=True)

            at = api.portal.get_tool(name=ARCHETYPETOOLNAME)
            at.setCatalogsByType('MetaType', [
                'portal_catalog',
                'eea_notifications_catalog',
            ])

            catalog.catalog_rebuild()
コード例 #8
0
def remove_from_catalog(obj, evt):
    """ Remove object from EEA Notifications Catalog
    """
    get_catalog().uncatalog_object(obj.absolute_url_path())
コード例 #9
0
def add_or_update_in_catalog(obj, evt):
    """ Reindex object in EEA Notifications Catalog
    """
    get_catalog().catalog_object(obj, idxs=('getTags', ), update_metadata=1)
コード例 #10
0
 def notifications_catalog(self):
     return get_catalog()
コード例 #11
0
def default_events(context):
    return [
        x for x in get_catalog().selected_events(
            user_id=api.user.get_current().id)
    ]
コード例 #12
0
ファイル: vocabulary.py プロジェクト: eea/eea.notifications
def get_events_vocab(context):
    catalog = get_catalog()
    res = [x[0] for x in catalog.all_events()]
    vocab = vocab_from_values(res)

    return vocab