def main(): parser = argparse.ArgumentParser() parser.add_argument("config_uri", help="Paster ini file to load settings from") parser.add_argument("meeting_name", help="Which meeting to change") args = parser.parse_args() env = bootstrap(args.config_uri) root = env['root'] meeting = root[args.meeting_name] print "Resetting unread in %r" % args.meeting_name found = 0 i = 0 for obj in find_all_db_objects(meeting): unread = IUnread(obj, None) if unread == None: continue unread.reset_unread() found += 1 i += 1 if i == 10: print found i = 0 transaction.commit() env['closer']()
def evolve(root): """ Evolve db to work with Arche instead. Removes anything that's a duplicate. """ from arche.utils import find_all_db_objects try: import betahaus.pyracont #test except ImportError: print "IMPORTANT! password fields needed to make this migration. Install betahaus.pyracont" raise #Loop through all user objects _marker = object() for user in root.users.values(): #Remove old password tokens if hasattr(user, '__token__'): delattr(user, '__token__') #Transfer password fields old_pw = user.field_storage.get('password', {}).get(_marker) if old_pw: user.__password_hash__ = old_pw user.field_storage.pop('password', None) for obj in find_all_db_objects(root): #Handle groups attribute and transfer to local role if hasattr(obj, '__groups__'): for (name, roles) in obj.__groups__.items(): new_roles = set(roles) if 'role:Admin' in new_roles: new_roles.remove('role:Admin') new_roles.add('role:Administrator') obj.local_roles[name] = new_roles delattr(obj, '__groups__')
def save_success(self, appstruct): self.flash_messages.add(self.default_success, type="success") name = appstruct['name'] parent = self.context.__parent__ for obj in find_all_db_objects(self.context): self.request.reference_guards.moving(obj.uid) del parent[self.context.__name__] parent[name] = self.context return HTTPFound(location = self.request.resource_url(self.context))
def reindex_catalog(root, savepoint_limit = 1000, savepoint_callback=_savepoint_callback): i = 0 total = 0 import transaction logger.info("Reindexing catalog") for obj in find_all_db_objects(root): try: cataloger = ICataloger(obj) except TypeError: continue cataloger.index_object() i += 1 total += 1 if i>=savepoint_limit: i = 0 transaction.savepoint() savepoint_callback(total) logger.info("Process complete. %s objects reindexed", total)
def __call__(self): if not can_paste(self.context, self.request, self): raise HTTPForbidden(_("Can't paste to this context")) paste_data = self.request.session.get('__paste_data__') action_obj = self.resolve_uid(paste_data['uid']) parent = action_obj.__parent__ use_name = generate_slug(self.context, action_obj.__name__) if paste_data.get('move', False): for obj in find_all_db_objects(action_obj): self.request.reference_guards.moving(obj.uid) del parent[action_obj.__name__] self.flash_messages.add(_("Moved here")) else: action_obj = copy_recursive(action_obj) self.flash_messages.add(_("copy_references_notice", default = "New copy added here. " "References that pointed to the original object won't point to this one.")) self.context[use_name] = action_obj del self.request.session['__paste_data__'] return HTTPFound(location = self.request.resource_url(self.context[use_name]))
def _reorder_ais(meeting): order_priority = {} #Order will be blank so we must fetch the keys from data curr_keys = set(meeting.data.keys()) if curr_keys != set(meeting.keys()): meeting.order = meeting.data.keys() for k in curr_keys: order_priority[k] = len(curr_keys) for ai in meeting.values(): if not IAgendaItem.providedBy(ai): continue if 'order' in ai.field_storage: order_priority[ai.__name__] = ai.field_storage.pop('order') def _sorter(key): return order_priority[key] order = sorted(curr_keys, key=_sorter) meeting.order = order for obj in find_all_db_objects(meeting): cataloger = ICataloger(obj, None) if cataloger: cataloger.index_object()
def reindex_catalog(args, root, registry, **kw): root.catalog.clear() root.document_map.docid_to_address.clear() root.document_map.address_to_docid.clear() root.document_map.docid_to_metadata.clear() i = 0 limit = 500 total = 0 for obj in find_all_db_objects(root): try: cataloger = ICataloger(obj) except TypeError: continue cataloger.index_object() i += 1 total += 1 if i>limit: i = 0 transaction.savepoint() print total print "-- Process complete. Reindexed %s objects" % total
def reindex_catalog(args, root, registry, **kw): root.catalog.clear() root.document_map.docid_to_address.clear() root.document_map.address_to_docid.clear() root.document_map.docid_to_metadata.clear() i = 0 limit = 500 total = 0 for obj in find_all_db_objects(root): try: cataloger = ICataloger(obj) except TypeError: continue cataloger.index_object() i += 1 total += 1 if i > limit: i = 0 transaction.savepoint() print total print "-- Process complete. Reindexed %s objects" % total
def evolve(root): """ Change all poll descriptions to plaintext. """ from arche.interfaces import ICataloger from arche.utils import find_all_db_objects from webhelpers.html.render import sanitize #Move description to body root.body = root.description root.description = "" ICataloger(root).index_object() for obj in find_all_db_objects(root): if IPoll.providedBy(obj): #Turn description into plaintext obj.description = sanitize(obj.description) ICataloger(obj).index_object() elif IMeeting.providedBy(obj): #Move HTML field content to body obj.body = obj.description obj.description = "" ICataloger(obj).index_object()
def evolve(root): """ Change the Proposals so title and text are separated. Old proposals used to have only a title field that could be really long. Also add portlets to all meetings. """ from arche.utils import find_all_db_objects from arche.portlets import get_portlet_manager from voteit.core.models.meeting import add_default_portlets_meeting manager = get_portlet_manager(root) if not manager.get_portlets('right', 'meeting_list'): manager.add('right', 'meeting_list') for obj in find_all_db_objects(root): if IProposal.providedBy(obj): try: obj.text = obj.field_storage.pop('title') except KeyError: pass elif IMeeting.providedBy(obj): add_default_portlets_meeting(obj)