Python django.shortcuts.HttpResponseRedirect() Examples

The following are 30 code examples for showing how to use django.shortcuts.HttpResponseRedirect(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.shortcuts , or try the search function .

Example 1
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 2
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 3
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 5
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 6
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 8
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 9
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 10
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 11
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 15
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 16
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 17
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 18
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 19
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 20
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 21
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 22
Project: lmgtdfy   Author: opendata   File: views.py    License: MIT License 6 votes vote down vote up
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 23
Project: KortURL   Author: yandenghong   File: views.py    License: MIT License 6 votes vote down vote up
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 24
Project: adminset   Author: guohongze   File: user.py    License: GNU General Public License v2.0 6 votes vote down vote up
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 25
Project: adminset   Author: guohongze   File: resource.py    License: GNU General Public License v2.0 6 votes vote down vote up
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 26
Project: adminset   Author: guohongze   File: product.py    License: GNU General Public License v2.0 6 votes vote down vote up
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 27
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 5 votes vote down vote up
def register(request, event_slug):
    """
    CAREFUL, this view is open to the whole world.
    """
    event = get_object_or_404(OutreachEvent, slug=event_slug)
    if request.method == 'POST':
        form = OutreachEventRegistrationForm(request.POST)
        form.add_extra_questions(event)
        form.check_dietary_field(event)
        if form.is_valid():
            registration = form.save(commit=False)
            registration.event = event
            if 'extra_questions' in registration.event.config and len(registration.event.config['extra_questions']) > 0:
                temp = {}
                for question in registration.event.config['extra_questions']:
                    temp[question] = form.cleaned_data[question]
                registration.config['extra_questions'] = temp
            if event.registrations_waitlisted():
                registration.waitlisted = True
                registration.attended = False
            registration.save()
            registration.email_memo()
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'Successfully registered')
            l = LogEntry(userid='',
                         description="Registered %s for event %s" % (registration.fullname(), registration.event.title),
                         related_object=registration
                         )
            l.save()
            if registration.waitlisted:
                return HttpResponseRedirect(reverse('outreach:register_waitlisted', kwargs={'event_slug': event_slug}))
            else:
                return HttpResponseRedirect(reverse('outreach:register_success', kwargs={'event_slug': event_slug}))
    else:
        form = OutreachEventRegistrationForm()
        form.add_extra_questions(event)
        form.check_dietary_field(event)
    return render(request, 'outreach/register.html', {'form': form, 'event': event}) 
Example 28
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 5 votes vote down vote up
def edit_registration(request, registration_id, event_slug=None):
    registration = get_object_or_404(OutreachEventRegistration, pk=registration_id, event__unit__in=request.units)
    if request.method == 'POST':
        form = OutreachEventRegistrationForm(request.POST, instance=registration)
        form.add_extra_questions(registration.event)
        form.check_dietary_field(registration.event)
        if form.is_valid():
            registration = form.save(commit=False)
            if 'extra_questions' in registration.event.config and len(registration.event.config['extra_questions']) > 0:
                temp = {}
                for question in registration.event.config['extra_questions']:
                    temp[question] = form.cleaned_data[question]
                registration.config['extra_questions'] = temp
            registration.save()
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'Registration was edited')
            l = LogEntry(userid=request.user.username,
                         description="Edited registration for %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'))
    else:
        form = OutreachEventRegistrationForm(instance=registration, initial={'confirm_email': registration.email})
        form.add_extra_questions(registration.event)
        form.check_dietary_field(registration.event)
    return render(request, 'outreach/edit_registration.html', {'form': form, 'registration': registration,
                                                               'event_slug': event_slug}) 
Example 29
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 5 votes vote down vote up
def delete_registration(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.delete()
        messages.success(request, 'Hid registration %s' % registration)
        l = LogEntry(userid=request.user.username,
                     description="Deleted 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 30
Project: coursys   Author: sfu-fas   File: views.py    License: GNU General Public License v3.0 5 votes vote down vote up
def toggle_registration_attendance(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.attended = not registration.attended
        registration.save()
        messages.success(request, 'Toggle attendance for %s' % registration)
        l = LogEntry(userid=request.user.username,
                     description="Toggled attendance 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'))