示例#1
0
def bootstrap(zodb_root, app_root_id, request):
    """Setup Root Object and the ZODB Database structure"""

    if not app_root_id in zodb_root:
        # add root folders
        app_root = WebshopAPI()
        zodb_root[app_root_id] = app_root
        zodb_root[app_root_id]["categories"] = Folder()
        zodb_root[app_root_id]["item_groups"] = Folder()
        zodb_root[app_root_id]["items"] = Folder()
        zodb_root[app_root_id]["unit_of_measures"] = Folder()
        zodb_root[app_root_id]["vpe_types"] = Folder()
        # add repoze.catalog for indexing
        app_root["catalog"] = Catalog()
        app_root["catalog"]['parent_id'] = CatalogFieldIndex(get_parent_id)
        app_root["catalog"]['id'] = CatalogFieldIndex(get_id)
        app_root["catalog"]['__type__'] = CatalogFieldIndex(get__type__)
        app_root["catalog"]['group'] = CatalogFieldIndex(get_group)
        app_root["catalog"]['vpe_type_id'] = CatalogFieldIndex(get_vpe_type_id)
        app_root["catalog"]['unit_of_measure_id'] = \
            CatalogFieldIndex(get_unit_of_measure_id)
        app_root["catalog"]['quality_id'] = CatalogFieldIndex(get_quality_id)
        app_root["catalog"]['vpe_default'] = CatalogFieldIndex(get_vpe_default)
        app_root["catalog"]['title_url_slugs'] = CatalogKeywordIndex(
            get_title_url_slugs)
        app_root["catalog"]['shop_id'] = CatalogKeywordIndex(get_shop_ids)
        app_root["document_map"] = DocumentMap()
        transaction.commit()
    return Root(request, zodb_root[app_root_id])
示例#2
0
    def init_catalog(self):
        '''
        Create a repoze.catalog instance and specify
        indices of intereset
        '''        
        catalog = RCatalog()
        catalog.document_map = DocumentMap()                
        # set up indexes
        catalog['title'] = CatalogTextIndex('_get_title')
        catalog['titleSorter'] = CatalogFieldIndex('_get_sorter')
        catalog['collection'] = CatalogKeywordIndex('_get_collection')
        # Descriptions are converted to TEXT for indexing
        catalog['description'] = CatalogTextIndex('_get_description')
        catalog['startDate'] = CatalogFieldIndex('_get_startDate')
        catalog['endDate'] = CatalogFieldIndex('_get_endDate')
        catalog['modificationDate'] = CatalogFieldIndex('_get_modificationDate')
        catalog['fid'] = CatalogTextIndex('_get_fid')
        catalog['keywords'] = CatalogKeywordIndex('_get_keywordsList')
        catalog['category'] = CatalogKeywordIndex('_get_categoryList')
        # I define as Text because I would permit searched for part of names
        catalog['rolesVals'] = CatalogTextIndex('_get_roles')
        catalog['persons'] = CatalogTextIndex('_get_persons')

        # ICTP SPECIFIC: index a deadline date if found. Just COMMENT this line if not interested
        catalog['deadlineDate'] = CatalogFieldIndex('_get_deadlineDate')


        self.db.root()[self.catalogName] = catalog
        self.catalog = self.db.root()[self.catalogName] 
        # commit the indexes
        transaction.commit()
