Esempio n. 1
0
def clear_and_reindex(root):
    import re

    from pyramid.traversal import resource_path
    from pyramid.traversal import find_interface
    from repoze.catalog.query import Eq

    from voteit.core.models.catalog import metadata_for_query
    from voteit.core.models.catalog import index_object
    from voteit.core.models.catalog import reindex_object
    from voteit.core.models.catalog import update_indexes
    from voteit.core.models.interfaces import IMeeting
    from voteit.core.scripts.catalog import find_all_base_content

    # reindex catalog
    root.catalog.clear()
    updated_indexes = update_indexes(root.catalog, reindex=False)
    contents = find_all_base_content(root)
    content_count = len(contents)

    #Note: There might be catalog aware models outside of this scope.
    #In that case, we need some way of finding them
    print "Found %s objects to update" % content_count
    i = 1
    p = 1
    for obj in contents:
        index_object(root.catalog, obj)
        if p == 100:
            print "%s of %s done" % (i, content_count)
            p = 0
        i += 1
        p += 1
Esempio n. 2
0
def clear_and_reindex(root):
    import re
    
    from pyramid.traversal import resource_path
    from pyramid.traversal import find_interface
    from repoze.catalog.query import Eq
    
    from voteit.core.models.catalog import metadata_for_query
    from voteit.core.models.catalog import index_object
    from voteit.core.models.catalog import reindex_object
    from voteit.core.models.catalog import update_indexes
    from voteit.core.models.interfaces import IMeeting
    from voteit.core.scripts.catalog import find_all_base_content

    # reindex catalog
    root.catalog.clear()
    updated_indexes = update_indexes(root.catalog, reindex=False)
    contents = find_all_base_content(root)
    content_count = len(contents)

    #Note: There might be catalog aware models outside of this scope.
    #In that case, we need some way of finding them
    print "Found %s objects to update" % content_count
    i = 1
    p = 1
    for obj in contents:
        index_object(root.catalog, obj)
        if p == 100:
            print "%s of %s done" % (i, content_count)
            p = 0
        i+=1
        p+=1
Esempio n. 3
0
    def test_index_object_preforms_reindex_if_object_already_indexed(self):
        from voteit.core.models.catalog import index_object
        catalog = self.root.catalog

        meeting = createContent('Meeting')
        meeting.title = 'hello world'
        self.root['meeting'] = meeting
        meeting.title = 'something new'
        #This should now preform reindex instead
        index_object(catalog, meeting)
        self.assertEqual(catalog.query("title == 'something new'")[0], 1)
Esempio n. 4
0
    def test_index_object_preforms_reindex_if_object_already_indexed(self):
        from voteit.core.models.catalog import index_object
        catalog = self.root.catalog

        meeting = createContent('Meeting')
        meeting.title = 'hello world'
        self.root['meeting'] = meeting
        meeting.title = 'something new'
        #This should now preform reindex instead
        index_object(catalog, meeting)
        self.assertEqual(catalog.query("title == 'something new'")[0], 1)
Esempio n. 5
0
 def import_data(self, parent, name, filedata):
     connection = parent._p_jar
     new_obj = connection.importFile(filedata)
     if ISiteRoot.providedBy(new_obj):
         raise ValueError(
             "Importing a new site root is not supported. If you want to import a complete database, simply copy the database file Data.fs"
         )
     parent[name] = new_obj
     # Reindex all objects
     for obj in find_all_base_content(new_obj):
         index_object(self.context.catalog, obj)
Esempio n. 6
0
def change_votes(root, userid, userid_lower):
    catalog = root.catalog
    result = catalog.search(content_type='Vote', creators=(userid, ))[1]
    for docid in result:
        # get vote
        obj = resolve_catalog_docid(catalog, root, docid)
        # get parent of vote
        parent = obj.__parent__
        # if userid is in parent container and the object in the parent is the object from the catalog
        if userid in parent and parent[userid] == obj:
            #Remember that this part won't reindex the catalog as it normally does.
            unindex_object(catalog, parent[userid])
            del parent[userid]  # remove with old userid
            parent[userid_lower] = obj  # add with new userid
            index_object(catalog, obj)
