示例#1
0
 def test_ClientForm_invalid_number(self):
     form = ClientForm(
         data={
             'name': 'Lo Lo',
             'calling_number': '9898887888',
             'contact_number': '987877899'
         })
     self.assertFalse(form.is_valid())
示例#2
0
 def get(self, request, *args, **kwargs):
     client_form = ClientForm()
     template_name = 'customers/client_form.html'
     context = {
         'client_form': client_form,
     }
     return render(request, template_name, context)
示例#3
0
 def post(self, request):
     form = ClientForm(request.POST or None)
     next = request.POST['next']
     if next == reverse('customers:customer_create_view'):
         next = None
     if not next:
         next = reverse('customers:customer_list_view')
     if form.is_valid():
         instance = form.save(commit=False)
         instance.created_by = self.request.user
         instance.save()
         messages.add_message(request, messages.INFO,
                              'Success - Customer added successfully!')
         return redirect(next)
     messages.add_message(request, messages.INFO,
                          'Failed - Invalid details')
     return redirect(next)
示例#4
0
 def post(self, request, id):
     form = ClientForm(request.POST or None)
     if form.is_valid():
         ClientDetails.objects.filter(pk=id).update(
             name=request.POST['name'],
             contact_number=request.POST['contact_number'],
             calling_number=request.POST['calling_number'],
             address=request.POST['address'],
             city=request.POST['city'],
             state=request.POST['state'],
             pin=request.POST['pin'],
             edited_by=self.request.user,
             edit_datetime=datetime.datetime.now())
         messages.add_message(request, messages.INFO,
                              'Success - Customer edited successfully')
         return redirect('customers:customer_list_view')
     messages.add_message(request, messages.INFO,
                          'Failed - Invalid details!')
     return redirect('customers:customer_list_view')
示例#5
0
    def post(self, request, *args, **kwargs):
        client_form = ClientForm(request.POST)

        if client_form.is_valid():
            client = client_form.save(commit=False)
            client.domain_url = client.name + '.' + settings.DOMAIN_NAME
            client.schema_name = client.name
            client.save()

            port = settings.CREATED_TENANT_REDIRECTION_PORT

            return redirect(
                f"http://{client.domain_url}:{port}/auth_tenants/register")

        else:
            template_name = 'customers/client_form.html'
            context = {
                'client_form': client_form,
            }

            return render(request, template_name, context)
示例#6
0
 def test_ClientForm_missing_number(self):
     form = ClientForm(data={
         'name': 'Lo Lo',
         'calling_number': '9898887888'
     })
     self.assertFalse(form.is_valid())