Beispiel #1
0
 def set_delegation_voters(self):
     _check_ongoing_poll(self)
     name = self.request.GET.get('delegation')
     delegation = self.meeting_delegations[name]
     if not self.request.authenticated_userid in delegation.leaders and not self.request.is_moderator:
         raise HTTPForbidden(_(u"Only delegation leads may distribute votes"))
     schema = DelegationVotesDistributionSchema()
     schema = schema.bind(context = self.context, request = self.request, view = self)
     form = deform.Form(schema, buttons=())
     controls = self.request.POST.items()
     try:
         appstruct = form.validate(controls)
     except deform.ValidationFailure:
         return HTTPForbidden(_(u"Something went wrong, please try again"))
     #We validate this data without the schema here
     userids_votes = appstruct['userids_votes']
     vote_count = sum([x['votes'] for x in userids_votes])
     if delegation.vote_count != vote_count:
         return HTTPForbidden(_(u"Vote count didn't match."))
     #clear current voters
     delegation.voters.clear()
     for item in userids_votes:
         if item['votes']:
             #Make sure they're voters
             delegation.voters[item['userid']] = item['votes']
             self.set_voter_role(item['userid'], True)
         else:
             #Remove voting permisison
             self.set_voter_role(item['userid'], False)
             
     self.flash_messages.add(_(u"Updated"))
     url = self.request.resource_url(self.context, 'manage_meeeting_delegation', query = {'delegation': name})
     return HTTPFound(location = url)
Beispiel #2
0
def add_ai_hashtag(schema, event):
    """ Subscriber that sets hashtag base for an agenda item. """
    schema.add(colander.SchemaNode(
        colander.String(),
        name = "proposal_hashtag",
        title = _(u"Base for hashtags."),
        validator = colander.Regex(r'[a-zA-Z0-9\-\_]{2,30}',
                                   msg = _("ai_hashtag_validator_error",
                                          default = "Only letters, numbers, '-' and '_'. "
                                                    "Required length 2-30 chars.")),
        description = _("ai_hashtag_description",
                        default = "Any proposals added here will have this string plus a number. "
                        "Something like this: [base for hashtag]-[number]"),
        missing = ""),)
Beispiel #3
0
 def delete_success(self, appstruct):
     msg = _("Deleted '${title}'",
             mapping = {'title': self.meeting_delegations[self.delegation_name].title})
     self.flash_messages.add(msg, type = 'warning')
     del self.meeting_delegations[self.delegation_name]
     url = self.request.resource_url(self.context, 'meeting_delegations')
     return HTTPFound(location = url)
Beispiel #4
0
def _check_ongoing_poll(view):
    """ Check if a poll is ongoing, return number of ongoing polls """
    meeting_path = resource_path(view.request.meeting)
    ongoing = view.catalog_search(type_name = 'Poll',
                                  path = meeting_path,
                                  workflow_state = 'ongoing')
    if ongoing:
        raise HTTPForbidden(_(u"access_during_ongoing_not_allowed",
                            default = u"During ongoing polls, this action isn't allowed. "
                            "Try again when polls have closed."))
Beispiel #5
0
 def __call__(self, node, value):
     existing_userid = ExistingUserIDs(self.context)
     existing_userid(node, value) #Make sure userid exists
     delegations = self.request.registry.getAdapter(self.context, IMeetingDelegations)
     current_name = self.request.GET.get('delegation')
     for delegation in delegations.values():
         if delegation.name == current_name:
             continue
         if value in delegation.members:
             raise colander.Invalid(node, _(u"Already part of the delegation ${delegation}",
                                            mapping = {'delegation': delegation.title}))
Beispiel #6
0
 def save_success(self, appstruct):
     delegation = self.delegation
     delegation.title = appstruct['title']
     delegation.description = appstruct['description']
     delegation.leaders.clear()
     delegation.leaders.update(appstruct['leaders'])
     if delegation.vote_count != appstruct['vote_count']:
         delegation.vote_count = appstruct['vote_count']
         delegation.voters.clear()
         msg = _(u"voters_cleared_on_update_notice",
                 default = u"When you update vote count, vote distribution is cleared. Please redistribute votes for this group!")
         self.flash_messages.add(msg)
     else:
         self.flash_messages.add(self.default_success)
     url = self.request.resource_url(self.context, 'manage_meeeting_delegation', query = {'delegation': self.delegation_name})
     return HTTPFound(location = url)
