Exemplo n.º 1
0
    def test_tabs_mapping(self):
        """
        {
            'all': {'title': u'All'},
            'documents': {'portal_types': ('Document',), 'title': 'Documents'},
            'events': {'portal_types': ('Event',), 'title': 'Events'},
            'file': {'portal_types': ('File',), 'title': 'File'},
            'links': {'portal_types': ('Link',), 'title': 'Links'},
            'news': {'portal_types': ('News Item',), 'title': 'News'},
        }
        """

        tabs_mapping = self.view.tabs_mapping
        self.assertEquals(len(tabs_mapping.keys()), 6)
        self.assertTrue('documents' in tabs_mapping)
        self.assertTrue('news' in tabs_mapping)
        self.assertTrue('links' in tabs_mapping)
        self.assertTrue('file' in tabs_mapping)
        self.assertTrue('events' in tabs_mapping)
        self.assertEquals(tabs_mapping['documents']['portal_types'],
                          ('Document', ))
        self.assertEquals(tabs_mapping['news']['portal_types'],
                          ('News Item', ))
        self.assertEquals(tabs_mapping['events']['portal_types'], ('Event', ))

        # change settings
        old_settings = api.portal.get_registry_record(
            'tabs_mapping', interface=IRERSiteSearchSettings)
        new_settings = []
        for record in old_settings:
            if record.tab_title in ['News', 'Events']:
                continue
            if record.tab_title == 'Documents':
                new_record = TabsValueField()
                new_record.tab_title = record.tab_title
                new_record.portal_types = ('Document', 'Event', 'News Item')
                new_settings.append(new_record)
            else:
                new_settings.append(record)
        api.portal.set_registry_record(
            'tabs_mapping',
            tuple(new_settings),
            interface=IRERSiteSearchSettings,
        )

        tabs_mapping = self.view.tabs_mapping
        self.assertTrue('documents' in tabs_mapping)
        self.assertFalse('news' in tabs_mapping)
        self.assertTrue('links' in tabs_mapping)
        self.assertTrue('file' in tabs_mapping)
        self.assertFalse('events' in tabs_mapping)
        self.assertEquals(
            tabs_mapping['documents']['portal_types'],
            ('Document', 'Event', 'News Item'),
        )

        # go back to default
        api.portal.set_registry_record('tabs_mapping',
                                       old_settings,
                                       interface=IRERSiteSearchSettings)
Exemplo n.º 2
0
    def test_types_mapping(self):
        """
        {
            'Link': 'links',
            'Document': 'documents',
            'News Item': 'news',
            'Event': 'events',
            'File': 'file',
        }
        """

        types_mapping = self.view.types_mapping

        self.assertEquals(len(types_mapping.keys()), 5)
        self.assertEquals(types_mapping['Link'], 'links')
        self.assertEquals(types_mapping['Document'], 'documents')
        self.assertEquals(types_mapping['News Item'], 'news')
        self.assertEquals(types_mapping['Event'], 'events')
        self.assertEquals(types_mapping['File'], 'file')

        # change settings
        old_settings = api.portal.get_registry_record(
            'tabs_mapping', interface=IRERSiteSearchSettings
        )

        new_settings = []
        for record in old_settings:
            if record.tab_title in ['News', 'Events']:
                continue
            if record.tab_title == 'Documents':
                new_record = TabsValueField()
                new_record.tab_title = record.tab_title
                new_record.portal_types = ('Document', 'Event', 'News Item')
                new_settings.append(new_record)
            else:
                new_settings.append(record)
        api.portal.set_registry_record(
            'tabs_mapping',
            tuple(new_settings),
            interface=IRERSiteSearchSettings,
        )

        types_mapping = self.view.types_mapping

        self.assertEquals(len(types_mapping.keys()), 5)
        self.assertEquals(types_mapping['Link'], 'links')
        self.assertEquals(types_mapping['Document'], 'documents')
        self.assertEquals(types_mapping['News Item'], 'documents')
        self.assertEquals(types_mapping['Event'], 'documents')
        self.assertEquals(types_mapping['File'], 'file')

        # go back to default
        api.portal.set_registry_record(
            'tabs_mapping', old_settings, interface=IRERSiteSearchSettings
        )
