Exemplo n.º 1
0
 def test_form_sap_id_validation_negative(self):
     data = [str(get_random_int_with_digit_count(PRODUCT_SAP_DIGITS - 1)),
             str(get_random_int_with_digit_count(PRODUCT_SAP_DIGITS + 1)), 'test']
     for value in data:
         self.product_form['product_sap_id'] = value
         product_form = ProductForm(data=self.product_form, instance=self.product)
         self.assertFalse(product_form.is_valid(), msg=f"Value: {value}")
Exemplo n.º 2
0
 def get_context_data(self, **kwargs):
     """Add to context client side form hints."""
     context = super().get_context_data(**kwargs)
     context['product_validation_hints'] = ProductForm.validation_hints
     context['spec_validation_hints'] = SpecificationForm.validation_hints
     context['form'] = {'product': ProductForm(), 'spec': SpecificationForm()}
     return context
Exemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        """Call customized form object to protect sap id field from change."""
        product_form = ProductForm(data=self.request.POST)
        spec_form = SpecificationForm(data=self.request.POST)
        multiform = {'product': product_form, 'spec': spec_form}

        if all(form.is_valid() for form in multiform.values()):
            return self.form_valid(multiform)
        return self.form_invalid(multiform)
Exemplo n.º 4
0
 def get_context_data(self, **kwargs):
     """Add to context client side form hints.
     Call product form with update flag to disable sap id field."""
     context = super().get_context_data(**kwargs)
     context['product_validation_hints'] = ProductForm.validation_hints
     context['spec_validation_hints'] = SpecificationForm.validation_hints
     product_form = ProductForm(update=True, instance=self.object)
     spec_form = SpecificationForm(instance=self.object.specification)
     context['form'] = {'product': product_form, 'spec': spec_form}
     return context
Exemplo n.º 5
0
def create_product(request):
    if request.method == 'GET':
        form = ProductForm()
        return render(request, 'products/product_form.html', {'form': form})
    elif request.method == 'POST':
        form = ProductForm(request.POST or None, request.FILES or None)
        if form.is_valid():
            print(form)
            form.save()
            return redirect("success")
Exemplo n.º 6
0
 def test_form_index_validation_negative(self):
     data = ['R87543445/324', 'R7655674323/32', 'T001234322', 'S877543454/00', 'test', '123']
     for value in data:
         self.product_form['index'] = value
         product_form = ProductForm(data=self.product_form, instance=self.product)
         self.assertFalse(product_form.is_valid(), msg=f"Value: {value}")
Exemplo n.º 7
0
 def test_form_index_validation_positive(self):
     data = ['R875434454/32', 'T001234322/34', '']
     for value in data:
         self.product_form['index'] = value
         product_form = ProductForm(data=self.product_form, instance=self.product)
         self.assertTrue(product_form.is_valid(), msg=f"Value: {value}")
Exemplo n.º 8
0
 def test_form_sap_id_validation_positive(self):
     self.product_form['product_sap_id'] = str(get_random_int_with_digit_count(PRODUCT_SAP_DIGITS))
     product_form = ProductForm(data=self.product_form, instance=self.product)
     self.assertTrue(product_form.is_valid())