def deferred_groups_widget(node, kw): context = kw['context'] meeting = find_interface(context, IMeeting) groups = meeting.get('groups', {}) choices = [] for (name, group) in groups.items(): choices.append((name, group.title)) if choices: choices.insert(0, ('', _(u"<select>"))) else: choices.append(('', _(u"<No groups available!>"))) return deform.widget.SelectWidget(values = choices)
def rec_to_discussions_form(self): """ Note: This is far from finished, don't use this unless you really know what you're doing! """ schema = createSchema('PopulateFromRecommendationsSchema') add_csrf_token(self.context, self.request, schema) schema = schema.bind(context = self.context, request = self.request, api = self.api) form = deform.Form(schema, buttons=(button_save,)) self.api.register_form_resources(form) post = self.request.POST if 'save' in post: controls = post.items() try: appstruct = form.validate(controls) except deform.ValidationFailure, e: self.response['form'] = e.render() return self.response adjust_wf = appstruct['adjust_wf'] group = appstruct['group'] userid = appstruct['userid'] dry_run = appstruct['dry_run'] created_discussion_posts = 0 wf_adjusted_proposals = 0 proposals_and_rec = self.get_proposals_and_rec(group) handled_props = len(proposals_and_rec) for (prop, rec) in proposals_and_rec: if rec['text']: created_discussion_posts += 1 text = "%s\n%s" % (rec['text'], u" ".join([u'#%s' % x for x in prop.get_tags()])) post = createContent('DiscussionPost', creators = [userid], text = text) name = post.suggest_name(prop.__parent__) prop.__parent__[name] = post if rec['state'] and adjust_wf: wf_adjusted_proposals += 1 prop.workflow.initialize(prop) prop.set_workflow_state(self.request, rec['state']) self.api.flash_messages.add(_(u"Done - handled ${count} proposals", mapping = {'count': handled_props})) self.api.flash_messages.add(_(u"${count} new discussion posts added", mapping = {'count': created_discussion_posts})) if wf_adjusted_proposals: self.api.flash_messages.add(_(u"${count} proposals workflow adjusted", mapping = {'count': wf_adjusted_proposals})) if dry_run: from transaction import abort abort() self.api.flash_messages.add(_(u"DRY RUN - transaction aborted and nothing saved!")) return HTTPFound(location = self.request.resource_url(self.context))
def transfer_permissions_form(self): schema = createSchema('TransferPermissionsSchema').bind(context = self.context, request = self.request) add_csrf_token(self.context, self.request, schema) form = deform.Form(schema, buttons=(button_save, button_cancel,)) self.api.register_form_resources(form) post = self.request.POST if 'save' in post: controls = post.items() try: appstruct = form.validate(controls) except deform.ValidationFailure, e: #pragma : no cover self.response['form'] = e.render() return self.response from_meeting = self.api.root[appstruct['from_meeting']] value = from_meeting.get_security() self.api.meeting.set_security(value) self.api.flash_messages.add(_(u"Permissions transfered")) return HTTPFound(location = self.request.resource_url(self.api.meeting))
def clone_form(self): """ Note: This is far from finished, don't use this unless you really know what you're doing! """ schema = createSchema('CloneMeetingSchema') add_csrf_token(self.context, self.request, schema) schema = schema.bind(context = self.context, request = self.request, api = self.api) form = deform.Form(schema, buttons=(button_save, button_cancel,)) self.api.register_form_resources(form) post = self.request.POST if 'save' in post: controls = post.items() try: appstruct = form.validate(controls) except deform.ValidationFailure, e: #pragma : no cover self.response['form'] = e.render() return self.response new_name = appstruct['new_name'] new_meeting = createContent('Meeting', title = "Clone of %s" % self.context.title) self.api.root[new_name] = new_meeting if hasattr(self.context, '__proposal_ids__'): new_meeting.__proposal_ids__ = deepcopy(self.context.__proposal_ids__) ignore_attributes = appstruct['ignore_attributes'].splitlines() self.process_meeting_structure(new_meeting, ignore_attributes) self.api.flash_messages.add(_(u"Cloned meeting")) return HTTPFound(location = self.request.resource_url(new_meeting))
import colander import deform from betahaus.pyracont.decorators import schema_factory from voteit.core.validators import deferred_check_context_unique_name from voteit.tools import ToolsMF as _ @schema_factory('CloneMeetingSchema', title = _("Clone meeting content - Warning: Don't use this unless you know what you're doing!"), description = _(u"clone_meeting_description", default = u"Warning - this may take a really long time. No status messages or similar will be displayed while processing. " u"Make sure no heavy activity goes on within the database while you copy, it will fail in that case. " u"Note that mail notifications might be sent to users."),) class CloneMeetingSchema(colander.Schema): new_name = colander.SchemaNode(colander.String(), validator = deferred_check_context_unique_name) #FIXME: types_to_clone = colander.SchemaNode() ignore_attributes = colander.SchemaNode(colander.String(), description = _(u"ignore_attrs_description", default = u"Things not to copy from field_storage."), widget = deform.widget.TextAreaWidget(cols = 40, rows = 5), default = "uid", missing = u"",)
mapping = {'count': created_discussion_posts})) if wf_adjusted_proposals: self.api.flash_messages.add(_(u"${count} proposals workflow adjusted", mapping = {'count': wf_adjusted_proposals})) if dry_run: from transaction import abort abort() self.api.flash_messages.add(_(u"DRY RUN - transaction aborted and nothing saved!")) return HTTPFound(location = self.request.resource_url(self.context)) self.response['form'] = form.render() return self.response def get_proposals_and_rec(self, group): """ Return all proposals that have recommendations from selected group. """ results = set() for docid in self.api.search_catalog(context = self.context, content_type = 'Proposal')[1]: prop = self.api.resolve_catalog_docid(docid) recs = self.request.registry.getAdapter(prop, IGroupRecommendations) recommendation = recs.get_group_data(group) if recommendation is not None: results.add((prop, recommendation)) return results @view_action('meeting', 'rec_to_discussions', title = _(u"Recommendations to discussions"), permission = security.MANAGE_SERVER) def menu_link(context, request, va, **kw): api = kw['api'] url = request.resource_url(api.meeting, 'rec_to_discussions') return """<li><a href="%s">%s</a></li>""" % (url, api.translate(va.title))
def transfer_permissions_form(self): schema = createSchema('TransferPermissionsSchema').bind(context = self.context, request = self.request) add_csrf_token(self.context, self.request, schema) form = deform.Form(schema, buttons=(button_save, button_cancel,)) self.api.register_form_resources(form) post = self.request.POST if 'save' in post: controls = post.items() try: appstruct = form.validate(controls) except deform.ValidationFailure, e: #pragma : no cover self.response['form'] = e.render() return self.response from_meeting = self.api.root[appstruct['from_meeting']] value = from_meeting.get_security() self.api.meeting.set_security(value) self.api.flash_messages.add(_(u"Permissions transfered")) return HTTPFound(location = self.request.resource_url(self.api.meeting)) self.response['form'] = form.render() return self.response @view_action('meeting', 'transfer_permissions', title = _(u"Transfer permissions"), link = "transfer_permissions", permission = security.MANAGE_SERVER) def menu_link(context, request, va, **kw): api = kw['api'] url = request.resource_url(api.meeting, va.kwargs['link']) return """<li><a href="%s">%s</a></li>""" % (url, api.translate(va.title))
def deferred_groups_widget(node, kw): context = kw['context'] meeting = find_interface(context, IMeeting) groups = meeting.get('groups', {}) choices = [] for (name, group) in groups.items(): choices.append((name, group.title)) if choices: choices.insert(0, ('', _(u"<select>"))) else: choices.append(('', _(u"<No groups available!>"))) return deform.widget.SelectWidget(values = choices) @schema_factory('PopulateFromRecommendationsSchema', title = _("Populate a meeting based on group recommendations"), description = _(u"populate_from_recommendations_description", default = u"Create discussions and adjust proposals according to group recommendations. " u"Warning - this may take a really long time. No status messages or similar will be displayed while processing. " u"Make sure no heavy activity goes on within the database while you copy, it will fail in that case. " u"Note that mail notifications might be sent to users."),) class PopulateFromRecommendationsSchema(colander.Schema): userid = colander.SchemaNode( colander.String(), title = _(u"UserID to post as"), validator=deferred_existing_userid_validator, widget = deferred_autocompleting_userid_widget, ) group = colander.SchemaNode( colander.String(), title = _(u"Group to use"),
def process_meeting_structure(self, new_meeting, ignore_attributes): for ai in self.context.get_content(content_type = 'AgendaItem'): new_ai = createContent('AgendaItem') for (k, v) in ai.field_storage.items(): if k in ignore_attributes: continue new_ai.field_storage[k] = v new_meeting[ai.__name__] = new_ai self.process_ai(ai, new_ai, ignore_attributes) def process_ai(self, ai, new_ai, ignore_attributes): #FIXME: This should be dynamic later on for obj in ai.get_content(content_type = 'Proposal'): new_obj = createContent('Proposal') for (k, v) in obj.field_storage.items(): if k in ignore_attributes: continue new_obj.field_storage[k] = v if hasattr(obj, '__tags__'): new_obj.__tags__ = deepcopy(obj.__tags__) new_ai[obj.__name__] = new_obj @view_action('meeting', 'clone_meeting', title = _(u"Clone meeting"), link = "clone_meeting", permission = security.MANAGE_SERVER) def menu_link(context, request, va, **kw): api = kw['api'] url = request.resource_url(api.meeting, va.kwargs['link']) return """<li><a href="%s">%s</a></li>""" % (url, api.translate(va.title))
import colander import deform from pyramid.traversal import find_root from betahaus.pyracont.decorators import schema_factory from voteit.core.validators import deferred_check_context_unique_name from voteit.tools import ToolsMF as _ @colander.deferred def meeting_choices_widget(node, kw): context = kw['context'] root = find_root(context) meeting_choices = set() for meeting in root.get_content(content_type='Meeting'): meeting_choices.add((meeting.__name__, meeting.title)) return deform.widget.SelectWidget(values=meeting_choices) @schema_factory('TransferPermissionsSchema', title = _("Transfer Permissions - Warning: Don't use this unless you know what you're doing!"), description = _(u"transfer_permissions_description", default = u"Copy another meetings permissions and make them identical here. " u"This will replace local permissions with the ones from the other meeting! "),) class CloneMeetingSchema(colander.Schema): from_meeting = colander.SchemaNode(colander.String(), widget = meeting_choices_widget)