Exemplo n.º 3
0
    def test_types_mapping(self):
        """
        {
            'Link': 'links',
            'Document': 'documents',
            'News Item': 'news',
            'Event': 'events',
            'File': 'file',
        }
        """

        types_mapping = self.view.types_mapping

        self.assertEquals(len(types_mapping.keys()), 5)
        self.assertEquals(types_mapping['Link'], 'links')
        self.assertEquals(types_mapping['Document'], 'documents')
        self.assertEquals(types_mapping['News Item'], 'news')
        self.assertEquals(types_mapping['Event'], 'events')
        self.assertEquals(types_mapping['File'], 'file')

        # change settings
        old_settings = api.portal.get_registry_record(
            'tabs_mapping', interface=IRERSiteSearchSettings)

        new_settings = []
        for record in old_settings:
            if record.tab_title in ['News', 'Events']:
                continue
            if record.tab_title == 'Documents':
                new_record = TabsValueField()
                new_record.tab_title = record.tab_title
                new_record.portal_types = ('Document', 'Event', 'News Item')
                new_settings.append(new_record)
            else:
                new_settings.append(record)
        api.portal.set_registry_record(
            'tabs_mapping',
            tuple(new_settings),
            interface=IRERSiteSearchSettings,
        )

        types_mapping = self.view.types_mapping

        self.assertEquals(len(types_mapping.keys()), 5)
        self.assertEquals(types_mapping['Link'], 'links')
        self.assertEquals(types_mapping['Document'], 'documents')
        self.assertEquals(types_mapping['News Item'], 'documents')
        self.assertEquals(types_mapping['Event'], 'documents')
        self.assertEquals(types_mapping['File'], 'file')

        # go back to default
        api.portal.set_registry_record('tabs_mapping',
                                       old_settings,
                                       interface=IRERSiteSearchSettings)
Exemplo n.º 4
0
def setRegistryTabs(context):
    """
    """
    types_tool = getToolByName(context, 'portal_types')
    portal_types = types_tool.listContentTypes()
    new_tabs = []
    for tab in DEFAULT_TABS:
        tab_ptype = tab[0]
        tab_title = tab[1]
        if tab_ptype in portal_types:
            new_value = TabsValueField()
            new_value.tab_title = tab_title
            new_value.portal_types = (tab_ptype,)
            new_tabs.append(new_value)
    return tuple(new_tabs)
Exemplo n.º 5
0
def setRegistryTabs(context):
    """
    """
    types_tool = getToolByName(context, 'portal_types')
    portal_types = types_tool.listContentTypes()
    new_tabs = []
    for tab in DEFAULT_TABS:
        tab_ptype = tab[0]
        tab_title = tab[1]
        if tab_ptype in portal_types:
            new_value = TabsValueField()
            new_value.tab_title = tab_title
            new_value.portal_types = (tab_ptype, )
            new_tabs.append(new_value)
    return tuple(new_tabs)
