def edit_potential(request, id): """Render and process a form for users to modify information about an existing potential. Required parameters: - id => the unique ID of the potential to edit (as an integer) """ log_page_view(request, 'Edit Potential') potential = get_object_or_404(Potential, id=id) if request.method == 'POST': form = PotentialForm(request.POST, instance=potential) if form.is_valid(): form.save() if form.cleaned_data['pledged']: redirect = reverse('show_pledge', kwargs={'id': id}) else: redirect = reverse('show_potential', kwargs={'id': id}) return HttpResponseRedirect(redirect) else: if 'delete' in request.GET and request.GET.get('delete') == 'true': if potential.rush: redirect = reverse('potentials', kwargs={'name': potential.rush.get_unique_name()}) else: redirect = reverse('all_potentials') log.info('%s (%s) deleted potential %s %s', request.user.username, request.user.get_full_name(), potential.first_name, potential.last_name) potential.delete() return HttpResponseRedirect(redirect) form = PotentialForm(instance=potential) return render(request, 'rush/edit_potential.html', {'form': form, 'potential': potential, 'pledge': False}, context_instance=RequestContext(request))
def add_potential(request, name=None): """Render and process a form for users to create records of new potential members. Optional parameters: - name => the unique name (abbreviation) of the rush with which to associate the potential: defaults to none """ log_page_view(request, 'Add Potential') rush = _get_rush_or_404(name) if request.method == 'POST': form = PotentialForm(request.POST) if form.is_valid(): potential = form.save(commit=False) if rush is not None: potential.rush = rush rush.updated = datetime.now() rush.save() potential.save() redirect = reverse( 'all_potentials') if rush is None else rush.get_absolute_url() return HttpResponseRedirect(redirect) else: form = PotentialForm() if rush is None else PotentialForm( initial={'rush': rush}) return render(request, 'rush/add_potential.html', { 'form': form, 'rush': rush, 'pledge': False }, context_instance=RequestContext(request))
def edit_potential(request, id): """Render and process a form for users to modify information about an existing potential. Required parameters: - id => the unique ID of the potential to edit (as an integer) """ log_page_view(request, 'Edit Potential') potential = get_object_or_404(Potential, id=id) if request.method == 'POST': form = PotentialForm(request.POST, instance=potential) if form.is_valid(): form.save() if form.cleaned_data['pledged']: redirect = reverse('show_pledge', kwargs={'id': id}) else: redirect = reverse('show_potential', kwargs={'id': id}) return HttpResponseRedirect(redirect) else: if 'delete' in request.GET and request.GET.get('delete') == 'true': if potential.rush: redirect = reverse( 'potentials', kwargs={'name': potential.rush.get_unique_name()}) else: redirect = reverse('all_potentials') log.info('%s (%s) deleted potential %s %s', request.user.username, request.user.get_full_name(), potential.first_name, potential.last_name) potential.delete() return HttpResponseRedirect(redirect) form = PotentialForm(instance=potential) return render(request, 'rush/edit_potential.html', { 'form': form, 'potential': potential, 'pledge': False }, context_instance=RequestContext(request))
def add_potential(request, name=None): """Render and process a form for users to create records of new potential members. Optional parameters: - name => the unique name (abbreviation) of the rush with which to associate the potential: defaults to none """ log_page_view(request, 'Add Potential') rush = _get_rush_or_404(name) if request.method == 'POST': form = PotentialForm(request.POST) if form.is_valid(): potential = form.save(commit=False) if rush is not None: potential.rush = rush rush.updated = datetime.now() rush.save() potential.save() redirect = reverse('all_potentials') if rush is None else rush.get_absolute_url() return HttpResponseRedirect(redirect) else: form = PotentialForm() if rush is None else PotentialForm(initial={'rush': rush}) return render(request, 'rush/add_potential.html', {'form': form, 'rush': rush, 'pledge': False}, context_instance=RequestContext(request))