Exemplo n.º 1
0
 def test_CallRegisterForm_valid(self):
     form = CallRegisterForm(
         data={
             'complaint_nature': 'Wet Service',
             'appointment_date': datetime.date.today()
         })
     self.assertTrue(form.is_valid())
Exemplo n.º 2
0
 def post(self, request, id):
     """
     Overrides all existing details of specific call, similar to
     call register.
     """
     form                        = CallRegisterForm(request.POST or None)
     if form.is_valid():
         object                  = get_object_or_404(CallRegister, pk=id)
         # Getting only ONE customer from db
         # that matches passed name
         # MUST BE CHANGED
         CallRegister.objects.filter(pk=id).update(
             customer            = get_object_or_404(ClientDetails, pk=request.POST['customer-id']),
             complaint_nature    = form.cleaned_data['complaint_nature'],
             brand               = form.cleaned_data['brand'],
             product_name        = form.cleaned_data['product_name'],
             product_serial      = form.cleaned_data['product_serial'],
             product_coverage    = form.cleaned_data['product_coverage'],
             appointment_date    = form.cleaned_data['appointment_date'],
             appointment_time    = form.cleaned_data['appointment_time'],
             edited_by           = self.request.user,
             edit_datetime       = datetime.datetime.now()
             )
         messages.add_message(request, messages.INFO, 'Success - Call detials edited successfully!')
         return redirect(reverse('calls:call_detail_view', kwargs={'id':id}))
     messages.add_message(request, messages.INFO, 'Failed - Invalid details')
     return redirect(reverse('calls:call_edit_view', kwargs={'id':id}))
Exemplo n.º 3
0
 def test_CallRegisterForm_all_fields(self):
     form = CallRegisterForm(
         data={
             'complaint_nature': 'Service',
             'brand': 'PLC',
             'product_name': 'JCW',
             'product_serial': '678SDD233DS',
             'product_coverage': True,
             'appointment_date': datetime.date.today(),
             'appointment_time': datetime.datetime.now().strftime(
                 '%H:%M:%S')
         })
     self.assertTrue(form.is_valid())
Exemplo n.º 4
0
 def post(self, request):
     """
     Registers new call against passed customer id
     """
     form                        = CallRegisterForm(request.POST or None)
     if form.is_valid():
         instance                = form.save(commit=False)
         instance.customer       = get_object_or_404(ClientDetails, pk=request.POST['customer-id'])
         instance.added_by       = self.request.user
         instance.save()
         messages.add_message(request, messages.INFO, 'Success - Call added successfully!')
         return redirect('calls:calls_list_view')
     messages.add_message(request, messages.INFO, 'Failed - Invalid details')
     return render(request, self.template_name)
Exemplo n.º 5
0
 def get(self, request, id):
     """
     Returns single call data from db, appointment_date is passed into
     form to display as form only.
     """
     object                      = get_object_or_404(CallRegister, pk=id)
     form                        = CallRegisterForm(instance=object)
     context                     = {
         'object'                : object,
         'form'                  : form
     }
     return render(request, self.template_name, context)
Exemplo n.º 6
0
 def test_CallRegisterForm_invalid(self):
     form = CallRegisterForm(data={'complaint_nature': ''})
     self.assertFalse(form.is_valid())
Exemplo n.º 7
0
 def get(self, request):
     """
     Returns template to register call with form from forms.py
     """
     form                        = CallRegisterForm()
     return render(request, self.template_name, {'form':form})