示例#3
0
    def update_indexes(self):
        """ Ensure that we have indexes matching what the application needs.

        This function is called when the site is first created, and again
        whenever the ``reindex_catalog`` script is run.

        Extensions can arrange to get their own indexes added by registering
        named utilities for the
        :interface:`karl.models.interfaces.IIndexFactory` interface:  each
        such interface will be called to create a new (or overwritten) index.
        """
        indexes = {
            'name': CatalogFieldIndex(get_name),
            'title': CatalogFieldIndex(get_title),  # used as sort index
            'titlestartswith': CatalogFieldIndex(get_title_firstletter),
            'interfaces': CatalogKeywordIndex(get_interfaces),
            'containment': CatalogKeywordIndex(get_containment),
            'texts': CatalogTextIndex(get_textrepr),
            'path': CatalogPathIndex2(get_path, attr_discriminator=get_acl),
            'allowed': CatalogKeywordIndex(get_allowed_to_view),
            'creation_date': GranularIndex(get_creation_date),
            'modified_date': GranularIndex(get_modified_date),
            'content_modified': GranularIndex(get_content_modified_date),
            'start_date': GranularIndex(get_start_date),
            'end_date': GranularIndex(get_end_date),
            'publication_date': GranularIndex(get_publication_date),
            'mimetype': CatalogFieldIndex(get_mimetype),
            'creator': CatalogFieldIndex(get_creator),
            'modified_by': CatalogFieldIndex(get_modified_by),
            'email': CatalogFieldIndex(get_email),
            'tags': TagIndex(self),
            'lastfirst': CatalogFieldIndex(get_lastfirst),
            'member_name': CatalogTextIndex(get_member_name),
            'virtual': CatalogFieldIndex(get_virtual),
        }

        for name, utility in getUtilitiesFor(IIndexFactory):
            indexes[name] = utility()

        catalog = self.catalog

        # add indexes
        for name, index in indexes.iteritems():
            if name not in catalog:
                catalog[name] = index

        # remove indexes
        for name in catalog.keys():
            if name not in indexes:
                del catalog[name]
示例#4
0
文件: evolve34.py 项目: iotest3/new
def evolve(site):
    """
    Add the new containment index to the catalog.
    """
    catalog = find_catalog(site)
    if 'containment' in catalog:
        print 'Nothing to do.'
        return

    index = CatalogKeywordIndex(get_containment)
    catalog['containment'] = index
    for docid, address in catalog.document_map.docid_to_address.items():
        print 'Indexing containment: %s' % address
        model = find_resource(site, address)
        index.index_doc(docid, model)
        model._p_deactivate()
示例#5
0
def _default_indexes():
    return {
        'title':
        CatalogFieldIndex(get_title),
        'description':
        CatalogFieldIndex(get_description),
        'type_name':
        CatalogFieldIndex(get_type_name),
        'sortable_title':
        CatalogFieldIndex(get_sortable_title),
        'path':
        CatalogPathIndex(get_path),
        'searchable_text':
        CatalogTextIndex(get_searchable_text,
                         lexicon=Lexicon(Splitter(), CaseNormalizer())),
        'uid':
        CatalogFieldIndex(get_uid),
        'tags':
        CatalogKeywordIndex(get_tags),
        'search_visible':
        CatalogFieldIndex(get_search_visible),
        'date':
        CatalogFieldIndex(get_date),
        'modified':
        CatalogFieldIndex(get_modified),
        'created':
        CatalogFieldIndex(get_created),
        'wf_state':
        CatalogFieldIndex(get_wf_state),
        'workflow':
        CatalogFieldIndex(get_workflow),
    }.items()
示例#6
0
    def test_it(self):
        from repoze.catalog.catalog import Catalog
        from repoze.catalog.indexes.field import CatalogFieldIndex
        from repoze.catalog.indexes.keyword import CatalogKeywordIndex
        from repoze.catalog.indexes.text import CatalogTextIndex

        catalog = Catalog()
        catalog['name'] = CatalogFieldIndex('name')
        catalog['title'] = CatalogFieldIndex('title')
        catalog['text'] = CatalogTextIndex('text')
        catalog['allowed'] = CatalogKeywordIndex('allowed')

        catalog.index_doc(1, Content('name1', 'title1', 'body one', ['a']))
        catalog.index_doc(2, Content('name2', 'title2', 'body two', ['b']))
        catalog.index_doc(3, Content('name3', 'title3', 'body three', ['c']))
        catalog.index_doc(4, Content('name4', None, 'body four', ['a', 'b']))
        catalog.index_doc(
            5, Content('name5', 'title5', 'body five', ['a', 'b', 'c']))
        catalog.index_doc(6, Content('name6', 'title6', 'body six', ['d']))

        numdocs, result = catalog.query(self.query,
                                        sort_index='name',
                                        limit=5,
                                        names=dict(body='body'))
        self.assertEqual(numdocs, 2)
        self.assertEqual(list(result), [4, 5])
