def evolve(root): print "initial reindex of catalog to make sure everything is up to date" clear_and_reindex(root) registry = get_current_registry() print "extracting the last aid from poroposals" catalog = root.catalog result = catalog.search(content_type="Proposal")[1] for docid in result: print "--------------------------------------------------" proposal = resolve_catalog_docid(catalog, root, docid) meeting = find_interface(proposal, IMeeting) proposal_ids = registry.queryAdapter(meeting, IProposalIds) print "extracting from proposal %s" % proposal.__name__ # get aid from propsoal aid_int = proposal.get_field_value('aid_int') print "proposal aid %s" % aid_int # get the aid for the creator currently saved in the meeting creators = proposal.get_field_value('creators') current_aid = proposal_ids.get(creators[0]) print "current aid for creator %s" % current_aid # if current aid is empty or the aid from the proposal is # greater then the current one, save it in the meeting if not current_aid or aid_int > current_aid: proposal_ids.add(creators[0], aid_int)
def evolve(root): from repoze.catalog.query import Any from repoze.catalog.query import Contains from repoze.catalog.query import Eq from pyramid.traversal import resource_path from voteit.core.models.catalog import reindex_object from voteit.core.models.catalog import resolve_catalog_docid print "Removing absolute urls in profile links" catalog = root.catalog host = None while not host: host = raw_input("Enter a host to replace (ex http://127.0.0.1:6543): ") count, result = catalog.query(Eq('path', resource_path(root)) & \ Contains('searchable_text', 'class="inlineinfo"') & \ Any('content_type', ('DiscussionPost', 'Proposal', ))) catalog = root.catalog print "Processing %s objects" % count for docid in result: # get object obj = resolve_catalog_docid(catalog, root, docid) obj.title = obj.title.replace(host, '') reindex_object(catalog, obj)
def evolve(root): from repoze.catalog.query import Any from repoze.catalog.query import Contains from repoze.catalog.query import Eq from pyramid.traversal import resource_path from voteit.core.models.catalog import reindex_object from voteit.core.models.catalog import resolve_catalog_docid print "Removing absolute urls in profile links" catalog = root.catalog host = None while not host: host = raw_input( "Enter a host to replace (ex http://127.0.0.1:6543): ") count, result = catalog.query(Eq('path', resource_path(root)) & \ Contains('searchable_text', 'class="inlineinfo"') & \ Any('content_type', ('DiscussionPost', 'Proposal', ))) catalog = root.catalog print "Processing %s objects" % count for docid in result: # get object obj = resolve_catalog_docid(catalog, root, docid) obj.title = obj.title.replace(host, '') reindex_object(catalog, obj)
def test_resolve_catalog_docid(self): from voteit.core.models.catalog import resolve_catalog_docid catalog = self.root.catalog meeting = createContent('Meeting') self.root['m'] = meeting docid = catalog.query("content_type == 'Meeting'")[1][0] self.assertEqual(meeting, resolve_catalog_docid(catalog, self.root, docid))
def change_usertags(root, userid, userid_lower): catalog = root.catalog result = catalog.search(path=resource_path(root), like_userids=(userid,))[1] for docid in result: obj = resolve_catalog_docid(catalog, root, docid) # get unread adapter usertags = UserTags(obj) for tag in usertags.tags_storage: if userid in usertags.tags_storage[tag]: usertags.tags_storage[tag].remove(userid) # remove old userid usertags.tags_storage[tag].add(userid_lower) # add new userid
def change_unread(root, userid, userid_lower): catalog = root.catalog result = catalog.search(path=resource_path(root), unread=(userid, ))[1] for docid in result: # get object obj = resolve_catalog_docid(catalog, root, docid) # get unread adapter unread = Unread(obj) if userid in unread.unread_storage: unread.unread_storage.remove(userid) # remove old userid unread.unread_storage.add(userid_lower) # add new userid
def change_unread(root, userid, userid_lower): catalog = root.catalog result = catalog.search(path=resource_path(root), unread=(userid,))[1] for docid in result: # get object obj = resolve_catalog_docid(catalog, root, docid) # get unread adapter unread = Unread(obj) if userid in unread.unread_storage: unread.unread_storage.remove(userid) # remove old userid unread.unread_storage.add(userid_lower) # add new userid
def change_mentions(root, userid, userid_lower): catalog = root.catalog result = catalog.query(Eq('path', resource_path(root)) & \ Contains('searchable_text', userid) & \ Any('content_type', ('DiscussionPost', 'Proposal', )))[1] for docid in result: # get object obj = resolve_catalog_docid(catalog, root, docid) title = obj.title for match in re.finditer('<a class="inlineinfo" href="http:\/\/[\da-z.-:]*/[\w-]*/_userinfo\?userid=('+userid+')" title="[\w\s-]*">@('+userid+')</a>', title, re.UNICODE): title = title[0:match.start(1)] + userid_lower + title[match.end(1):len(title)] # replace in url title = title[0:match.start(2)] + userid_lower + title[match.end(2):len(title)] # replace in text obj.title = title
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)
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)
def evolve(root): from voteit.core.models.catalog import resolve_catalog_docid from voteit.core.models.proposal_ids import create_proposal_id print "initial reindex of catalog to make sure everything is up to date" clear_and_reindex(root) print "adding aid to poroposals" catalog = root.catalog result = catalog.search(content_type="Proposal")[1] for docid in result: obj = resolve_catalog_docid(catalog, root, docid) create_proposal_id(obj) print "initial reindex of catalog to make sure everything is up to date" clear_and_reindex(root)
def change_creator_and_owner(root, userid, userid_lower): catalog = root.catalog result = catalog.search(path=resource_path(root), creators=(userid,))[1] for docid in result: # get object obj = resolve_catalog_docid(catalog, root, docid) # change creators creators = list(obj.creators) # get creators creators.remove(userid) # remove old userid creators.append(userid_lower) # add new userid obj.creators = creators # set creators # change owner if userid is owner if ROLE_OWNER in obj.get_groups(userid): obj.del_groups(userid, (ROLE_OWNER, ), event=False) # remove old userid obj.add_groups(userid_lower, (ROLE_OWNER, ), event=False) # add new userid
def resolve_catalog_docid(self, docid): """ Take a catalog docid and fetch its object. Convenience wrapper for api view""" return resolve_catalog_docid(self.root.catalog, self.root, docid)