当前位置: 首页>>代码示例>>Python>>正文


Python core._函数代码示例

本文整理汇总了Python中voteit.core._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: agenda_template_select

 def agenda_template_select(self):
     #FIXME: Should this be a migrate script?
     try:
         agenda_templates = self.api.root['agenda_templates']
     except KeyError:  # pragma: no coverage
         obj = createContent('AgendaTemplates', title = _(u"Agenda templates"), creators = ['admin'])
         agenda_templates = self.api.root['agenda_templates'] = obj
     
     get = self.request.GET
     if 'apply' in get:
         template_name = get['apply']
         if template_name in agenda_templates:
             template = agenda_templates[template_name]
             template.populate_meeting(self.context)
             
             msg = _(u"agenda_template_apply_template_success",
                     default = u"Selected template applied to meeting.")
             self.api.flash_messages.add(msg)
             
             return HTTPFound(location = resource_url(self.context, self.request))
         else:
             err_msg = _(u"agenda_template_apply_invalid_template",
                     default = u"No template named ${template} could be found.",
                     mapping = {'template': template_name})
             self.api.flash_messages.add(err_msg, type="error")
     
     self.response['agenda_templates'] = agenda_templates
     
     return self.response
开发者ID:tobsan,项目名称:voteit.core,代码行数:29,代码来源:agenda_templates.py

示例2: sort

    def sort(self):
        self.response['title'] = _(u"order_agenda_template_view_title",
                                   default = u"Drag and drop agenda items to reorder")

        post = self.request.POST
        if 'cancel' in self.request.POST:
            url = resource_url(self.context, self.request)
            return HTTPFound(location = url)

        if 'save' in post:
            controls = self.request.POST.items()
            ais = self.context.get_field_value('agenda_items')
            order = 0
            agenda_items = []
            for (k, v) in controls:
                if k == 'agenda_items':
                    ai = ais[int(v)]
                    ai['order'] = order
                    order += 1
                    agenda_items.append(ai)
            self.context.set_field_value('agenda_items', agenda_items)
            self.api.flash_messages.add(_(u'Order updated'))
            url = resource_url(self.context, self.request)
            return HTTPFound(location = url)

        return self.response
开发者ID:tobsan,项目名称:voteit.core,代码行数:26,代码来源:agenda_templates.py

示例3: _results_ts

 def _results_ts(count):
     """ Note about the odd syntax: pluralize returns unicode, so it won't be translated.
         Hence it needs to be converted back to a translation string.
     """
     return _(self.api.pluralize(_(u"item"),
                               _(u"items"),
                               count))
开发者ID:tobsan,项目名称:voteit.core,代码行数:7,代码来源:search.py

示例4: edit_form

 def edit_form(self):
     """ For configuring polls that haven't started yet. """
     schema_name = self.api.get_schema_name(self.context.content_type, 'edit')
     schema = createSchema(schema_name, after_bind=poll_schema_after_bind)
     add_csrf_token(self.context, self.request, schema)
     schema = schema.bind(context=self.context, request=self.request, api = self.api)
     form = Form(schema, buttons=(button_update, button_cancel))
     self.api.register_form_resources(form)
     post = self.request.POST
     if self.request.method == 'POST':
         if 'update' in post:
             controls = post.items()
             try:
                 #appstruct is deforms convention. It will be the submitted data in a dict.
                 appstruct = form.validate(controls)
             except ValidationFailure, e:
                 self.response['form'] = e.render()
                 return self.response
             removed_uids = set(self.context.proposal_uids) - set(appstruct['proposals'])
             if removed_uids:
                 #Adjust removed proposals back to published state, if they're locked
                 for uid in removed_uids:
                     prop = self.context.get_proposal_by_uid(uid)
                     if prop.get_workflow_state() == 'voting':
                         prop.set_workflow_state(self.request, u'published')
             updated = self.context.set_field_appstruct(appstruct)
             if updated:
                 self.api.flash_messages.add(_(u"Successfully updated"))
             else:
                 self.api.flash_messages.add(_(u"Nothing changed"))
         if 'cancel' in post:
             self.api.flash_messages.add(_(u"Canceled"))
         url = self.request.resource_url(self.context.__parent__, anchor = self.context.uid)
         return HTTPFound(location = url)
开发者ID:tobsan,项目名称:voteit.core,代码行数:34,代码来源:poll.py

