本文整理汇总了Python中morepath.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: publish_event
def publish_event(self, request):
""" Publish an event. """
self.publish()
request.success(_("You have accepted the event ${title}", mapping={
'title': self.title
}))
if self.meta.get('submitter_email'):
session = request.app.session()
ticket = TicketCollection(session).by_handler_id(self.id.hex)
send_html_mail(
request=request,
template='mail_event_accepted.pt',
subject=_("Your event was accepted"),
receivers=(self.meta.get('submitter_email'), ),
content={
'model': self,
'ticket': ticket
}
)
if 'return-to' in request.GET:
return morepath.redirect(request.GET['return-to'])
return morepath.redirect(request.link(self))
开发者ID:i18nHub,项目名称:onegov.town,代码行数:29,代码来源:event.py
示例2: view_upload_election
def view_upload_election(self, request):
""" Upload results of an election.
Redirects to the majorz or proporz upload view.
"""
if self.type == 'majorz':
return morepath.redirect(request.link(self, 'upload-majorz'))
return morepath.redirect(request.link(self, 'upload-proporz'))
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:10,代码来源:election.py
示例3: view_latest_event
def view_latest_event(self, request):
""" Redirects to the latest occurrence of an event that is, either the
next future event or the last event in the past if there are no more
future events.
"""
now = utcnow()
for occurrence in self.occurrences:
if now < occurrence.start:
return morepath.redirect(request.link(occurrence))
return morepath.redirect(request.link(occurrence))
开发者ID:i18nHub,项目名称:onegov.town,代码行数:14,代码来源:event.py
示例4: handle_edit_reservation
def handle_edit_reservation(self, request, form):
# this view is public, but only for a limited time
assert_anonymous_access_only_temporary(self, request)
collection = ResourceCollection(request.app.libres_context)
resource = collection.by_id(self.resource)
if form.submitted(request):
scheduler = resource.get_scheduler(request.app.libres_context)
try:
if self.email != form.email.data:
scheduler.change_email(self.token, form.email.data)
start, end = form.get_date_range()
scheduler.change_reservation(
self.token, self.id, start, end, quota=form.data.get('quota')
)
except LibresError as e:
utils.show_libres_error(e, request)
else:
forms = FormCollection(request.app.session())
submission = forms.submissions.by_id(self.token)
confirm_link = request.link(self, 'bestaetigung')
if submission is None:
return morepath.redirect(confirm_link)
else:
return morepath.redirect(
get_submission_link(request, submission, confirm_link)
)
form.apply_model(self)
layout = ReservationLayout(resource, request)
layout.breadcrumbs.append(Link(_("Edit Reservation"), '#'))
title = _("Change reservation for ${title}", mapping={
'title': resource.title,
})
return {
'layout': layout,
'title': title,
'form': form,
'allocation': self,
'button_text': _("Continue")
}
开发者ID:i18nHub,项目名称:onegov.town,代码行数:48,代码来源:reservation.py
示例5: reopen_ticket
def reopen_ticket(self, request):
user = UserCollection(request.app.session()).by_username(
request.identity.userid)
try:
self.reopen_ticket(user)
except InvalidStateChange:
request.alert(
_("The ticket cannot be re-opened because it's not closed.")
)
else:
request.success(_("You have reopened ticket ${number}", mapping={
'number': self.number
}))
email = self.snapshot.get('email') or self.handler.email
send_html_mail(
request=request,
template='mail_ticket_reopened.pt',
subject=_("Your ticket has been reopened"),
receivers=(email, ),
content={
'model': self
}
)
request.app.update_ticket_count()
return morepath.redirect(request.link(self))
开发者ID:i18nHub,项目名称:onegov.town,代码行数:30,代码来源:ticket.py
示例6: handle_new_page
def handle_new_page(self, request, form, src=None):
if form.submitted(request):
pages = PageCollection(request.app.session())
page = pages.add(
parent=self.page,
title=form.title.data,
type=self.page.type,
meta={'trait': self.trait}
)
form.update_model(page)
request.app.update_homepage_pages()
request.success(page.trait_messages[page.trait]['new_page_added'])
return morepath.redirect(request.link(page))
if src:
form.apply_model(src)
site_title = self.page.trait_messages[self.trait]['new_page_title']
return {
'layout': EditorLayout(self, request, site_title),
'title': site_title,
'form': form,
'form_width': 'large'
}
开发者ID:i18nHub,项目名称:onegov.town,代码行数:27,代码来源:editor.py
示例7: clear_election_compound
def clear_election_compound(self, request, form):
""" Clear the results of an election ompound. """
layout = ManageElectionCompoundsLayout(self, request)
archive = ArchivedResultCollection(request.session)
if form.submitted(request):
archive.clear(self, request)
request.message(_("Results deleted."), 'success')
return redirect(layout.manage_model_link)
return {
'message': _(
'Do you really want to clear all party results of "${item}"?',
mapping={
'item': self.title
}
),
'layout': layout,
'form': form,
'title': self.title,
'shortcode': self.shortcode,
'subtitle': _("Clear results"),
'button_text': _("Clear results"),
'button_class': 'alert',
'cancel': layout.manage_model_link
}
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:27,代码来源:election_compounds.py
示例8: view_topic
def view_topic(self, request):
assert self.trait in {'link', 'page'}
if not request.is_logged_in and self.trait == 'link':
return morepath.redirect(self.content['url'])
layout = PageLayout(self, request)
if request.is_logged_in:
layout.editbar_links = self.get_editbar_links(request)
children = self.children
else:
children = request.exclude_invisible(self.children)
return {
'layout': layout,
'title': self.title,
'name': self.trait_messages[self.trait]['name'],
'page': self,
'children': [
Link(child.title, request.link(child), model=child)
for child in sorted(children, key=lambda c: c.name)
]
}
开发者ID:Gitlab11,项目名称:onegov.town,代码行数:25,代码来源:page.py
示例9: delete_subscriber
def delete_subscriber(self, request, form):
""" Delete a single subsriber. """
layout = ManageSubscribersLayout(self, request)
if form.submitted(request):
subscribers = SubscriberCollection(request.session)
subscribers.unsubscribe(self.address)
request.message(_("Subscriber deleted."), 'success')
return redirect(layout.manage_model_link)
return {
'message': _(
'Do you really want to delete "${item}"?',
mapping={
'item': self.address
}
),
'layout': layout,
'form': form,
'title': self.address,
'subtitle': _("Delete subscriber"),
'button_text': _("Delete subscriber"),
'button_class': 'alert',
'cancel': layout.manage_model_link
}
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:27,代码来源:subscribers.py
示例10: handle_defined_form
def handle_defined_form(self, request, form):
""" Renders the empty form and takes input, even if it's not valid, stores
it as a pending submission and redirects the user to the view that handles
pending submissions.
"""
collection = FormCollection(request.app.session())
if request.POST:
submission = collection.submissions.add(
self.name, form, state='pending')
return morepath.redirect(request.link(submission))
return {
'layout': FormSubmissionLayout(self, request),
'title': self.title,
'form': form,
'definition': self,
'form_width': 'small',
'lead': self.meta.get('lead'),
'text': self.content.get('text'),
'people': self.people,
'contact': self.contact_html
}
开发者ID:Gitlab11,项目名称:onegov.town,代码行数:26,代码来源:form_submission.py
示例11: search
def search(self, request):
layout = DefaultLayout(self, request)
layout.breadcrumbs.append(Link(_("Search"), "#"))
try:
request.app.es_client.ping()
except TransportError:
log.warn("Elasticsearch cluster is offline")
return {"title": _("Search Unavailable"), "layout": layout, "connection": False}
if "lucky" in request.GET:
url = self.feeling_lucky()
if url:
return morepath.redirect(url)
return {
"title": _("Search"),
"model": self,
"layout": layout,
"hide_search_header": True,
"searchlabel": _("Search through ${count} indexed documents", mapping={"count": self.available_documents}),
"resultslabel": _("${count} Results", mapping={"count": self.subset_count}),
"connection": True,
}
开发者ID:i18nHub,项目名称:onegov.town,代码行数:26,代码来源:search.py
示例12: accept_reservation
def accept_reservation(self, request):
if not self.data or not self.data.get('accepted'):
collection = ResourceCollection(request.app.libres_context)
resource = collection.by_id(self.resource)
scheduler = resource.get_scheduler(request.app.libres_context)
reservations = scheduler.reservations_by_token(self.token)
send_html_mail(
request=request,
template='mail_reservation_accepted.pt',
subject=_("Your reservation was accepted"),
receivers=(self.email, ),
content={
'model': self,
'resource': resource,
'reservations': reservations
}
)
for reservation in reservations:
reservation.data = reservation.data or {}
reservation.data['accepted'] = True
# libres does not automatically detect changes yet
flag_modified(reservation, 'data')
request.success(_("The reservation was accepted"))
else:
request.warning(_("The reservation has already been accepted"))
return morepath.redirect(request.params['return-to'])
开发者ID:i18nHub,项目名称:onegov.town,代码行数:31,代码来源:reservation.py
示例13: delete_data_source_item
def delete_data_source_item(self, request, form):
""" Delete the data source item. """
layout = ManageDataSourceItemsLayout(self.source, request)
if form.submitted(request):
data_source_items = DataSourceItemCollection(request.session)
data_source_items.delete(self)
request.message(_("Mapping deleted."), 'success')
return morepath.redirect(layout.manage_model_link)
return {
'message': _(
'Do you really want to delete "${item}"?',
mapping={
'item': self.name
}
),
'layout': layout,
'form': form,
'title': self.name,
'subtitle': _("Delete mapping"),
'button_text': _("Delete mapping"),
'button_class': 'alert',
'cancel': layout.manage_model_link
}
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:27,代码来源:data_sources.py
示例14: close_ticket
def close_ticket(self, request):
try:
self.close_ticket()
except InvalidStateChange:
request.alert(
_("The ticket cannot be closed because it's not pending")
)
else:
request.success(_("You have closed ticket ${number}", mapping={
'number': self.number
}))
email = self.snapshot.get('email') or self.handler.email
send_html_mail(
request=request,
template='mail_ticket_closed.pt',
subject=_("Your ticket has been closed"),
receivers=(email, ),
content={
'model': self
}
)
request.app.update_ticket_count()
return morepath.redirect(
request.link(TicketCollection(request.app.session())))
开发者ID:i18nHub,项目名称:onegov.town,代码行数:29,代码来源:ticket.py
示例15: edit_election
def edit_election(self, request, form):
""" Edit an existing election. """
layout = ManageElectionsLayout(self, request)
archive = ArchivedResultCollection(request.session)
form.set_domain(request.app.principal)
if form.submitted(request):
form.update_model(self)
archive.update(self, request)
request.message(_("Election modified."), 'success')
return redirect(layout.manage_model_link)
if not form.errors:
form.apply_model(self)
return {
'layout': layout,
'form': form,
'title': self.title,
'shortcode': self.shortcode,
'subtitle': _("Edit election"),
'cancel': layout.manage_model_link
}
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:25,代码来源:elections.py
示例16: handle_password_reset_request
def handle_password_reset_request(self, request, form):
""" Handles the GET and POST password reset requests. """
if form.submitted(request):
user, token = form.get_token(request)
if user is not None and token is not None:
url = "{0}?token={1}".format(request.link(self, name="reset-password"), token)
send_html_mail(
request=request,
template="mail_password_reset.pt",
subject=_("Password reset"),
receivers=(user.username,),
content={"model": None, "url": url},
)
else:
log.info("Failed password reset attempt by {}".format(request.client_addr))
response = morepath.redirect(request.link(self))
request.success(
_(
(
u"A password reset link has been sent to ${email}, provided an "
u"account exists for this email address."
),
mapping={"email": form.email.data},
)
)
return response
layout = DefaultLayout(self, request)
layout.breadcrumbs = [
Link(_("Homepage"), layout.homepage_url),
Link(_("Reset password"), request.link(self, name="request-password")),
]
return {"layout": layout, "title": _(u"Reset password"), "form": form, "form_width": "small"}
开发者ID:Gitlab11,项目名称:onegov.town,代码行数:35,代码来源:reset_password.py
示例17: handle_password_reset
def handle_password_reset(self, request, form):
request.include("common")
request.include("check_password")
if form.submitted(request):
identity = form.get_identity(request)
if identity is not None:
response = morepath.redirect(request.link(self))
morepath.remember_identity(response, request, identity)
request.success(_("Password changed."))
return response
else:
request.alert(_("Wrong username or password reset link not valid any more."))
log.info("Failed password reset attempt by {}".format(request.client_addr))
if "token" in request.params:
form.token.data = request.params["token"]
layout = DefaultLayout(self, request)
layout.breadcrumbs = [
Link(_("Homepage"), layout.homepage_url),
Link(_("Reset password"), request.link(self, name="request-password")),
]
return {"layout": layout, "title": _(u"Reset password"), "form": form, "form_width": "small"}
开发者ID:Gitlab11,项目名称:onegov.town,代码行数:25,代码来源:reset_password.py
示例18: delete_upload_token
def delete_upload_token(self, request, form):
""" Delete the upload token item. """
layout = ManageUploadTokensLayout(self, request)
if form.submitted(request):
upload_tokens = UploadTokenCollection(request.session)
upload_tokens.delete(self)
request.message(_("Upload token deleted."), 'success')
return morepath.redirect(layout.manage_model_link)
return {
'message': _(
'Do you really want to delete "${item}"?',
mapping={'item': self.token}
),
'layout': layout,
'form': form,
'title': self.token,
'subtitle': _("Delete upload token"),
'button_text': _("Delete upload token"),
'button_class': 'alert',
'cancel': layout.manage_model_link
}
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:25,代码来源:upload_tokens.py
示例19: reject_reservation
def reject_reservation(self, request):
collection = ResourceCollection(request.app.libres_context)
resource = collection.by_id(self.resource)
scheduler = resource.get_scheduler(request.app.libres_context)
reservations = scheduler.reservations_by_token(self.token.hex)
forms = FormCollection(request.app.session())
submission = forms.submissions.by_id(self.token.hex)
send_html_mail(
request=request,
template='mail_reservation_rejected.pt',
subject=_("Your reservation was rejected"),
receivers=(self.email, ),
content={
'model': self,
'resource': resource,
'reservations': reservations
}
)
# create a snapshot of the ticket to keep the useful information
tickets = TicketCollection(request.app.session())
ticket = tickets.by_handler_id(self.token.hex)
ticket.create_snapshot(request)
scheduler.remove_reservation(self.token.hex)
if submission:
forms.submissions.delete(submission)
request.success(_("The reservation was rejected"))
# return none on intercooler js requests
if not request.headers.get('X-IC-Request'):
return morepath.redirect(request.params['return-to'])
开发者ID:i18nHub,项目名称:onegov.town,代码行数:35,代码来源:reservation.py
示例20: delete_election_compound
def delete_election_compound(self, request, form):
""" Delete an existing election compound. """
layout = ManageElectionCompoundsLayout(self, request)
archive = ArchivedResultCollection(request.session)
if form.submitted(request):
archive.delete(self, request)
request.message(_("Compound deleted."), 'success')
return redirect(layout.manage_model_link)
return {
'message': _(
'Do you really want to delete "${item}"?',
mapping={
'item': self.title
}
),
'layout': layout,
'form': form,
'title': self.title,
'shortcode': self.shortcode,
'subtitle': _("Delete compound"),
'button_text': _("Delete compound"),
'button_class': 'alert',
'cancel': layout.manage_model_link
}
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:28,代码来源:election_compounds.py
注:本文中的morepath.redirect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论