Beispiel #7
0
 def manage_delegation(self):
     """ Manage delegation members and votes, for delegation leads.
         Note that delegation lead isn't a perm and has to be checked in this view.
     """
     sfs_manage_delegation.need()
     _check_ongoing_poll(self)
     #FIXME: When we can use dynamic permissions, update perms here
     delegation = self.meeting_delegations[self.request.GET.get('delegation')]
     if not self.request.authenticated_userid in delegation.leaders and not self.request.is_moderator:
         raise HTTPForbidden(_(u"Only delegation leads may distribute votes"))
     response = {}
     response['delegation'] = delegation
     #Make sure all members are inbluded in form, even if they're not stored as voters
     voters = {}
     for userid in delegation.members:
         voters[userid] = 0
     voters.update(delegation.voters)
     response['voters'] = voters
     return response
Beispiel #8
0
 def save_success(self, appstruct):
     previous_members = set(self.delegation.members) - set(appstruct['members'])
     self.delegation.members.clear()
     self.delegation.members.update(appstruct['members'])
     #Set discuss and propose for delegation members
     for userid in appstruct['members']:
         self.context.local_roles.add(userid, [security.ROLE_DISCUSS, security.ROLE_PROPOSE])
     #remove discuss and propose + vote in case they have that
     for userid in previous_members:
         self.context.local_roles.remove(userid, [security.ROLE_DISCUSS, security.ROLE_PROPOSE, security.ROLE_VOTER])
     #Remove non-members from vote list
     userids_non_members = set(self.delegation.voters.keys()) - set(appstruct['members'])
     for userid in userids_non_members:
         del self.delegation.voters[userid]
     if userids_non_members:
         msg = _(u"removed_from_voters_list_notice",
                 default = u"You removed users who had votes set to them - please update vote distribution. Previous voters are: ${prev_voters}",
                 mapping = {'prev_voters': ", ".join(userids_non_members)})
         self.flash_messages.add(msg, type = 'warning')
     else:
         self.flash_messages.add(self.default_success)
     url = self.request.resource_url(self.context, 'manage_meeeting_delegation', query = {'delegation': self.delegation.name})
     return HTTPFound(location = url)
Beispiel #9
0
 def title(self):
     return _(u"really_delete_delegation_warning",
              default = u"Really delete delegation '${delegation_title}'? This can't be undone",
              mapping = {'delegation_title': self.meeting_delegations[self.delegation_name].title})
Beispiel #10
0
 def __init__(self, context, request):
     super(MangeDelegationMembersForm, self).__init__(context, request)
     _check_ongoing_poll(self)
     if not self.request.authenticated_userid in self.delegation.leaders and not self.request.is_moderator:
         raise HTTPForbidden(_("Only delegation leaders may change members."))
Beispiel #11
0
#             if polls:
#                 result_ais.append(ai)
#                 result_polls[ai.__name__] = polls
#         self.response['result_ais'] = result_ais
#         self.response['result_polls'] = result_polls
# 
#         def _vote_count_for(poll, userids):
#             
#             return self.api.search_catalog(path = resource_path(poll),
#                                            content_type = 'Vote',
#                                            creators = {'query': userids,
#                                                        'operator': 'or'})[0]
#         self.response['vote_count_for'] = _vote_count_for
#         return self.response

@view_action('participants_menu', 'delegations', title = _(u"Delegations"))
def delegations_menu_link(context, request, va, **kw):
    return """<li><a href="%s">%s</a></li>""" % (request.resource_url(request.meeting, 'meeting_delegations'),
                                                 request.localizer.translate(va.title))

@view_action('user_info', 'delegation_info', interface = IUser)
def delegation_info(context, request, va, **kw):
    if not request.meeting:
        return
    delegations = request.registry.getAdapter(request.meeting, IMeetingDelegations)
    delegation = delegations.get_delegation_for(context.userid)
    if not delegation:
        return
    response = dict(
        delegation = delegation,
        context = context)