Python django.shortcuts.HttpResponseRedirect() Examples
The following are 30
code examples of django.shortcuts.HttpResponseRedirect().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.shortcuts
, or try the search function
.
Example #1
Source File: product.py From adminset with GNU General Public License v2.0 | 6 votes |
def product_edit(request, product_id): product = Product.objects.get(id=product_id) if request.method == 'POST': form = ProductForm(request.POST, instance=product) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('product_list')) else: form = ProductForm(instance=product) results = { 'form': form, 'product_id': product_id, 'request': request, } return render(request, 'appconf/product_base.html', results)
Example #2
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #3
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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={}))
Example #4
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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)
Example #5
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #6
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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'))
Example #7
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #8
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #9
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #10
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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)
Example #11
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #12
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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}))
Example #13
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #14
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #15
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_config(request, config_slug): config = get_object_or_404(SessionalConfig, slug=config_slug, unit__in=request.units) if request.method == 'POST': form = SessionalConfigForm(request, request.POST, instance=config) if form.is_valid(): config = form.save(commit=False) config.save() messages.add_message(request, messages.SUCCESS, 'Configuration was edited.' ) l = LogEntry(userid=request.user.username, description="edited config: %s" % config, related_object=config ) l.save() return HttpResponseRedirect(reverse('sessionals:manage_configs')) else: form = SessionalConfigForm(request, instance=config) return render(request, 'sessionals/edit_config.html', {'form': form, 'config': config})
Example #16
Source File: resource.py From adminset with GNU General Public License v2.0 | 6 votes |
def resource_edit(request, resource_id): resource_obj = Resource.objects.get(id=resource_id) if request.method == 'POST': form = ResourceForm(request.POST, instance=resource_obj) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('resource_list')) else: form = ResourceForm(instance=resource_obj) results = { 'form': form, 'resource_id': resource_id, 'request': request, } return render(request, 'branches/resource_base.html', results)
Example #17
Source File: user.py From adminset with GNU General Public License v2.0 | 6 votes |
def login(request): if request.user.is_authenticated(): return HttpResponseRedirect('/') if request.method == 'GET' and request.GET.has_key('next'): next_page = request.GET['next'] else: next_page = '/' if next_page == "/accounts/logout/": next_page = '/' if request.method == "POST": form = LoginUserForm(request, data=request.POST) if form.is_valid(): auth.login(request, form.get_user()) return HttpResponseRedirect(request.POST['next']) else: form = LoginUserForm(request) kwargs = { 'request': request, 'form': form, 'next': next_page, } return render(request, 'accounts/login.html', kwargs)
Example #18
Source File: views.py From KortURL with MIT License | 6 votes |
def post(self, request): form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(username=username, password=password) if user is not None: login(request, user) response = HttpResponseRedirect(reverse("index")) if self.select_rem(request): return self.set_cookie(response, 'username', username) else: return response else: return render(request, 'login.html', {"error": {"username": ["用户名或密码错误"]}, "saved_username": self.saved_username(request)}) else: return render(request, 'login.html', {"error": form.errors, "saved_username": self.saved_username(request)})
Example #19
Source File: views.py From lmgtdfy with MIT License | 6 votes |
def form_valid(self, form): data = form.cleaned_data domain = data['domain_base'] domain_is_whitelisted = check_valid_tld(domain) if not domain_is_whitelisted: messages.info( self.request, "Sorry, but to limit the cost of running this service, we have not enabled searching this domain name (%s)." % domain ) return HttpResponseRedirect(resolve_url('home')) search_done = search_bing(domain) if not search_done: messages.info( self.request, "This domain has already been requested today! Here is what we've gathered." ) else: messages.info( self.request, "Gathering results now. They will be displayed shortly." ) return HttpResponseRedirect( resolve_url('domain_result', domain) )
Example #20
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_contract(request, contract_slug): contract = get_object_or_404(SessionalContract, slug=contract_slug, unit__in=request.units) if request.method == 'POST': form = SessionalContractForm(request, request.POST, instance=contract) if form.is_valid(): contract = form.save(commit=False) # Let's convert the person in there to an AnyPerson person = form.cleaned_data['person'] contract.sessional = AnyPerson.get_or_create_for(person=person) contract.save() messages.add_message(request, messages.SUCCESS, 'Contract was edited.' ) l = LogEntry(userid=request.user.username, description="edited sessional contract for: %s" % contract.sessional, related_object=contract ) l.save() return HttpResponseRedirect(reverse('sessionals:sessionals_index')) else: form = SessionalContractForm(request, instance=contract) form.fields['person'].initial = contract.sessional.get_person().emplid return render(request, 'sessionals/edit_contract.html', {'form': form, 'contract': contract})
Example #21
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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)
Example #22
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_account(request, account_slug): account = get_object_or_404(SessionalAccount, slug=account_slug, unit__in=request.units) if request.method == 'POST': form = SessionalAccountForm(request, request.POST, instance=account) if form.is_valid(): account = form.save(commit=False) account.save() messages.add_message(request, messages.SUCCESS, 'Account was edited.' ) l = LogEntry(userid=request.user.username, description="edited account: %s" % account, related_object=account ) l.save() return HttpResponseRedirect(reverse('sessionals:manage_accounts')) else: form = SessionalAccountForm(request, instance=account) return render(request, 'sessionals/edit_account.html', {'form': form, 'account': account})
Example #23
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def new_account(request): if request.method == 'POST': form = SessionalAccountForm(request, request.POST) if form.is_valid(): account = form.save(commit=False) account.save() messages.add_message(request, messages.SUCCESS, 'Account was created.' ) l = LogEntry(userid=request.user.username, description="added account: %s" % account, related_object=account ) l.save() return HttpResponseRedirect(reverse('sessionals:manage_accounts')) else: form = SessionalAccountForm(request) return render(request, 'sessionals/new_account.html', {'form': form})
Example #24
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def new_attachment(request, asset_id): asset = get_object_or_404(Asset, pk=asset_id, unit__in=request.units) editor = get_object_or_404(Person, userid=request.user.username) form = AssetAttachmentForm() context = {"asset": asset, "attachment_form": form} if request.method == "POST": form = AssetAttachmentForm(request.POST, request.FILES) if form.is_valid(): attachment = form.save(commit=False) attachment.asset = asset 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('inventory:view_asset', kwargs={'asset_slug': asset.slug})) else: context.update({"attachment_form": form}) return render(request, 'inventory/asset_document_attachment_form.html', context)
Example #25
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_asset(request, asset_slug): asset = get_object_or_404(Asset, slug=asset_slug, unit__in=request.units) if request.method == 'POST': form = AssetForm(request, request.POST, instance=asset) if form.is_valid(): asset = form.save() messages.add_message(request, messages.SUCCESS, 'Asset was modified') l = LogEntry(userid=request.user.username, description="Modified asset %s" % asset.name, related_object=asset) l.save() return HttpResponseRedirect(reverse('inventory:inventory_index')) else: if asset.user: user = asset.user.emplid else: user = None form = AssetForm(request, instance=asset, initial={'user': user}) return render(request, 'inventory/edit_asset.html', {'form': form, 'asset_slug': asset_slug})
Example #26
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #27
Source File: views.py From srvup-rest-framework with Apache License 2.0 | 5 votes |
def auth_login(request): form = LoginForm(request.POST or None) next_url = request.GET.get('next') if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] print username, password user = authenticate(username=username, password=password) if user is not None: login(request, user) if next_url is not None: return HttpResponseRedirect(next_url) return HttpResponseRedirect("/") action_url = reverse("login") title = "Login" submit_btn = title submit_btn_class = "btn-success btn-block" extra_form_link = "Upgrade your account today <a href='%s'>here</a>!" %(reverse("account_upgrade")) context = { "form": form, "action_url": action_url, "title": title, "submit_btn": submit_btn, "submit_btn_class": submit_btn_class, "extra_form_link":extra_form_link } return render(request, "accounts/account_login_register.html", context)
Example #28
Source File: views.py From SecurityManageFramwork-SeMF with GNU General Public License v3.0 | 5 votes |
def notice_read(request,notice_id): user = request.user notice = get_object_or_404(models.Notice,notice_user =user ,id =notice_id) notice.notice_status = True notice.save() return HttpResponseRedirect(notice.notice_url)
Example #29
Source File: views.py From srvup-rest-framework with Apache License 2.0 | 5 votes |
def video_detail(request, cat_slug, vid_slug): cat = get_object_or_404(Category, slug=cat_slug) obj = get_object_or_404(Video, slug=vid_slug, category=cat) page_view.send(request.user, page_path=request.get_full_path(), primary_obj=obj, secondary_obj=cat) if request.user.is_authenticated() or obj.has_preview: try: is_member = request.user.is_member except: is_member = None if is_member or obj.has_preview: comments = obj.comment_set.all() for c in comments: c.get_children() comment_form = CommentForm() context = {"obj": obj, "comments":comments, "comment_form": comment_form} return render(request, "videos/video_detail.html", context) else: # upgrade account next_url = obj.get_absolute_url() return HttpResponseRedirect("%s?next=%s"%(reverse('account_upgrade'), next_url)) else: next_url = obj.get_absolute_url() return HttpResponseRedirect("%s?next=%s"%(reverse('login'), next_url))
Example #30
Source File: views.py From SecurityManageFramwork-SeMF with GNU General Public License v3.0 | 5 votes |
def logout(request): auth.logout(request) request.session.clear() return HttpResponseRedirect('/view/')