本文整理匯總了Python中django.shortcuts.HttpResponseRedirect方法的典型用法代碼示例。如果您正苦於以下問題:Python shortcuts.HttpResponseRedirect方法的具體用法?Python shortcuts.HttpResponseRedirect怎麽用?Python shortcuts.HttpResponseRedirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.shortcuts
的用法示例。
在下文中一共展示了shortcuts.HttpResponseRedirect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def create(request):
person = get_person(request.user)
if request.method == 'POST':
form = ReminderForm(data=request.POST, person=person)
if form.is_valid():
reminder = form.save(commit=False)
reminder.person = person
reminder.save()
l = LogEntry(userid=request.user.username,
description="created reminder %s" % (reminder.slug,),
related_object=reminder
)
l.save()
messages.add_message(request, messages.SUCCESS, 'Reminder created.')
return HttpResponseRedirect(reverse('reminders:view', kwargs={'reminder_slug': reminder.slug}))
else:
form = ReminderForm(person=person)
context = {
'form': form,
}
return render(request, 'reminders/create.html', context)
示例2: edit
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def edit(request, reminder_slug):
reminder, person = _get_reminder_or_404(request, reminder_slug)
if request.method == 'POST':
form = ReminderForm(instance=reminder, data=request.POST, person=person)
if form.is_valid():
reminder = form.save(commit=False)
reminder.person = person
reminder.save()
l = LogEntry(userid=request.user.username,
description="edited reminder %s" % (reminder.slug,),
related_object=reminder
)
l.save()
messages.add_message(request, messages.SUCCESS, 'Reminder updated.')
return HttpResponseRedirect(reverse('reminders:view', kwargs={'reminder_slug': reminder.slug}))
else:
form = ReminderForm(instance=reminder, person=person)
context = {
'form': form,
'reminder': reminder,
}
return render(request, 'reminders/edit.html', context)
示例3: delete
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def delete(request, reminder_slug):
if request.method != 'POST':
return HttpError(request, status=405, title="Method not allowed", error="This URL accepts only POST requests", errormsg=None)
reminder, person = _get_reminder_or_404(request, reminder_slug)
reminder.person = person
reminder.status = 'D'
reminder.save()
l = LogEntry(userid=request.user.username,
description="deleted reminder %s" % (reminder.slug,),
related_object=reminder
)
l.save()
messages.add_message(request, messages.SUCCESS, 'Reminder deleted.')
return HttpResponseRedirect(reverse('reminders:index', kwargs={}))
示例4: new_event
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def new_event(request):
if request.method == 'POST':
form = OutreachEventForm(request, request.POST)
if form.is_valid():
event = form.save()
messages.add_message(request,
messages.SUCCESS,
'Event was created')
l = LogEntry(userid=request.user.username,
description="Added event %s" % event,
related_object=event)
l.save()
return HttpResponseRedirect(reverse('outreach:outreach_index'))
else:
form = OutreachEventForm(request)
return render(request, 'outreach/new_event.html', {'form': form})
示例5: edit_event
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def edit_event(request, event_slug):
event = get_object_or_404(OutreachEvent, slug=event_slug, unit__in=request.units)
if request.method == 'POST':
form = OutreachEventForm(request, request.POST, instance=event)
if form.is_valid():
event = form.save()
messages.add_message(request,
messages.SUCCESS,
'Event was saved')
l = LogEntry(userid=request.user.username,
description="Edited event %s" % event,
related_object=event)
l.save()
return HttpResponseRedirect(reverse('outreach:outreach_index'))
else:
form = OutreachEventForm(request, instance=event)
return render(request, 'outreach/edit_event.html', {'form': form, 'event_slug': event.slug})
示例6: toggle_registration_waitlist
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def toggle_registration_waitlist(request, registration_id, event_slug=None):
registration = get_object_or_404(OutreachEventRegistration, pk=registration_id, event__unit__in=request.units)
if request.method == 'POST':
registration.waitlisted = not registration.waitlisted
# since we just manually toggled the waitlist status, it just makes sense that the attendance status should be
# the opposite of the waitlist status. If you're forcing someone off the waitlist, they should be attending,
# and vice-versa.
registration.attended = not registration.waitlisted
registration.save()
messages.success(request, 'Toggle waitlist status for %s. Please note that the attendance status may have '
'have also been changed accordingly.' % registration)
l = LogEntry(userid=request.user.username,
description="Toggled waitlist status for registration: %s" % registration,
related_object=registration)
l.save()
if event_slug:
return HttpResponseRedirect(reverse('outreach:view_event_registrations', kwargs={'event_slug': event_slug}))
return HttpResponseRedirect(reverse('outreach:view_all_registrations'))
示例7: edit_visa
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def edit_visa(request, visa_id):
visa = get_object_or_404(Visa, pk=visa_id)
if request.method == 'POST':
form = VisaForm(request, request.POST, instance=visa)
if form.is_valid():
visa = form.save(commit=False)
visa.save()
messages.add_message(request,
messages.SUCCESS,
'Visa was successfully modified.'
)
l = LogEntry(userid=request.user.username,
description="edited visa: %s" % (visa),
related_object=visa.person
)
l.save()
return HttpResponseRedirect(reverse('visas:list_all_visas'))
else:
# The initial value needs to be the person's emplid in the form.
# Django defaults to the pk, which is not human readable.
form = VisaForm(request, instance=visa, initial={'person': visa.person.emplid})
return render(request, 'visas/edit_visa.html', {'form': form, 'visa_id': visa_id})
示例8: new_attachment
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def new_attachment(request, visa_id):
visa = get_object_or_404(Visa, pk=visa_id)
editor = get_object_or_404(Person, userid=request.user.username)
form = VisaAttachmentForm()
context = {"visa": visa,
"attachment_form": form}
if request.method == "POST":
form = VisaAttachmentForm(request.POST, request.FILES)
if form.is_valid():
attachment = form.save(commit=False)
attachment.visa = visa
attachment.created_by = editor
upfile = request.FILES['contents']
filetype = upfile.content_type
if upfile.charset:
filetype += "; charset=" + upfile.charset
attachment.mediatype = filetype
attachment.save()
return HttpResponseRedirect(reverse('visas:view_visa', kwargs={'visa_id':visa.id}))
else:
context.update({"attachment_form": form})
return render(request, 'visas/visa_document_attachment_form.html', context)
示例9: add_location
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def add_location(request):
if request.method == 'POST':
form = LocationForm(request, request.POST)
if form.is_valid():
location = form.save()
messages.add_message(request,
messages.SUCCESS,
'Location was created')
l = LogEntry(userid=request.user.username,
description="Added location %s" % location,
related_object=location)
l.save()
return HttpResponseRedirect(reverse('space:index'))
else:
form = LocationForm(request)
return render(request, 'space/new_location.html', {'form': form})
示例10: add_roomtype
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def add_roomtype(request):
if request.method == 'POST':
form = RoomTypeForm(request, request.POST)
if form.is_valid():
roomtype = form.save()
messages.add_message(request,
messages.SUCCESS,
'Room type was created')
l = LogEntry(userid=request.user.username,
description="Added roomtype %s" % roomtype,
related_object=roomtype)
l.save()
return HttpResponseRedirect(reverse('space:list_roomtypes'))
else:
form = RoomTypeForm(request)
return render(request, 'space/new_roomtype.html', {'form': form})
示例11: edit_roomtype
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def edit_roomtype(request, roomtype_slug):
roomtype = get_object_or_404(RoomType, slug=roomtype_slug, unit__in=Unit.sub_units(request.units))
if request.method == 'POST':
form = RoomTypeForm(request, request.POST, instance=roomtype)
if form.is_valid():
roomtype = form.save()
messages.add_message(request,
messages.SUCCESS,
'Room type was edited')
l = LogEntry(userid=request.user.username,
description="Edited roomtype %s" % roomtype,
related_object=roomtype)
l.save()
return HttpResponseRedirect(reverse('space:list_roomtypes'))
else:
form = RoomTypeForm(request, instance=roomtype)
return render(request, 'space/edit_roomtype.html', {'form': form, 'roomtype': roomtype})
示例12: send_memo
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def send_memo(request, booking_slug, from_index=0):
booking = get_object_or_404(BookingRecord, slug=booking_slug, location__unit__in=Unit.sub_units(request.units))
editor = get_object_or_404(Person, userid=request.user.username)
if request.method == 'POST':
booking_memo = BookingMemo(booking_record=booking, created_by=editor)
booking_memo.email_memo()
booking_memo.save()
messages.add_message(request,
messages.SUCCESS,
'Memo was sent')
l = LogEntry(userid=request.user.username,
description="Send memo to %s" % booking.person,
related_object=booking_memo)
l.save()
if from_index == '1':
return HttpResponseRedirect(reverse('space:view_location', kwargs={'location_slug': booking.location.slug}))
return HttpResponseRedirect(reverse('space:view_booking', kwargs={'booking_slug': booking.slug}))
示例13: add_room_safety_item
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def add_room_safety_item(request):
if request.method == 'POST':
form = RoomSafetyItemForm(request, request.POST)
if form.is_valid():
item = form.save()
messages.add_message(request,
messages.SUCCESS,
'Safety item was created')
l = LogEntry(userid=request.user.username,
description="Added safety item %s" % item,
related_object=item)
l.save()
return HttpResponseRedirect(reverse('space:manage_safety_items'))
else:
form = RoomSafetyItemForm(request)
return render(request, 'space/add_safety_item.html', {'form': form})
示例14: edit_room_safety_item
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def edit_room_safety_item(request, safety_item_slug):
safety_item = get_object_or_404(RoomSafetyItem, unit__in=Unit.sub_units(request.units), slug=safety_item_slug)
if request.method == 'POST':
form = RoomSafetyItemForm(request, request.POST, instance=safety_item)
if form.is_valid():
item = form.save()
messages.add_message(request,
messages.SUCCESS,
'Safety item was saved')
l = LogEntry(userid=request.user.username,
description="Edited safety item %s" % item,
related_object=item)
l.save()
return HttpResponseRedirect(reverse('space:manage_safety_items'))
else:
form = RoomSafetyItemForm(request, instance=safety_item)
return render(request, 'space/edit_safety_item.html', {'form': form, 'safety_item_slug': safety_item_slug})
示例15: edit_contact
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import HttpResponseRedirect [as 別名]
def edit_contact(request, contact_slug):
contact = get_object_or_404(Contact, slug=contact_slug, unit__in=request.units)
if request.method == 'POST':
form = ContactForm(request, request.POST, instance=contact)
if form.is_valid():
contact = form.save()
messages.add_message(request,
messages.SUCCESS,
'Contact was edited')
l = LogEntry(userid=request.user.username,
description="Edited contact %s" % contact,
related_object=contact)
l.save()
return HttpResponseRedirect(reverse('relationships:index'))
else:
form = ContactForm(request, instance=contact)
return render(request, 'relationships/edit_contact.html', {'form': form, 'contact': contact})