def post(self, request, *args, **kwargs): self.user = request.user self.object = self.get_object() if not self.object.can_be_edited_by(self.user): return HttpResponseForbidden() data = json.loads(request.POST['json']) theme = data['theme'] if theme['custom']: data['custom_theme'] = theme['path'] data['theme'] = '' else: data['custom_theme'] = None data['theme'] = theme['path'] self.questions = data['questions'] del data['questions'] exam_form = ExamForm(data, instance=self.object) if exam_form.is_valid(): return self.form_valid(exam_form) else: return self.form_invalid(exam_form)
def post(self, request, *args, **kwargs): super(UpdateView, self).post(request, *args, **kwargs) theme = self.data['theme'] if theme['custom']: self.data['custom_theme'] = theme['path'] self.data['theme'] = '' else: self.data['custom_theme'] = None self.data['theme'] = theme['path'] self.question_groups = self.data['question_groups'] del self.data['question_groups'] exam_form = ExamForm(self.data, instance=self.object) if exam_form.is_valid(): return self.form_valid(exam_form) else: return self.form_invalid(exam_form)