コード例 #1
0
class UploadView(generic.CreateView):
    """Upload a .exam file representing an exam"""

    model = Exam

    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_success_url(self):
        if len(self.files) == 1:
            return reverse('exam_edit',
                           args=(self.object.pk, self.object.slug))
        else:
            return reverse('exam_index')
コード例 #2
0
ファイル: exam.py プロジェクト: reshama/editor
class CreateView(generic.CreateView):
    
    """Create an exam."""
    
    model = Exam
    form_class = NewExamForm

    def get(self, request, *args, **kwargs):
        self.object = Exam()
        self.object.author = request.user
        self.object.locale = request.user.userprofile.language
        self.object.save()
        return redirect(self.get_success_url())

    def get_success_url(self):
        return reverse('exam_edit', args=(self.object.pk,
                                          self.object.slug,))
コード例 #3
0
class CreateView(generic.CreateView):
    """Create an exam."""

    model = Exam
    form_class = NewExamForm

    def get(self, request, *args, **kwargs):
        self.object = Exam()
        self.object.author = request.user
        self.object.locale = request.user.userprofile.language
        self.object.save()
        return redirect(self.get_success_url())

    def get_success_url(self):
        return reverse('exam_edit', args=(
            self.object.pk,
            self.object.slug,
        ))
コード例 #4
0
ファイル: exam.py プロジェクト: reshama/editor
class UploadView(generic.CreateView):
    
    """Upload a .exam file representing an exam"""

    model = Exam

    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 get_success_url(self):
        if len(self.files)==1:
            return reverse('exam_edit', args=(self.object.pk, self.object.slug) )
        else:
            return reverse('exam_index')