Esempio n. 1
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()
Esempio n. 2
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])
Esempio n. 3
0
 def clear_catalog(self, catalog_id):
     try:
         catalog = getattr(self, catalog_id)
         doc_map = getattr(self, catalog_id + '_map')
     except:
         raise Exception("Catalog " + catalog_id + " doenst exist.")
     setattr(self, catalog_id, Catalog())
     setattr(self, catalog_id + '_map', DocumentMap())
Esempio n. 4
0
    def clear(self):

        self._catalog.clear()
        self._document_map = DocumentMap()
        self._p_changed = 1
        self.catalog._p_changed = 1
        self._document_map._p_changed = 1
        self.__parent__._p_changed = 1
Esempio n. 5
0
    def __init__(self):
        super(PeopleDirectory, self).__init__()
        self['categories'] = Folder()  # {id: PeopleCategory}
        self.catalog = CachingCatalog()
        self.catalog.document_map = DocumentMap()
        self.update_indexes()

        # Set up a default configuration
        self['all'] = section = PeopleSection('All')
        section['all'] = report = PeopleReport('All')
        report.columns = ('name', 'organization', 'location', 'email')
        self.order = ['all']
Esempio n. 6
0
def bootstrap(zodb_root):
    if not 'projector' in zodb_root:
        # add site folder
        root = SiteFolder('Projector Site')
        zodb_root['projector'] = root
        # add catalog and document map
        catalog = Catalog()
        catalog['title'] = CatalogTextIndex('title')
        catalog['content'] = CatalogTextIndex('content')
        root.catalog = catalog
        document_map = DocumentMap()
        root.document_map = document_map
    return zodb_root['projector']
Esempio n. 7
0
    def __init__(self):
        super(Site, self).__init__()
        self.catalog = CachingCatalog()
        self.update_indexes()
        self.catalog.document_map = DocumentMap()

        profiles = create_content(IProfiles)
        self['profiles'] = profiles
        communities = create_content(ICommunities)
        self['communities'] = communities
        people = create_content(IPeopleDirectory)
        self['people'] = people
        self.users = KARLUsers(self)
        self.tags = Tags(self)
        self.sessions = SessionDataManager(3600, 5)
        self.filestore = PersistentMapping()
        self.list_aliases = OOBTree()
Esempio n. 8
0
File: site.py Progetto: lslaz1/karl
    def __init__(self):
        super(Site, self).__init__()
        self.catalog = CachingCatalog()
        self.update_indexes()
        self.catalog.document_map = DocumentMap()

        profiles = create_content(IProfiles)
        self['profiles'] = profiles
        communities = create_content(ICommunities)
        self['communities'] = communities
        people = create_content(IPeopleDirectory)
        self['people'] = people
        self.users = KARLUsers(self)
        self.tags = Tags(self)
        self.sessions = SessionDataManager(3600, 5)
        self.filestore = PersistentMapping()
        self.list_aliases = OOBTree()
        self.settings = OOBTree(self._default_settings)
        self.access_requests = OOBTree()
        self.failed_login_attempts = OOBTree()
        self.email_templates = OOBTree()
        self.denial_tracker = OOBTree()
        self['email_images'] = EmailFolder()
        self['invitations'] = create_content(IInvitationsFolder)
Esempio n. 9
0
 def __init__(self, data=None, **kwargs):
     self.catalog = Catalog()
     self.document_map = DocumentMap()
     populate_catalog(self.catalog)
     self.__site_settings__ = OOBTree()
     super(Root, self).__init__(data=data, **kwargs)
Esempio n. 10
0
 def __init__(self, data=None, **kwargs):
     self.catalog = Catalog()
     self.catalog.__parent__ = self  #To make traversal work
     self.catalog.document_map = DocumentMap()
     super(SiteRoot, self).__init__(data=data, **kwargs)
     update_indexes(self.catalog)
Esempio n. 11
0
 def add_catalog(self, catalog_id):
     setattr(self, catalog_id, Catalog())
     setattr(self, catalog_id + '_map', DocumentMap())
     self.catalogs.append(catalog_id)
     return getattr(self, catalog_id)
Esempio n. 12
0
    def __init__(self):

        self._catalog = RepozeCatalog()
        self._document_map = DocumentMap()