示例#7
0
    def __call__(self, context):
        catalog = Catalog()
        idindexer = NodeAttributeIndexer('id')
        catalog['id'] = CatalogFieldIndex(idindexer)
        hashindex = NodeAttributeIndexer('searches')
        catalog['searches'] = CatalogKeywordIndex(hashindex)

        return catalog
示例#8
0
    def _test_functional_merge(self, **extra):
        catalog = self._makeOne()
        from repoze.catalog.indexes.field import CatalogFieldIndex
        from repoze.catalog.indexes.keyword import CatalogKeywordIndex
        from repoze.catalog.indexes.text import CatalogTextIndex
        from repoze.catalog.indexes.path2 import CatalogPathIndex2

        class Content(object):
            def __init__(self, field, keyword, text, path):
                self.field = field
                self.keyword = keyword
                self.text = text
                self.path = path

        field = CatalogFieldIndex('field')
        keyword = CatalogKeywordIndex('keyword')
        text = CatalogTextIndex('text')
        path = CatalogPathIndex2('path')
        catalog['field'] = field
        catalog['keyword'] = keyword
        catalog['text'] = text
        catalog['path'] = path
        map = {
            1:
            Content('field1', ['keyword1', 'same'], 'text one', '/path1'),
            2:
            Content('field2', ['keyword2', 'same'], 'text two',
                    '/path1/path2'),
            3:
            Content('field3', ['keyword3', 'same'], 'text three',
                    '/path1/path2/path3'),
        }
        for num, doc in map.items():
            catalog.index_doc(num, doc)
        num, result = catalog.search(field=('field1', 'field1'), **extra)
        self.assertEqual(num, 1)
        self.assertEqual(list(result), [1])
        num, result = catalog.search(field=('field2', 'field2'), **extra)
        self.assertEqual(num, 1)
        self.assertEqual(list(result), [2])
        num, result = catalog.search(field=('field2', 'field2'),
                                     keyword='keyword2',
                                     **extra)
        self.assertEqual(num, 1)
        self.assertEqual(list(result), [2])
        num, result = catalog.search(field=('field2', 'field2'),
                                     text='two',
                                     **extra)
        self.assertEqual(num, 1)
        self.assertEqual(list(result), [2])
        num, result = catalog.search(text='text', keyword='same', **extra)
        self.assertEqual(num, 3)
        self.assertEqual(list(result), [1, 2, 3])

        num, result = catalog.search(text='text', path='/path1', **extra)
        self.assertEqual(num, 2)
        self.assertEqual(list(result), [2, 3])
示例#9
0
 def __call__(self, context):
     catalog = Catalog()
     channels_indexer = NodeAttributeIndexer("channels")
     catalog[u"channels"] = CatalogKeywordIndex(channels_indexer)
     date_indexer = NodeAttributeIndexer("date")
     catalog[u"date"] = CatalogFieldIndex(date_indexer)
     title_indexer = NodeAttributeIndexer("title")
     catalog[u"title"] = CatalogTextIndex(title_indexer)
     type_indexer = NodeAttributeIndexer("type")
     catalog[u"type"] = CatalogFieldIndex(type_indexer)
     return catalog
