Ignore:
Timestamp:
19/07/08 07:17:20 (4 years ago)
Author:
nigel.sim
Message:
  • Added payment history
    • Added editing capibilities
File:
1 edited

Legend:

Unmodified
Added
Removed
  • django/domainmanager/trunk/manager/views.py

    r136 r143  
    1 from django.http import HttpResponse 
     1from django.http import HttpResponse, HttpResponseRedirect 
    22from django.contrib.simpletemplate.public import get_template 
    33from django.template import Context, loader 
     
    66from forms import DomainForm, ChargesForm 
    77from django.conf import settings 
    8 from django import newforms as forms 
     8from django import forms 
    99 
    1010from domains.manager.models import Domain, Client, Charge 
     
    2222        domainForm = DomainForm 
    2323        clientForm = forms.form_for_model(Client) 
    24  
     24         
    2525        if request.method == 'POST': 
    2626                addDomainForm = domainForm(request.POST, prefix='domain') 
     
    6868        domain = get_object_or_404(Domain, id=domain_id) 
    6969        updateDomainForm = DomainForm 
    70          
    71         addPaymentForm = ChargesForm 
    72         if request.method == 'POST': 
    73                 return 
     70 
     71        # Add charges form 
     72        addChargesForm = ChargesForm 
     73        if request.method == 'GET' and request.GET.has_key('edit_charge'): 
     74                charge = get_object_or_404(Charge, id=request.GET.get('edit_charge')) 
     75                chargesForm = addChargesForm(initial=forms.model_to_dict(charge), prefix='charge') 
     76        elif request.method == 'POST' and request.POST.get('action') == 'addCharge': 
     77                print "B" 
     78                chargesForm = addChargesForm(request.POST, prefix='charge') 
     79                if chargesForm.is_valid(): 
     80                        charge = Charge() 
     81                        charge.amount = chargesForm.cleaned_data['amount'] 
     82                        charge.description = chargesForm.cleaned_data['description'] 
     83                        charge.invoice_date = chargesForm.cleaned_data['invoice_date'] 
     84                        charge.paid_date = chargesForm.cleaned_data['paid_date'] 
     85                        charge.id = chargesForm.cleaned_data['id'] 
     86                        charge.domain = domain 
     87                        charge.save() 
     88                        return HttpResponseRedirect(request.path) 
     89                else: 
     90                        # Let this fall through to be caught by the form again 
     91                        pass 
     92        else: 
     93                chargesForm = addChargesForm(prefix='charge') 
     94                 
     95        chargeHistory = Charge.objects.filter(domain=domain) 
    7496 
    7597        return render_to_response('domains/domain.html', 
    7698                                                          {'domainList':domain_list, 
    7799                                                           'settings': settings, 
    78                                                            'updateDomainForm':updateDomainForm(forms.model_to_dict(domain)).as_table(), 
    79                                                            'addPaymentForm': addPaymentForm().as_table(), 
    80                                                            'paymentHistory': None, 
     100                                                           'updateDomainForm':updateDomainForm(initial=forms.model_to_dict(domain)).as_table(), 
     101                                                           'addPaymentForm': chargesForm.as_table(), 
     102                                                           'paymentHistory': chargeHistory, 
    81103                                                           }) 
Note: See TracChangeset for help on using the changeset viewer.