def add(self): # FIXME: It's may use ModelForm.save() method here. # Maybe in future. if not self.request.user.has_perm('testcases.add_bug'): return self.render(response='Permission denied.') form = CaseBugForm(request.GET) if not form.is_valid(): errors = [] for _field_name, error_messages in form.errors.items(): for item in error_messages: errors.append(item) response = '\n'.join(errors) return self.render(response=response) try: self.case.add_bug( bug_id=form.cleaned_data['bug_id'], bug_system_id=form.cleaned_data['bug_system'].pk, summary=form.cleaned_data['summary'], description=form.cleaned_data['description'], ) except Exception as exception: return self.render(response=str(exception)) return self.render()
def render_form(self): form = CaseBugForm(initial={ 'case_run': self.case_run.case_run_id, 'case': self.case_run.case_id, }) if self.request.GET.get('type') == 'table': return HttpResponse(form.as_table()) return HttpResponse(form.as_p())