Exemple #1
0
 def __init__(self,request,*args,**kwargs):
     super(CustomerUpdationForm,self).__init__(*args,**kwargs)
     if 'ln' in request.POST:   
         # Handle Fresh Request
         customer = Customer.objects.get(login_name=request.POST['ln'])
         self.fields['login_name'] = forms.CharField(max_length=32, widget = forms.TextInput(attrs={'readonly':'readonly'}),
             initial=customer.login_name)
         self.fields['password'] = forms.CharField(max_length=128, initial="", required=False)
         self.fields['name'] = forms.CharField(max_length=32, initial=customer.name)
         self.fields['address'] = forms.CharField(max_length=124, required=False, initial=customer.address)
         self.fields['city'] = forms.CharField(max_length=32, required=False, initial=customer.city)
         self.fields['mobile_no'] = forms.CharField(max_length=13, required=False, initial=customer.mobile_no)
         self.fields['email_addr'] = forms.EmailField(initial=customer.email_addr)
         self.fields['alert_type'] = forms.ChoiceField( choices=( ('AUTO','Auto'),
                         ('EMAIL','EMAIL'),
                         ('SMS','SMS'),
                         ('BOTH','Both')
                     ),
                     initial=customer.alert_type
             )
         self.fields['role'] = forms.ChoiceField( choices=get_inferior_roles(request.session['role']), initial=customer.role)
         self.fields['validity_till'] = forms.DateField(initial=customer.validity_till)
     else:
         # Handle the repeated request
         customer = Customer.objects.get(login_name=request.POST['login_name'])
         self.fields['login_name'] = forms.CharField(max_length=32, widget = forms.TextInput(attrs={'readonly':'readonly'}),
             initial=customer.login_name)
         self.fields['password'] = forms.CharField(max_length=128, initial="", required=False)
         self.fields['name'] = forms.CharField(max_length=32, initial=customer.name)
         self.fields['address'] = forms.CharField(max_length=124, required=False, initial=customer.address)
         self.fields['city'] = forms.CharField(max_length=32, required=False, initial=customer.city)
         self.fields['mobile_no'] = forms.CharField(max_length=13, required=False, initial=customer.mobile_no)
         self.fields['email_addr'] = forms.EmailField(initial=customer.email_addr)
         self.fields['alert_type'] = forms.ChoiceField( choices=( ('AUTO','Auto'),
                         ('EMAIL','EMAIL'),
                         ('SMS','SMS'),
                         ('BOTH','Both')
                     ),
                     initial=customer.alert_type
             )
         self.fields['role'] = forms.ChoiceField( choices=get_inferior_roles(request.session['role']), initial=customer.role)
         self.fields['validity_till'] = forms.DateField(initial=customer.validity_till)
Exemple #2
0
 def __init__(self,request,*args,**kwargs):
     super(CustomerRegistrationForm,self).__init__(*args,**kwargs)
     self.fields['role'] = forms.ChoiceField( choices=get_inferior_roles(request.session['role']) )
     customer = Customer.objects.get(login_name=request.session['ln'])
     """
     Read at: https://tabo.pe/projects/django-treebeard/docs/tip/intro.html#basic-usage
     Returns:
         [(<Customer: root>, {'close': [0], 'level': 0L, 'open': True})]
     """
     childs = Customer.get_annotated_list(parent=customer)
     childs_tuple_list = []
     for child in childs:
        childs_tuple_list.append((child[0].login_name, ('-' * child[1]['level']) + child[0].name))
     child_tuple_tuple = tuple(childs_tuple_list)
     self.fields['parent'] = forms.ChoiceField( choices=child_tuple_tuple )