Esempio n. 13
0
class Catalog(object):

    def __init__(self):

        self._catalog = RepozeCatalog()
        self._document_map = DocumentMap()

    @property
    def catalog(self):
        """ convenient proxy to real catalog """

        return self._catalog

    def query(self, qry, as_summary=False, as_object=False, **kwargs):

        """ Query the catalog. If as_summary is set, return object summaries,
        as fetched from info from the indexes"""

        res = self._catalog.query(qry, **kwargs)

        if as_summary:
            return [self.get_object_summary(uuid) for uuid in res[1]]
        elif as_object:
            return [self.get_object(uuid) for uuid in res[1]]
        else:
            return res

    def index_object(self, object):

        path = object_to_path(object)
        uuid = object.uuid

        docid = self._document_map.add(uuid)
        self._document_map.add_metadata(docid, {'path': path})

        try:
            self.catalog.index_doc(docid, object)
            self._p_changed = 1
            self.catalog._p_changed = 1
            self._document_map._p_changed = 1
            self.__parent__._p_changed = 1
        except:
            LOGGER.exception("Could not index object!")

    def reindex_object(self, object):

        uuid = object.uuid

        docid = self._document_map.docid_for_address(uuid)
        if not docid:
            self.index_object(object)
            docid = self._document_map.docid_for_address(uuid)

        # update the path of the object in the documentmap since the
        # object might have been renamed / moved
        path = object_to_path(object)
        self._document_map.add_metadata(docid, {'path': path})

        try:
            self.catalog.reindex_doc(docid, object)
            self._p_changed = 1
            self.catalog._p_changed = 1
            self._document_map._p_changed = 1
            self.__parent__._p_changed = 1
        except:
            LOGGER.exception("Could not index object!")

    def unindex_object(self, object):

        uuid = object.uuid

        docid = self._document_map.docid_for_address(uuid)
        if docid:
            self.catalog.unindex_doc(docid)
            self._document_map.remove_docid(docid)
            self._p_changed = 1
            self.catalog._p_changed = 1
            self._document_map._p_changed = 1
            self.__parent__._p_changed = 1

    def clear(self):

        self._catalog.clear()
        self._document_map = DocumentMap()
        self._p_changed = 1
        self.catalog._p_changed = 1
        self._document_map._p_changed = 1
        self.__parent__._p_changed = 1

    def get_object(self, docid):

        metadata = self._document_map.get_metadata(docid)
        path = metadata['path']
        return path_to_object(path, self.__parent__)

    def get_object_summary(self, uuid):

        """ Return a summary of the found object, based on the values that
        the indexes hold on the given uuid"""

        summ = {}

        for key in self.catalog.keys():
            idx = self.catalog[key]
            if hasattr(idx, "_rev_index"):
                summ[key] = idx._rev_index.get(uuid, '')

        summ['key'] = uuid

        return ObjectSummary(summ)

    def list_objects(self):

        docids = self.list_object_ids()
        for docid in docids:
            metadata = self._document_map.get_metadata(docid)
            yield (docid, metadata['path'])

    def list_object_ids(self):

        return self._document_map.docid_to_address.keys()
Esempio n. 14
0
 def __init__(self, home, name, docid_attr='docid'):
     self.indexes = Indexes()
     self.home = home
     self.name = name
     self.docid_attr = docid_attr
     self.document_map = DocumentMap()
Esempio n. 15
0
class Catalog(object):

    def __init__(self, home, name, docid_attr='docid'):
        self.indexes = Indexes()
        self.home = home
        self.name = name
        self.docid_attr = docid_attr
        self.document_map = DocumentMap()

    def index_doc(self, doc):
        return self.indexes.index_doc(self._get_docid(doc), doc)

    def reindex_doc(self, doc):
        return self.indexes.reindex_doc(self._get_docid(doc), doc)

    def unindex_doc(self, doc_or_docid):
        if type(doc_or_docid) in (int, long):
            docid = doc_or_docid
        else:
            docid = getattr(doc_or_docid, self.docid_attr, None)
            if docid is None:
                return
        self.document_map.remove_docid(docid)
        return self.indexes.unindex_doc(docid)

    def query(self, queryobject, sort_index=None, limit=None, sort_type=None,
              reverse=False, names=None):
        count, docids = self.indexes.query(
            queryobject,
            sort_index=sort_index,
            limit=limit,
            sort_type=sort_type,
            reverse=reverse,
            names=names)
        return count, docids, self.resolver()

    def _get_docid(self, doc):
        docid_attr = self.docid_attr
        path = resource_path(doc)
        document_map = self.document_map
        docid = getattr(doc, docid_attr, None)
        if docid is None:
            docid = document_map.add(path)
            setattr(doc, docid_attr, docid)
        else:
            old_path = document_map.address_for_docid(docid)
            if old_path != path:
                document_map.remove_address(old_path)
                document_map.add(path, docid)
        return docid

    def resolver(self):
        root = self.home['content']
        document_map = self.document_map
        def resolve(docid):
            path = document_map.address_for_docid(docid)
            return find_resource(root, path)
        return resolve

    def add_index(self, name, index):
        """
        Add an index to an existing catalog.
        """
        log.info('Adding index: %s' % name)
        self.indexes[name] = index
        resolver = self.resolver()
        for docid in self.document_map.docid_to_address.keys():
            doc = resolver(docid)
            log.info('Calculating index for %s' % resource_path(doc))
            index.index_doc(docid, doc)