示例5: configure_access_policy

 def configure_access_policy(self):
     access_policy_name = self.context.get_field_value('access_policy', 'invite_only')
     access_policy = self.request.registry.queryAdapter(self.context, IAccessPolicy, name = access_policy_name)
     if not access_policy:
         err_msg = _(u"access_policy_not_found_moderator",
                     default = u"""Can't find an access policy with the id '${policy}'.
                                 This might mean that the registered access type for this meeting doesn't exist anylonger.
                                 Please change access policy.""",
                     mapping = {'policy': access_policy_name})
         self.api.flash_messages.add(err_msg, type="error")
         url = self.request.resource_url(self.api.meeting, 'access_policy')
         return HTTPFound(location=url)
     form = access_policy.config_form(self.api)
     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
         self.context.set_field_appstruct(appstruct)
         self.api.flash_messages.add(_(u"Saved"))
         url = self.request.resource_url(self.api.meeting)
         return HTTPFound(location=url)
开发者ID:tobsan,项目名称:voteit.core,代码行数:25,代码来源:meeting.py

示例6: add_form

    def add_form(self):
        post = self.request.POST
        if 'cancel' in post:
            self.api.flash_messages.add(_(u"Canceled"))
            url = resource_url(self.context, self.request)
            return HTTPFound(location=url)

        schema = createSchema('AddUserSchema')
        add_csrf_token(self.context, self.request, schema)
        schema = schema.bind(context=self.context, request=self.request, api = self.api)
        form = Form(schema, buttons=(button_add, button_cancel))
        self.api.register_form_resources(form)

        if 'add' in post:
            controls = post.items()
            try:
                #appstruct is deforms convention. It will be the submitted data in a dict.
                appstruct = form.validate(controls)
            except ValidationFailure, e:
                self.response['form'] = e.render()
                return self.response
            
            #Userid and name should be consistent
            name = appstruct['userid']
            del appstruct['userid']
            
            #creators takes care of setting the role owner as well as adding it to creators attr.
            obj = createContent('User', creators=[name], **appstruct)
            self.context[name] = obj

            self.api.flash_messages.add(_(u"Successfully added"))

            url = resource_url(self.context, self.request)            
            return HTTPFound(location=url)
开发者ID:tobsan,项目名称:voteit.core,代码行数:34,代码来源:users.py

示例7: meeting_mail_name_node

def meeting_mail_name_node():
    return colander.SchemaNode(colander.String(),
                               title = _(u"Name of the contact person for this meeting"),
                               default = _deferred_current_fullname,
                               validator = colander.Regex(regex=NAME_PATTERN,
                                                          msg=_(u"name_pattern_error",
                                                                default = u"Must be at least 3 chars + only alphanumeric characters allowed")),)
开发者ID:tobsan,项目名称:voteit.core,代码行数:7,代码来源:meeting.py

示例8: ticket_claim

 def ticket_claim(self):
     """ After login or registration, redirect back here, where information about the ticket will be displayed,
         and a confirmation that you want to use the ticket for the current user.
         
         While we use a regular deform form, it's not ment to be displayed or handle any validation.
     """
     if not self.api.userid:
         raise HTTPForbidden("Direct access to this view for unauthorized users not allowed.")
     schema = createSchema('ClaimTicketSchema', validator = deferred_token_form_validator)
     schema = schema.bind(context=self.context, request=self.request, api = self.api)
     form = deform.Form(schema, buttons=(button_add, button_cancel))
     if self.request.GET.get('claim'):
         controls = self.request.params.items()
         try:
             appstruct = form.validate(controls)
         except deform.ValidationFailure, e:
             msg = _(u"ticket_validation_fail",
                     default = u"Ticket validation failed. Either the ticket doesn't exist, was already used or the url used improperly. "
                               u"If you need help, please contact the moderator that invited you to this meeting.")
             self.api.flash_messages.add(msg, type = 'error')
             url = self.request.resource_url(self.api.root)
             return HTTPFound(location = url)
         #Everything in order, claim ticket
         ticket = self.context.invite_tickets[appstruct['email']]
         ticket.claim(self.request)
         self.api.flash_messages.add(_(u"You've been granted access to the meeting. Welcome!"))
         url = self.request.resource_url(self.context)
         return HTTPFound(location=url)
开发者ID:tobsan,项目名称:voteit.core,代码行数:28,代码来源:ticket.py

