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


Python shortcuts.HttpResponseRedirect方法代码示例

本文整理汇总了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) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:25,代码来源:views.py

示例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) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:26,代码来源:views.py

示例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={})) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:views.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:views.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:views.py

示例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')) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:20,代码来源:views.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:26,代码来源:views.py

示例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) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:27,代码来源:views.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:views.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:views.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:views.py

示例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})) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:views.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:views.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:views.py

示例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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:views.py


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