示例#10
0
    def update_indexes(self):
        indexes = {
            'lastfirst': CatalogFieldIndex(get_lastfirst),
            'lastnamestartswith': CatalogFieldIndex(get_lastname_firstletter),
            'texts': CatalogTextIndex(get_textrepr),
            # path index is needed for profile deletion
            'path': CatalogPathIndex2(get_path, attr_discriminator=get_acl),
            'allowed': CatalogKeywordIndex(get_allowed_to_view),
            'is_staff': CatalogFieldIndex(is_staff),
            'groups': CatalogKeywordIndex(get_groups),

            # provide indexes for sorting reports
            'department': CatalogFieldIndex(get_department),
            'email': CatalogFieldIndex(get_email),
            'location': CatalogFieldIndex(get_location),
            'organization': CatalogFieldIndex(get_organization),
            'phone': CatalogFieldIndex(get_phone),
            'position': CatalogFieldIndex(get_position),
        }

        # provide indexes for filtering reports
        for name in self['categories'].keys():
            getter = ProfileCategoryGetter(name)
            indexes['category_%s' % name] = CatalogKeywordIndex(getter)

        catalog = self.catalog
        need_reindex = False

        # add indexes
        for name, index in indexes.items():
            if name not in catalog:
                catalog[name] = index
                need_reindex = True

        # remove indexes
        for name in catalog.keys():
            if name not in indexes:
                del catalog[name]

        return need_reindex
示例#11
0
 def __call__(self, context=None):
     catalog = Catalog()
     uid_indexer = NodeAttributeIndexer('uid')
     catalog[u'uid'] = CatalogFieldIndex(uid_indexer)
     email_indexer = NodeAttributeIndexer('personal_data.email')
     catalog[u'personal_data.email'] = CatalogFieldIndex(email_indexer)
     ordernumber_indexer = NodeAttributeIndexer('ordernumber')
     catalog[u'ordernumber'] = CatalogFieldIndex(ordernumber_indexer)
     booking_uids_indexer = NodeAttributeIndexer('booking_uids')
     catalog[u'booking_uids'] = CatalogKeywordIndex(booking_uids_indexer)
     vendor_uids_indexer = NodeAttributeIndexer('vendor_uids')
     buyable_uids_indexer = NodeAttributeIndexer('buyable_uids')
     catalog[u'buyable_uids'] = CatalogKeywordIndex(buyable_uids_indexer)
     catalog[u'vendor_uids'] = CatalogKeywordIndex(vendor_uids_indexer)
     creator_indexer = NodeAttributeIndexer('creator')
     catalog[u'creator'] = CatalogFieldIndex(creator_indexer)
     created_indexer = NodeAttributeIndexer('created')
     catalog[u'created'] = CatalogFieldIndex(created_indexer)
     firstname_indexer = NodeAttributeIndexer('personal_data.firstname')
     catalog[u'personal_data.firstname'] = \
         CatalogFieldIndex(firstname_indexer)
     lastname_indexer = NodeAttributeIndexer('personal_data.lastname')
     catalog[u'personal_data.lastname'] = \
         CatalogFieldIndex(lastname_indexer)
     city_indexer = NodeAttributeIndexer('billing_address.city')
     catalog[u'billing_address.city'] = CatalogFieldIndex(city_indexer)
     search_attributes = [
         'personal_data.lastname', 'personal_data.firstname',
         'personal_data.email', 'billing_address.city', 'ordernumber'
     ]
     text_indexer = NodeTextIndexer(search_attributes)
     catalog[u'text'] = CatalogTextIndex(text_indexer)
     # state on order only used for sorting in orders table
     state_indexer = NodeAttributeIndexer('state')
     catalog[u'state'] = CatalogFieldIndex(state_indexer)
     # salaried on order only used for sorting in orders table
     salaried_indexer = NodeAttributeIndexer('salaried')
     catalog[u'salaried'] = CatalogFieldIndex(salaried_indexer)
     return catalog
示例#12
0
def includeme(config):
    """ Register metadata adapter. """
    config.add_searchable_text_index('aid')
    config.add_searchable_text_discriminator(get_searchable_prop_or_disc)
    indexes = {
        'aid': CatalogFieldIndex(get_aid),
        'aid_int': CatalogFieldIndex(get_aid_int),
        'allowed_to_view': CatalogKeywordIndex(get_allowed_to_view),
        'view_meeting_userids': CatalogKeywordIndex(get_view_meeting_userids),
        'start_time': CatalogFieldIndex(get_start_time),
        'end_time': CatalogFieldIndex(get_end_time),
        'workflow_state': CatalogFieldIndex(get_workflow_state),
        '__name__': CatalogFieldIndex('__name__'),
    }
    config.add_catalog_indexes(__name__, indexes)
    config.add_subscriber(update_contained_in_ai,
                          [IAgendaItem, IWorkflowStateChange])
    config.update_index_info('aid_int',
                             linked='aid_int',
                             type_names='Proposal')
    config.update_index_info('aid', type_names='Proposal')
    config.update_index_info('view_meeting_userids', type_names='Meeting')