示例9: get_vote_schema

    def get_vote_schema(self, request=None, api=None):
        """ Get an instance of the schema that this poll uses.
        """
        proposals = self.context.get_proposal_objects()
        
        #Choices should be something iterable with the contents [(UID for proposal, Title of proposal), <etc...>, ]
        choices = set()
        
        for prop in proposals:
            title = u"#%s - %s" % (prop.get_field_value('aid'), prop.title)
            choices.add((prop.uid, title))

        poll_wf_state = self.context.get_workflow_state()
        if poll_wf_state == 'ongoing':
            proposal_title = _(u"Vote for one")
        else:
            proposal_title = _(u"You can't change your vote now.")

        class Schema(colander.Schema):
            proposal = colander.SchemaNode(
                            colander.String(),
                            validator=colander.OneOf([x[0] for x in choices]),
                            widget=deform.widget.RadioChoiceWidget(values=choices),
                            title=proposal_title,
                            description=u'',)

        return Schema()
开发者ID:tobsan,项目名称:voteit.core,代码行数:27,代码来源:majority_poll.py

示例10: inline_add_proposal_form

def inline_add_proposal_form(context, request, va, **kw):
    """ For agenda item contexts.
    """
    api = kw['api']
    jquery_form.need() #This isn't included in widgets for some reason
    form = inline_add_form(api, 'Proposal', {})
    api.register_form_resources(form)
    if not api.context_has_permission(ADD_PROPOSAL, context):
        if context.get_workflow_state() == 'closed':
            msg = api.translate(_(u"no_propose_ai_closed",
                                  default = u"The agenda item is closed, you can't add a proposal here"))
        elif api.meeting.get_workflow_state() == 'closed':
            msg = api.translate(_(u"no_propose_meeting_closed",
                                  default = u"The meeting is closed, you can't add a proposal here"))
        else:
            msg = api.translate(_(u"no_propose_perm_notice",
                                  default = u"You don't have the required permission to add a proposal here"))
        return "<hr/>%s" % msg
    response = {}
    query = {'content_type': 'Proposal'}
    tag = request.GET.get('tag', None)
    if tag:
        query['tag'] = tag
    response['url'] = request.resource_url(context, '_inline_form', query = query)
    response['text'] = _(u'${username} propose', mapping={'username': api.userid})
    return render('../templates/snippets/inline_dummy_proposal_button.pt', response, request = request)
开发者ID:tobsan,项目名称:voteit.core,代码行数:26,代码来源:inline_add_form.py

示例11: render_result

    def render_result(self, view):
        votes = [x['uid']['proposal'] for x in self.context.poll_result]
        novotes = set(self.context.proposal_uids) - set(votes)
        translate = view.request.localizer.translate
        vote_singular = translate(_("vote_singular", default = "Vote"))
        vote_plural = translate(_("vote_plural", default = "Votes"))
        def _vote_text(count):
            return view.request.localizer.pluralize(vote_singular, vote_plural, count)

        results = []
        #Adjust result layout
        for res in tuple(self.context.poll_result):
            results.append({'uid': res['uid']['proposal'],
                            'count': res['count'],
                            'num': res['num'],
                            'perc': int(round(res['num'] * 100, 0))})
        for uid in novotes:
            results.append({'uid': uid, 'count': 0, 'num': 0, 'perc': 0})
        response = {}
        response['results'] = results
        #response['novotes'] = novotes
        response['vote_text'] = _vote_text
        response['total'] = sum([x[1] for x in self.context.ballots])
        proposals = {}
        for prop in self.context.get_proposal_objects():
            proposals[prop.uid] = prop
        response['proposals'] = proposals
        return render('templates/majority_poll.pt', response, request = view.request)
开发者ID:VoteIT,项目名称:voteit.core,代码行数:28,代码来源:majority_poll.py

示例12: __call__

 def __call__(self):
     tags = self.request.params.getall('tag')
     response = {'tags': tags}
     if tags:
         trans = self.request.localizer.translate
         filter_msg = """%s
         <a href="%s"
            data-load-agenda-item="#content"
            class="btn btn-default btn-xs"
            data-ai-name="%s"> %s </a>
        """ % (
             trans(_("Filter active, showing ${num} tag(s)", mapping={'num': len(tags)})),
             self.request.clear_tags_url(self.context),
             self.context.__name__,
             trans(_("Show all")),
         )
         filter_msg = filter_msg.replace('\n','')
         response['filter_msg'] = filter_msg
     # 200 is a default, but None removes the setting, hence this
     collapsible_limit = self.context.collapsible_limit
     if collapsible_limit is None:
         collapsible_limit = 200
     if collapsible_limit == 0:
         collapsible_limit = None
     response['collapsible_limit'] = collapsible_limit
     return response
开发者ID:VoteIT,项目名称:voteit.core,代码行数:26,代码来源:agenda_item.py

