def directory_valid(request, directory_id=0): if directory_id: testcase_directory = TestCaseDirectory.objects.get(pk=str(directory_id)) testcase_directory_form = TestCaseDirectoryForm(request.POST, instance=testcase_directory) else: testcase_directory_form = TestCaseDirectoryForm(request.POST) if testcase_directory_form.is_valid(): testcase_directory = testcase_directory_form.save() return success(message='testcase directory saved', data={ "parent_id" : getattr(testcase_directory.parent,"id", 0), "current_id" : testcase_directory.id }) else: return failed(message="Validation errors", data=[(k, v[0]) for k, v in testcase_directory_form.errors.items()])
def directory_valid(request, directory_id=0): if directory_id: testcase_directory = TestCaseDirectory.objects.get(pk=directory_id) testcase_directory_form = TestCaseDirectoryForm(request.POST, instance=testcase_directory) else: testcase_directory_form = TestCaseDirectoryForm(request.POST) if testcase_directory_form.is_valid(): testcase_directory = testcase_directory_form.save() return success(message='testcase directory saved', data={"parent_id": getattr(testcase_directory.parent, "id", 0), "current_id": testcase_directory.id}) else: return failed(message="Validation errors: %s" % testcase_directory_form.error_message(), data=testcase_directory_form.errors_list())
def directory_valid(request, directory_id=0, **kwargs): if directory_id: testcase_directory = TestCaseDirectory.objects.get(pk=directory_id) testcase_directory_form = TestCaseDirectoryForm(request.POST, instance=testcase_directory) else: testcase_directory_form = TestCaseDirectoryForm(request.POST) if testcase_directory_form.is_valid(): testcase_directory = testcase_directory_form.save() log = history.History(request.user, testcase_directory) log.add_form(testcase_directory_form, is_new=(directory_id == 0)) log.save() return success( message="Directory saved", data={"parent_id": getattr(testcase_directory.parent, "id", 0), "current_id": testcase_directory.id}, ) else: return failed( message="Validation errors: %s" % testcase_directory_form.error_message(), data=testcase_directory_form.errors_list(), )