예제 #1
0
def AddPerson(request,ledgerid=0):
    ### check if the ledger exists, bail out if not
    try:
        ledger = Ledger.objects.get(pk = ledgerid)
    except Ledger.DoesNotExist:
        response = render_to_response('ledgerdoesnotexist.html')
        return response

    ### check if the ledger is open
    if ledger.closed:
        response = render_to_response('ledger_is_closed.html')
        return response

    if request.method == 'POST':
        form = PersonForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            person = Person(ledger_id=ledgerid,name=form['name'].data)
            person.save() # save the new person
            return HttpResponseRedirect('/ledger/%s/#people' % ledgerid) # return to the ledger page
        else:
            form = PersonForm(request.POST)
    else:
        form = PersonForm()

    return render(request, 'add_person.html', {
        'form': form,
    })
예제 #2
0
def AddPerson(request, ledgerid=0):
    ### check if the ledger exists, bail out if not
    try:
        ledger = Ledger.objects.get(pk=ledgerid)
    except Ledger.DoesNotExist:
        response = render_to_response('ledgerdoesnotexist.html')
        return response

    ### check if the ledger is open
    if ledger.closed:
        response = render_to_response('ledger_is_closed.html')
        return response

    if request.method == 'POST':
        form = PersonForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            person = Person(ledger_id=ledgerid, name=form['name'].data)
            person.save()  # save the new person
            return HttpResponseRedirect('/ledger/%s/#people' %
                                        ledgerid)  # return to the ledger page
        else:
            form = PersonForm(request.POST)
    else:
        form = PersonForm()

    return render(request, 'add_person.html', {
        'form': form,
    })
예제 #3
0
def EditPerson(request, personid=0):
    ### Check if the person exists - bail out if not
    try:
        person = Person.objects.get(pk = personid)
    except Person.DoesNotExist:
        response = render_to_response('person_does_not_exist.html')
        return response

    
    ### check if the ledger is open
    ledger = Ledger.objects.get(pk=person.ledger.id)
    if ledger.closed:
        response = render_to_response('ledger_is_closed.html')
        return response

    if request.method == 'POST':
        form = PersonForm(request.POST) # A form bound to the person data
        if form.is_valid(): # All validation rules pass
            person.name = form['name'].data
            person.save()
            return HttpResponseRedirect('/ledger/%s/#people' % person.ledger.id) # return to the ledger page
        else:
            form = PersonForm(request.POST)
    else:
        form = PersonForm(instance=person)

    return render(request, 'edit_person.html', {
        'form': form,
        'person': person
    })
예제 #4
0
def EditPerson(request, personid=0):
    ### Check if the person exists - bail out if not
    try:
        person = Person.objects.get(pk=personid)
    except Person.DoesNotExist:
        response = render_to_response('person_does_not_exist.html')
        return response

    ### check if the ledger is open
    ledger = Ledger.objects.get(pk=person.ledger.id)
    if ledger.closed:
        response = render_to_response('ledger_is_closed.html')
        return response

    if request.method == 'POST':
        form = PersonForm(request.POST)  # A form bound to the person data
        if form.is_valid():  # All validation rules pass
            person.name = form['name'].data
            person.save()
            return HttpResponseRedirect(
                '/ledger/%s/#people' %
                person.ledger.id)  # return to the ledger page
        else:
            form = PersonForm(request.POST)
    else:
        form = PersonForm(instance=person)

    return render(request, 'edit_person.html', {
        'form': form,
        'person': person
    })