示例13: add_success

 def add_success(self, appstruct):
     emails = appstruct['emails'].splitlines()
     roles = appstruct['roles']
     added = 0
     rejected = 0
     for email in emails:
         result = self.context.add_invite_ticket(email, roles, sent_by = self.request.authenticated_userid)
         if result:
             added += 1
         else:
             rejected += 1
     if not rejected:
         msg = _('added_tickets_text', default = "Successfully added ${added} invites",
                 mapping={'added': added})
     elif not added:
         msg = _('no_tickets_added',
                 default = "No tickets added - all you specified probably exist already. "
                 "(Proccessed ${rejected})",
                 mapping = {'rejected': rejected})
         self.flash_messages.add(msg, type = 'warning', auto_destruct = False)
         url = self.request.resource_url(self.context, 'add_tickets')
         return HTTPFound(location = url)
     else:
         msg = _('added_tickets_text_some_rejected',
                 default = "Successfully added ${added} invites but discarded ${rejected} "
                 "since they already existed or were already used.",
                 mapping={'added': added, 'rejected': rejected})
     self.flash_messages.add(msg)
     self.request.session['send_tickets.emails'] = emails
     self.request.session['send_tickets.message'] = appstruct['message']
     url = self.request.resource_url(self.context, 'send_tickets')
     return HTTPFound(location = url)
开发者ID:VoteIT,项目名称:voteit.core,代码行数:32,代码来源:ticket.py

示例14: ticket_claim

 def ticket_claim(self):
     """ After login or registration, redirect back here, where information about the ticket will be displayed,
         and a confirmation that you want to use the ticket for the current user.
         
         While we use a regular deform form, it's not ment to be displayed or handle any validation.
     """
     if not self.request.authenticated_userid:
         raise HTTPForbidden("Direct access to this view for unauthorized users not allowed.")
     email = self.request.GET.get('email', '')
     ticket = self.context.invite_tickets.get(email, None)
     if ticket and ticket.closed != None:
         msg = _("This ticket has already been used.")
         self.flash_messages.add(msg, type = 'danger', auto_destruct = True, require_commit = False)
         return HTTPFound(location = self.request.resource_url(self.context))
     schema = get_content_schemas(self.request.registry)['Meeting']['claim_ticket']()
     schema = schema.bind(context = self.context, request = self.request, view = self)
     form = deform.Form(schema, buttons = (button_add, button_cancel,))
     if self.request.GET.get('claim'):
         controls = self.request.params.items()
         try:
             appstruct = form.validate(controls)
         except deform.ValidationFailure, e:
             msg = _("ticket_validation_fail",
                     default = "Ticket validation failed. Either the "
                     "ticket doesn't exist, was already used or the url used improperly. "
                     "If you need help, please contact the moderator that invited you to this meeting.")
             self.flash_messages.add(msg, type = 'danger', auto_destruct = False, require_commit = False)
             url = self.request.resource_url(self.root)
             return HTTPFound(location = url)
         #Everything in order, claim ticket
         ticket = self.context.invite_tickets[appstruct['email']]
         claim_ticket(ticket, self.request, self.request.authenticated_userid)
         self.flash_messages.add(_(u"You've been granted access to the meeting. Welcome!"))
         url = self.request.resource_url(self.context)
         return HTTPFound(location=url)
开发者ID:VoteIT,项目名称:voteit.core,代码行数:35,代码来源:ticket.py

示例15: add_success

 def add_success(self, appstruct):
     userid = appstruct['userid']
     roles = appstruct['roles']
     if roles and security.ROLE_VIEWER not in roles:
         roles.add(security.ROLE_VIEWER)
     old_roles = self.context.local_roles.get(userid, set())
     if old_roles:
         new_roles = roles - old_roles
         if new_roles:
             trans = self.request.localizer.translate
             role_titles = []
             for role_name in new_roles:
                 role = self.request.registry.roles.get(role_name)
                 role_titles.append(trans(role.title))
             msg = _("new_roles_appended_notice",
                     default = "User was already a part of this meeting, "
                     "but these new roles were added: ${roles}",
                     mapping = {'roles': ", ".join(role_titles)})
             self.flash_messages.add(msg, type = 'warning')
         else:
             self.flash_messages.add(_("No new roles added - user already had all of them."))
     else:
         #Userid wasn't registered in this meeting
         self.flash_messages.add(self.default_success, type = "success")
     self.context.local_roles.add(appstruct['userid'], roles)
     return HTTPFound(location = self.request.resource_url(self.context, 'add_userid'))
开发者ID:VoteIT,项目名称:voteit.core,代码行数:26,代码来源:permissions.py


注:本文中的voteit.core._函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。