示例#13
0
 def __call__(self, context):
     catalog = Catalog()
     text_indexer = NodeTextIndexer(["name", "surname", "email"])
     catalog[u"text"] = CatalogTextIndex(text_indexer)
     email_indexer = NodeAttributeIndexer("email")
     catalog[u"email"] = CatalogFieldIndex(email_indexer)
     name_indexer = NodeAttributeIndexer("name")
     catalog[u"name"] = CatalogFieldIndex(name_indexer)
     surname_indexer = NodeAttributeIndexer("surname")
     catalog[u"surname"] = CatalogFieldIndex(surname_indexer)
     channels_indexer = NodeAttributeIndexer("channels")
     catalog[u"channels"] = CatalogKeywordIndex(channels_indexer)
     date_indexer = NodeAttributeIndexer("date")
     catalog[u"date"] = CatalogFieldIndex(date_indexer)
     newspaper_indexer = NodeAttributeIndexer("newspaper")
     catalog[u"newspaper"] = CatalogFieldIndex(newspaper_indexer)
     return catalog
示例#14
0
def includeme(config):
    config.scan(__name__)
    config.add_subscriber(support_resources,
                          [IBaseView, IViewInitializedEvent])
    #Add catalog index
    indexes = {
        'support_userids': CatalogKeywordIndex(get_support_userids_indexer),
    }
    config.add_catalog_indexes(__name__, indexes)
    #Setup storage
    config.add_usertag('support',
                       IProposal,
                       catalog_index='support_userids',
                       add_perm=ADD_SUPPORT,
                       view_perm=PERM_VIEW)
    config.add_view(
        SupportUsersView,
        context=IProposal,
        name='_support_users_popover',
        permission=PERM_VIEW,
        renderer='voteit.core.plugins:templates/support_users_popover.pt')
示例#15
0
def update_indexes(catalog, reindex=True):
    """ Add or remove indexes. If reindex is True, also reindex all content if
        an index has been added or removed.
        Will return a set of indexes changed regardless.
    """

    indexes = {
        'title': CatalogFieldIndex(get_title),
        'sortable_title': CatalogFieldIndex(get_sortable_title),
        'description': CatalogFieldIndex(get_description),
        'uid': CatalogFieldIndex(get_uid),
        'aid': CatalogFieldIndex(get_aid),
        'aid_int': CatalogFieldIndex(get_aid_int),
        'content_type': CatalogFieldIndex(get_content_type),
        'workflow_state': CatalogFieldIndex(get_workflow_state),
        'path': CatalogPathIndex(get_path),
        'creators': CatalogKeywordIndex(get_creators),
        'created': CatalogFieldIndex(get_created),
        'allowed_to_view': CatalogKeywordIndex(get_allowed_to_view),
        'view_meeting_userids': CatalogKeywordIndex(get_view_meeting_userids),
        'searchable_text': CatalogTextIndex(get_searchable_text),
        'start_time': CatalogFieldIndex(get_start_time),
        'end_time': CatalogFieldIndex(get_end_time),
        'unread': CatalogKeywordIndex(get_unread),
        'like_userids': CatalogKeywordIndex(get_like_userids),
        'order': CatalogFieldIndex(get_order),
        'tags': CatalogKeywordIndex(get_tags),
    }

    changed_indexes = set()

    # remove indexes
    for name in catalog.keys():
        if name not in indexes:
            del catalog[name]

    # add indexes
    for name, index in indexes.iteritems():
        if name not in catalog:
            catalog[name] = index
            if reindex:
                changed_indexes.add(name)

    if reindex:
        reindex_indexes(catalog)

    return changed_indexes
示例#16
0
 def create(self, indexer):
     return CatalogKeywordIndex(indexer)