Exemplo n.º 6
0
def updateRegistryFromProperties(context):
    """
    Copy settings from old site properties to new plone.registry
    """
    logger.info('Migration from site_properties settings to registry')
    portal_properties = getToolByName(context, 'portal_properties')
    rer_properties = getattr(portal_properties, 'rer_properties', None)
    if not rer_properties:
        logger.info('No RER settings found. Migration skipped')
        return
    registry = queryUtility(IRegistry)
    settings = registry.forInterface(IRERSiteSearchSettings, check=False)
    indexes_in_search = rer_properties.getProperty('indexes_in_search', ())
    tabs_list = rer_properties.getProperty('tabs_list', ())
    indexes_hiddenlist = rer_properties.getProperty('indexes_hiddenlist', ())
    if not indexes_in_search:
        indexes = defaultSetRegistryIndex(context, DEFAULT_INDEXES)
        settings.available_indexes = indexes
    else:
        new_indexes = setRegistyIndexes(context, indexes_in_search)
        settings.available_indexes += new_indexes
    if not indexes_hiddenlist:
        indexes = defaultSetRegistryIndex(context, DEFAULT_HIDDEN_INDEXES)
        settings.hidden_indexes = indexes
    else:
        new_indexes = setRegistyIndexes(context, indexes_hiddenlist)
        settings.hidden_indexes += new_indexes
    if not tabs_list:
        tabs = defaultSetRegistyTabs(context)
        settings.tabs_mapping = tabs
        tabs_order_dict = queryUtility(IVocabularyFactory, name="rer.sitesearch.vocabularies.SearchTabsVocabulary")
        tabs_order = tabs_order_dict(context).by_token.keys()
        settings.tabs_order = tuple(tabs_order)
    else:
        tabs, tabs_order = setRegistryTabs(context, tabs_list)
        new_tabs = []
        for tab in tabs.keys():
            new_value = TabsValueField()
            new_value.tab_title = tab
            new_value.portal_types = tuple(tabs.get(tab))
            new_tabs.append(new_value)
        settings.tabs_mapping += tuple(new_tabs)
        settings.tabs_order = tabs_order
Exemplo n.º 7
0
    def test_tabs_mapping(self):
        """
        {
            'all': {'title': u'All'},
            'documents': {'portal_types': ('Document',), 'title': 'Documents'},
            'events': {'portal_types': ('Event',), 'title': 'Events'},
            'file': {'portal_types': ('File',), 'title': 'File'},
            'links': {'portal_types': ('Link',), 'title': 'Links'},
            'news': {'portal_types': ('News Item',), 'title': 'News'},
        }
        """

        tabs_mapping = self.view.tabs_mapping
        self.assertEquals(len(tabs_mapping.keys()), 6)
        self.assertTrue('documents' in tabs_mapping)
        self.assertTrue('news' in tabs_mapping)
        self.assertTrue('links' in tabs_mapping)
        self.assertTrue('file' in tabs_mapping)
        self.assertTrue('events' in tabs_mapping)
        self.assertEquals(
            tabs_mapping['documents']['portal_types'], ('Document',)
        )
        self.assertEquals(tabs_mapping['news']['portal_types'], ('News Item',))
        self.assertEquals(tabs_mapping['events']['portal_types'], ('Event',))

        # change settings
        old_settings = api.portal.get_registry_record(
            'tabs_mapping', interface=IRERSiteSearchSettings
        )
        new_settings = []
        for record in old_settings:
            if record.tab_title in ['News', 'Events']:
                continue
            if record.tab_title == 'Documents':
                new_record = TabsValueField()
                new_record.tab_title = record.tab_title
                new_record.portal_types = ('Document', 'Event', 'News Item')
                new_settings.append(new_record)
            else:
                new_settings.append(record)
        api.portal.set_registry_record(
            'tabs_mapping',
            tuple(new_settings),
            interface=IRERSiteSearchSettings,
        )

        tabs_mapping = self.view.tabs_mapping
        self.assertTrue('documents' in tabs_mapping)
        self.assertFalse('news' in tabs_mapping)
        self.assertTrue('links' in tabs_mapping)
        self.assertTrue('file' in tabs_mapping)
        self.assertFalse('events' in tabs_mapping)
        self.assertEquals(
            tabs_mapping['documents']['portal_types'],
            ('Document', 'Event', 'News Item'),
        )

        # go back to default
        api.portal.set_registry_record(
            'tabs_mapping', old_settings, interface=IRERSiteSearchSettings
        )