예제 #1
0
def edit_pledge(request, id):
    """Render and process a form for users to modify information about an existing pledge.

    Required parameters:
        - id    =>  the unique ID of the pledge to edit (as an integer)

    """
    log_page_view(request, 'Edit Pledge')
    pledge = get_object_or_404(Potential, id=id)
    if request.method == 'POST':
        form = PledgeForm(request.POST, instance=pledge)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(pledge.get_absolute_url())
    else:
        if 'delete' in request.GET and request.GET.get('delete') == 'true':
            if pledge.rush:
                redirect = reverse('pledges', kwargs={'name': pledge.rush.get_unique_name()})
            else:
                redirect = reverse('all_pledges')
            log.info('%s (%s) deleted pledge %s %s', request.user.username, request.user.get_full_name(),
                     pledge.first_name, pledge.last_name)
            pledge.delete()
            return HttpResponseRedirect(redirect)
        form = PledgeForm(instance=pledge)
    return render(request, 'rush/edit_potential.html', {'form': form, 'potential': pledge, 'pledge': True},
                  context_instance=RequestContext(request))
예제 #2
0
def add_pledge(request, name=None):
    """Render and process a form for users to create records of new pledges.

    Optional parameters:
        - name  =>  the unique name (abbreviation) of the rush with which to associate the pledge: defaults to none

    """
    log_page_view(request, 'Add Pledge')
    rush = _get_rush_or_404(name)
    if request.method == 'POST':
        form = PledgeForm(request.POST)
        if form.is_valid():
            pledge = form.save(commit=False)
            pledge.pledged = True
            pledge.save()
            if rush is None:
                redirect = reverse('all_pledges')
            else:
                rush.updated = datetime.now()
                rush.save()
                redirect = reverse('pledges', kwargs={'name': name})
            return HttpResponseRedirect(redirect)
    else:
        form = PledgeForm() if rush is None else PledgeForm(initial={'rush': rush})
    return render(request, 'rush/add_potential.html', {'form': form, 'rush': rush, 'pledge': True},
                  context_instance=RequestContext(request))
예제 #3
0
def edit_pledge(request, id):
    """Render and process a form for users to modify information about an existing pledge.

    Required parameters:
        - id    =>  the unique ID of the pledge to edit (as an integer)

    """
    log_page_view(request, 'Edit Pledge')
    pledge = get_object_or_404(Potential, id=id)
    if request.method == 'POST':
        form = PledgeForm(request.POST, instance=pledge)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(pledge.get_absolute_url())
    else:
        if 'delete' in request.GET and request.GET.get('delete') == 'true':
            if pledge.rush:
                redirect = reverse(
                    'pledges', kwargs={'name': pledge.rush.get_unique_name()})
            else:
                redirect = reverse('all_pledges')
            log.info('%s (%s) deleted pledge %s %s', request.user.username,
                     request.user.get_full_name(), pledge.first_name,
                     pledge.last_name)
            pledge.delete()
            return HttpResponseRedirect(redirect)
        form = PledgeForm(instance=pledge)
    return render(request,
                  'rush/edit_potential.html', {
                      'form': form,
                      'potential': pledge,
                      'pledge': True
                  },
                  context_instance=RequestContext(request))
예제 #4
0
def add_pledge(request, name=None):
    """Render and process a form for users to create records of new pledges.

    Optional parameters:
        - name  =>  the unique name (abbreviation) of the rush with which to associate the pledge: defaults to none

    """
    log_page_view(request, 'Add Pledge')
    rush = _get_rush_or_404(name)
    if request.method == 'POST':
        form = PledgeForm(request.POST)
        if form.is_valid():
            pledge = form.save(commit=False)
            pledge.pledged = True
            pledge.save()
            if rush is None:
                redirect = reverse('all_pledges')
            else:
                rush.updated = datetime.now()
                rush.save()
                redirect = reverse('pledges', kwargs={'name': name})
            return HttpResponseRedirect(redirect)
    else:
        form = PledgeForm() if rush is None else PledgeForm(
            initial={'rush': rush})
    return render(request,
                  'rush/add_potential.html', {
                      'form': form,
                      'rush': rush,
                      'pledge': True
                  },
                  context_instance=RequestContext(request))