本文整理汇总了Python中morepath.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
示例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'))
示例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))
示例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")
}
示例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))
示例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'
}
示例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
}
示例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)
]
}
示例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
}
示例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
}
示例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,
}
示例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'])
示例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
}
示例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())))
示例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
}