def post(self, request, *args, **kwargs): self.files = request.FILES.getlist('file') for file in self.files: content = file.read().decode('utf-8') self.object = Exam(content=content) if not self.object.content: return self.object.author = self.request.user self.object.save() exam_object = NumbasObject(source=self.object.content) qs = [] for q in exam_object.data['questions']: question = NumbasObject(data=q,version=exam_object.version) qo = Question( content = str(question), author = self.object.author ) qo.save() extensions = Extension.objects.filter(location__in=exam_object.data['extensions']) qo.extensions.add(*extensions) qs.append(qo) self.object.set_questions(qs) return HttpResponseRedirect(self.get_success_url())
def post(self, request, *args, **kwargs): content = request.FILES["file"].read() exam_object = NumbasObject(content) self.qs = [] for q in exam_object.data["questions"]: question = NumbasObject(data=q, version=exam_object.version) qo = Question(content=str(question), author=self.request.user) qo.save() extensions = Extension.objects.filter(location__in=exam_object.data["extensions"]) qo.extensions.add(*extensions) self.qs.append(qo) return redirect(self.get_success_url())
class CreateView(generic.CreateView): """Create a question.""" model = Question form_class = NewQuestionForm template_name = "question/new.html" def get(self, request, *args, **kwargs): self.object = Question() self.object.author = request.user self.object.save() return redirect(self.get_success_url()) def get_success_url(self): return reverse("question_edit", args=(self.object.pk, self.object.slug))
def post(self, request, *args, **kwargs): content = request.FILES['file'].read() exam_object = NumbasObject(content) self.qs = [] for q in exam_object.data['questions']: question = NumbasObject(data=q,version=exam_object.version) qo = Question( content = str(question), author = self.request.user ) qo.save() extensions = Extension.objects.filter(location__in=exam_object.data['extensions']) qo.extensions.add(*extensions) self.qs.append(qo) return redirect(self.get_success_url())
class CreateView(generic.CreateView): """Create a question.""" model = Question form_class = NewQuestionForm template_name = 'question/new.html' def get(self, request, *args, **kwargs): self.object = Question() self.object.author = request.user self.object.save() return redirect(self.get_success_url()) def get_success_url(self): return reverse('question_edit', args=(self.object.pk, self.object.slug,))
def post(self, request, *args, **kwargs): self.files = request.FILES.getlist('file') for file in self.files: content = file.read().decode('utf-8') self.object = Exam(content=content) if not self.object.content: return self.object.author = self.request.user self.object.save() exam_object = NumbasObject(source=self.object.content) qs = [] for q in exam_object.data['questions']: question = NumbasObject(data=q, version=exam_object.version) qo = Question(content=str(question), author=self.object.author) qo.save() qs.append(qo) self.object.set_questions(qs) return HttpResponseRedirect(self.get_success_url())
def get(self, request, *args, **kwargs): self.object = Question() self.object.author = request.user self.object.save() return redirect(self.get_success_url())