Esempio n. 7
0
def change_votes(root, userid, userid_lower):
    catalog = root.catalog
    result = catalog.search(content_type='Vote', creators=(userid,))[1]
    for docid in result:
        # get vote
        obj = resolve_catalog_docid(catalog, root, docid)
        # get parent of vote 
        parent = obj.__parent__
        # if userid is in parent container and the object in the parent is the object from the catalog
        if userid in parent and parent[userid] == obj:
            #Remember that this part won't reindex the catalog as it normally does.
            unindex_object(catalog, parent[userid])
            del parent[userid] # remove with old userid
            parent[userid_lower] = obj # add with new userid
            index_object(catalog, obj)
Esempio n. 8
0
def clear_and_reindex(root):
    # reindex catalog
    root.catalog.clear()
    updated_indexes = update_indexes(root.catalog, reindex=False)
    contents = find_all_base_content(root)
    content_count = len(contents)

    #Note: There might be catalog aware models outside of this scope.
    #In that case, we need some way of finding them
    print "Found %s objects to update" % content_count
    i = 1
    p = 1
    for obj in contents:
        index_object(root.catalog, obj)
        if p == 100:
            print "%s of %s done" % (i, content_count)
            p = 0
        i += 1
        p += 1
Esempio n. 9
0
def clear_and_reindex(root):
    # reindex catalog
    root.catalog.clear()
    updated_indexes = update_indexes(root.catalog, reindex=False)
    contents = find_all_base_content(root)
    content_count = len(contents)

    #Note: There might be catalog aware models outside of this scope.
    #In that case, we need some way of finding them
    print "Found %s objects to update" % content_count
    i = 1
    p = 1
    for obj in contents:
        index_object(root.catalog, obj)
        if p == 100:
            print "%s of %s done" % (i, content_count)
            p = 0
        i+=1
        p+=1
Esempio n. 10
0
def update_catalog(*args):
    worker = ScriptWorker('update_catalog')
    
    cat = worker.root.catalog
    print "Clearing old data from catalog"
    cat.clear()
    
    updated_indexes = update_indexes(cat, reindex=False)
    if updated_indexes:
        print "The following indexes were added: %s" % ", ".join(updated_indexes)
    print "Performing reindex of catalog indexes and metadata. This might take some time."
    
    contents = find_all_base_content(worker.root)
    content_count = len(contents)
        
    #Note: There might be catalog aware models outside of this scope.
    #In that case, we need some way of finding them
    
    print "Found %s objects to update" % content_count
    
    i = 1
    p = 1
    for obj in contents:
        index_object(cat, obj)
        if p == 20:
            print "%s of %s done" % (i, content_count)
            p = 0
        i+=1
        p+=1
    
    print "Update complete - reindexed %s objects" % content_count
    print "Committing to database"
    transaction.commit()
    print "Done"
    
    worker.shutdown()
    
Esempio n. 11
0
def update_catalog(*args):
    worker = ScriptWorker("update_catalog")

    cat = worker.root.catalog
    print "Clearing old data from catalog"
    cat.clear()

    updated_indexes = update_indexes(cat, reindex=False)
    if updated_indexes:
        print "The following indexes were added: %s" % ", ".join(updated_indexes)
    print "Performing reindex of catalog indexes and metadata. This might take some time."

    contents = find_all_base_content(worker.root)
    content_count = len(contents)

    # Note: There might be catalog aware models outside of this scope.
    # In that case, we need some way of finding them

    print "Found %s objects to update" % content_count

    i = 1
    p = 1
    for obj in contents:
        index_object(cat, obj)
        if p == 20:
            print "%s of %s done" % (i, content_count)
            p = 0
        i += 1
        p += 1

    print "Update complete - reindexed %s objects" % content_count
    print "Committing to database"
    transaction.commit()
    print "Done"

    worker.shutdown()
Esempio n. 12
0
def object_added(obj, event):
    """ Index a base content object. """
    root = find_interface(obj, ISiteRoot)
    index_object(root.catalog, obj)
    _update_if_ai_parent(root.catalog, obj)
Esempio n. 13
0
def object_added(obj, event):
    """ Index a base content object. """
    root = find_interface(obj, ISiteRoot)
    index_object(root.catalog, obj)
    _update_if_ai_parent(root.catalog, obj)