Changeset 136


Ignore:
Timestamp:
19/07/08 01:52:34 (4 years ago)
Author:
nigel.sim
Message:
  • Process domain adding forms
File:
1 edited

Legend:

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

    r129 r136  
    11from django.http import HttpResponse 
     2from django.contrib.simpletemplate.public import get_template 
    23from django.template import Context, loader 
    34from django.shortcuts import render_to_response, get_object_or_404 
    45from django.contrib.auth.decorators import login_required 
     6from forms import DomainForm, ChargesForm 
     7from django.conf import settings 
     8from django import newforms as forms 
    59 
    6 from domains.manager.models import Domain 
     10from domains.manager.models import Domain, Client, Charge 
    711 
    812# Create your views here. 
     
    1115def index(request): 
    1216        domain_list = Domain.objects.all() 
    13         t = loader.get_template('domains/index.html') 
    14         c = Context({ 
    15                 'domain_list':domain_list}) 
    16         return HttpResponse(t.render(c)) 
     17        #t = get_template('domains/index.html') 
     18        #c = Context({ 
     19        #       'domain_list':domain_list}) 
     20        #return HttpResponse(t.render(c)) 
     21        #domainForm = forms.form_for_model(Domain) 
     22        domainForm = DomainForm 
     23        clientForm = forms.form_for_model(Client) 
     24 
     25        if request.method == 'POST': 
     26                addDomainForm = domainForm(request.POST, prefix='domain') 
     27                if addDomainForm.is_valid(): 
     28                        if addDomainForm.cleaned_data['client'] == None: 
     29                                addClientForm = clientForm(request.POST, prefix='client') 
     30                                if addClientForm.is_valid(): 
     31                                        c = addClientForm.save() 
     32                                        print c 
     33                                        domain = Domain() 
     34                                        domain.name = addDomainForm.cleaned_data['name'] 
     35                                        domain.description = addDomainForm.cleaned_data['description'] 
     36                                        domain.registration_date = addDomainForm.cleaned_data['registration_date'] 
     37                                        domain.client = c 
     38                                        domain.save() 
     39                                else: 
     40                                        if not addDomainForm.errors.has_key('client'): 
     41                                                addDomainForm.errors['client'] = [] 
     42                                        addDomainForm.errors['client'].append('Either a new client needs to be added, or an existing one selected') 
     43                        else: 
     44                                domain = Domain() 
     45                                domain.name = addDomainForm.cleaned_data['name'] 
     46                                domain.description = addDomainForm.cleaned_data['description'] 
     47                                domain.registration_date = addDomainForm.cleaned_data['registration_date'] 
     48                                domain.client = addDomainForm.cleaned_data['client'] 
     49                                domain.save() 
     50                                message = "Domain created" 
     51        else: 
     52                # Create blank form 
     53                addDomainForm = domainForm(prefix='domain') 
     54        addClientForm = clientForm(prefix='client') 
     55         
     56        return render_to_response('domains/index.html', 
     57                                                          {'domainList':domain_list, 
     58                                                           'settings': settings, 
     59                                                           'addDomainForm':addDomainForm.as_table(), 
     60                                                           'addClientForm':addClientForm.as_table(), 
     61                                                           'submitAction':'add'}) 
    1762 
    1863@login_required 
    1964def details(request, domain_id): 
    20         domain = get_object_or_404(Domain, name=domain_id) 
    21         return HttpResponse('you want to know about %s'%domain_id) 
     65        # List of domains 
     66        domain_list = Domain.objects.all() 
     67        # Current domain 
     68        domain = get_object_or_404(Domain, id=domain_id) 
     69        updateDomainForm = DomainForm 
     70         
     71        addPaymentForm = ChargesForm 
     72        if request.method == 'POST': 
     73                return 
     74 
     75        return render_to_response('domains/domain.html', 
     76                                                          {'domainList':domain_list, 
     77                                                           'settings': settings, 
     78                                                           'updateDomainForm':updateDomainForm(forms.model_to_dict(domain)).as_table(), 
     79                                                           'addPaymentForm': addPaymentForm().as_table(), 
     80                                                           'paymentHistory': None, 
     81                                                           }) 
Note: See TracChangeset for help on using the changeset viewer.