本文整理汇总了Python中voteit.core._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: bootstrap_voteit
def bootstrap_voteit(echo=True):
""" Bootstrap site root.
Will add:
- Site root
- Agenda template folder
- Users folder
- An administrative user with login: admin and pass: admin
"""
if echo:
print "Bootstrapping site - creating 'admin' user with password 'admin'"
#Add root
root = createContent('Root', title = _(u"VoteIT"), creators = ['admin'])
root.set_field_value('footer', u'<a href="http://www.voteit.se">www.voteit.se</a> — '
u'<a href="http://manual.voteit.se">User and developer manual</a> — '
u'<a href="https://github.com/VoteIT">Source code and bugtracker</a>')
#Add templates if available
try:
root['agenda_templates'] = createContent('AgendaTemplates',
title = _(u"Agenda templates"),
creators = ['admin'])
except KeyError:
pass #For tests etc
#Add users folder
root['users'] = createContent('Users', title = _(u"Registered users"), creators = ['admin'])
users = root.users
#Add user admin - note that creators also set owner, which is important for changing password
admin = createContent('User',
password = 'admin',
creators = ['admin'],
first_name = _(u'VoteIT'),
last_name = _(u'Administrator'))
users['admin'] = admin
#Add admin to group managers
root.add_groups('admin', [ROLE_ADMIN])
return root
开发者ID:VoteIT,项目名称:voteit.core,代码行数:35,代码来源:bootstrap.py
示例17: request_password
def request_password(self):
schema = createSchema('RequestNewPasswordSchema').bind(context=self.context, request=self.request)
form = Form(schema, buttons=(button_request, button_cancel))
self.api.register_form_resources(form)
#Handle submitted information
if 'request' in self.request.POST:
controls = self.request.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_or_email = appstruct['userid_or_email']
#userid here can be either an email address or a login name
if '@' in userid_or_email:
#assume email
user = self.context['users'].get_user_by_email(userid_or_email)
else:
user = self.context['users'].get(userid_or_email)
if IUser.providedBy(user):
user.new_request_password_token(self.request)
self.api.flash_messages.add(_('Email sent.'))
url = resource_url(self.api.root, self.request)
return HTTPFound(location = url)
self.api.flash_messages.add(_('Username or email not found.'), type='error')
开发者ID:tobsan,项目名称:voteit.core,代码行数:32,代码来源:users.py
示例18: recaptcha_node
def recaptcha_node():
return colander.SchemaNode(colander.String(),
#FIXME: write a good title and description here
title=_(u"Verify you are human"),
description = _(u"meeting_captcha_description",
default=u"This is to prevent spambots from creating meetings"),
missing=u"",
widget=deferred_recaptcha_widget,)
开发者ID:tobsan,项目名称:voteit.core,代码行数:8,代码来源:meeting.py
示例19: schema
def schema(self):
#Just to make sure
self.hashlist
return colander.Schema(
title=_("Would you like to participate?"),
description=_(
"Clicking request access will grant you access if your email address "
"is allowed by the access policy."
)
)
开发者ID:VoteIT,项目名称:voteit.core,代码行数:10,代码来源:hashlist_ap.py
示例20: public_description_node
def public_description_node():
return colander.SchemaNode(
colander.String(),
title = _(u"Public presentation"),
description = _(u"meeting_public_description_description",
default=u"The public description is visible on the request access "
u"page and to not yet logged in visitors."),
missing = u"",
widget=deform.widget.RichTextWidget(),
validator=richtext_validator,)
开发者ID:tobsan,项目名称:voteit.core,代码行数:10,代码来源:meeting.py
注:本文中的voteit.core._函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论