def testcase_valid(request, testcase_id=0, **kwargs): if testcase_id: testcase = TestCase.objects.get(pk=str(testcase_id)) testcase_form = TestCaseForm(request.POST, instance=testcase) testcasesteps_form = TestCaseStepFormSet(request.POST, instance=testcase) else: testcase_form = TestCaseForm(request.POST) testcasesteps_form = TestCaseStepFormSet(request.POST) if testcase_form.is_valid() and testcasesteps_form.is_valid(): testcase = testcase_form.save() testcasesteps_form.instance = testcase testcasesteps_form.save() log = history.History(request.user, testcase) log.add_form(testcase_form, is_new=(testcase_id == 0)) log.add_formset(testcasesteps_form) log.save() return success( message="TestCase saved", data={"parent_id": getattr(testcase.parent, "id", 0), "current_id": testcase.id} ) else: return failed( message="Validation errors: %s" % testcase_form.error_message(), data=testcase_form.errors_list() + testcasesteps_form._errors_list(), )
def testcase_valid(request, testcase_id): testcase = TestCase.objects.get(pk=str(testcase_id)) testcase_form = TestCaseForm(request.POST, instance=testcase) testcasesteps_form = TestCaseStepFormSet(request.POST, instance=testcase) if testcase_form.is_valid() and testcasesteps_form.is_valid(): testcase_form.save() testcasesteps_form.save() return success(message='TestCase saved', data={ "parent_id" : getattr(testcase.parent,"id", 0), "current_id" : testcase.id }) else: formset_errors = [] for i, error in filter(lambda x: x[1], list(enumerate(testcasesteps_form.errors))): for v, k in error.items(): formset_errors.append(map(lambda x:(("testcasestep_set-%s-%s") % (i,v) ,x), k)[0]) # print formset_errors return failed(message="Validation errors", data=[(k, v[0]) for k, v in testcase_form.errors.items()] + formset_errors)
def testcase_valid(request, testcase_id=0): if testcase_id: testcase = TestCase.objects.get(pk=str(testcase_id)) testcase_form = TestCaseForm(request.POST, instance=testcase) testcasesteps_form = TestCaseStepFormSet(request.POST, instance=testcase) else: testcase_form = TestCaseForm(request.POST) testcasesteps_form = TestCaseStepFormSet(request.POST) if testcase_form.is_valid() and testcasesteps_form.is_valid(): testcase = testcase_form.save() testcasesteps_form.instance = testcase testcasesteps_form.save() return success(message='TestCase saved', data={"parent_id": getattr(testcase.parent, "id", 0), "current_id": testcase.id}) else: return failed(message="Validation errors: %s" % testcase_form.error_message(), data=testcase_form.errors_list() + testcasesteps_form.errors_list())