예제 #1
0
class CreateView(editor.views.editoritem.CreateView):
    form_class = NewExamForm
    template_name = 'exam/new.html'

    def make_exam(self, form):
        ei = form.save()
        ei.set_licence(ei.project.default_licence)
        ei.locale = ei.project.default_locale
        ei.save()
        self.exam = NewExam()
        self.exam.editoritem = ei
        return self.exam

    def form_valid(self, form):
        with transaction.atomic(), reversion.create_revision():
            self.make_exam(form)
            self.exam.save()
            reversion.set_user(self.exam.editoritem.author)

        return redirect(self.get_success_url())

    def get_success_url(self):
        return reverse('exam_edit',
                       args=(
                           self.exam.pk,
                           self.exam.editoritem.slug,
                       ))
예제 #2
0
 def make_exam(self, form):
     ei = form.save()
     ei.set_licence(ei.project.default_licence)
     ei.locale = ei.project.default_locale
     ei.save()
     self.exam = NewExam()
     self.exam.editoritem = ei
     return self.exam
예제 #3
0
    def make_exam(self, form):
        ei = form.save()
        ei.set_licence(ei.project.default_licence)
        ei.locale = ei.project.default_locale
        ei.save()
        self.exam = NewExam()

        self.exam.editoritem = ei
        self.exam.locale = self.request.user.userprofile.language
        return self.exam
예제 #4
0
파일: exam.py 프로젝트: numbas/editor
 def make_exam(self, form):
     ei = form.save()
     ei.set_licence(ei.project.default_licence)
     ei.locale = ei.project.default_locale
     ei.save()
     self.exam = NewExam()
     self.exam.editoritem = ei
     return self.exam
예제 #5
0
class CreateView(editor.views.editoritem.CreateView):
    form_class = NewExamForm
    template_name = 'exam/new.html'

    def make_exam(self,form):
        ei = form.save()
        ei.set_licence(ei.project.default_licence)
        ei.locale = ei.project.default_locale
        ei.save()
        self.exam = NewExam()
        self.exam.editoritem = ei
        return self.exam

    def form_valid(self, form):
        with transaction.atomic(), reversion.create_revision():
            self.make_exam(form)
            self.exam.save()

        return redirect(self.get_success_url())

    def get_success_url(self):
        return reverse('exam_edit', args=(self.exam.pk,
                                          self.exam.editoritem.slug,))
예제 #6
0
    def form_valid(self, form):
        exam_file = form.cleaned_data.get('file')

        content = exam_file.read().decode('utf-8')
        project = form.cleaned_data.get('project')

        ei = EditorItem(content=content,
                        author=self.request.user,
                        project=project)
        ei.locale = project.default_locale

        ei.save()
        ei.set_licence(project.default_licence)

        exam = NewExam()
        exam.editoritem = ei
        exam.save()

        exam_object = NumbasObject(source=content)

        groups = []
        for group in exam_object.data['question_groups']:
            qs = []
            for q in group['questions']:
                question_object = NumbasObject(data=q,
                                               version=exam_object.version)

                qei = EditorItem(content=str(question_object),
                                 author=ei.author)
                qei.set_licence(ei.licence)
                qei.project = ei.project
                qei.save()

                qo = NewQuestion()
                qo.editoritem = qei
                qo.save()

                extensions = Extension.objects.filter(
                    location__in=exam_object.data['extensions'])
                qo.extensions.add(*extensions)
                qs.append(qo.pk)
            groups.append(qs)
        exam.set_question_groups(groups)

        self.exam = exam

        return HttpResponseRedirect(self.get_success_url())
예제 #7
0
    def form_valid(self, form):
        exam_file = form.cleaned_data.get('file')

        content = exam_file.read().decode('utf-8')
        project = form.cleaned_data.get('project')

        ei = EditorItem(content=content,author=self.request.user,project=project)
        ei.locale = project.default_locale

        ei.save()
        ei.set_licence(project.default_licence)

        exam = NewExam()
        exam.editoritem = ei
        exam.save()

        exam_object = NumbasObject(source=content)

        groups = []
        for group in exam_object.data['question_groups']:
            qs = []
            for q in group['questions']:
                question_object = NumbasObject(data=q,version=exam_object.version)

                qei = EditorItem(
                    content = str(question_object),
                    author = ei.author
                )
                qei.set_licence(ei.licence)
                qei.project = ei.project
                qei.save()

                qo = NewQuestion()
                qo.editoritem = qei
                qo.save()

                extensions = Extension.objects.filter(location__in=exam_object.data['extensions'])
                qo.extensions.add(*extensions)
                qs.append(qo.pk)
            groups.append(qs)
        exam.set_question_groups(groups)

        self.exam = exam

        return HttpResponseRedirect(self.get_success_url())
예제 #8
0
파일: exam.py 프로젝트: numbas/editor
    def form_valid(self, form):
        exam_file = form.cleaned_data.get('file')

        content = exam_file.read().decode('utf-8')
        project = form.cleaned_data.get('project')

        ei = EditorItem(content=content, author=self.request.user, project=project)
        ei.locale = project.default_locale

        ei.save()
        ei.set_licence(project.default_licence)
        obj = ei.get_parsed_content()

        def add_contributors(item,contributor_data):
            root = self.request.build_absolute_uri('/')
            for c in contributor_data:
                if c['profile_url'][:len(root)]==root:
                    rest = c['profile_url'][len(root):]
                    try:
                        match = resolve(rest)
                        if match.url_name != 'view_profile':
                            raise Resolver404()
                        pk = match.kwargs['pk']
                        user = User.objects.get(pk=pk)
                        Contributor.objects.create(item=item,user=user)
                    except (Resolver404,User.DoesNotExist):
                        Contributor.objects.create(item=item,name=c['name'],profile_url=c['profile_url'])
                else:
                    Contributor.objects.create(item=item,name=c['name'],profile_url=c['profile_url'])

        contributors = obj.data.get('contributors',[])
        add_contributors(ei,contributors)

        exam = NewExam()
        exam.editoritem = ei
        exam.save()

        exam_object = NumbasObject(source=content)

        groups = []
        for group in exam_object.data['question_groups']:
            qs = []
            for q in group['questions']:
                question_object = NumbasObject(data=q, version=exam_object.version)

                qei = EditorItem(
                    content=str(question_object),
                    author=ei.author
                )
                qei.set_licence(ei.licence)
                qei.project = ei.project
                qei.save()

                qo = NewQuestion()
                qo.editoritem = qei
                qo.save()

                extensions = Extension.objects.filter(location__in=exam_object.data['extensions'])
                qo.extensions.add(*extensions)
                qs.append(qo.pk)

                contributors = q.get('contributors',[])
                add_contributors(qei,contributors)

            groups.append(qs)
        exam.set_question_groups(groups)

        self.exam = exam

        return HttpResponseRedirect(self.get_success_url())
예제 #9
0
    def form_valid(self, form):
        exam_file = form.cleaned_data.get('file')

        content = exam_file.read().decode('utf-8')
        project = form.cleaned_data.get('project')

        ei = EditorItem(content=content, author=self.request.user, project=project)
        ei.locale = project.default_locale

        ei.save()
        ei.set_licence(project.default_licence)
        obj = ei.get_parsed_content()

        def add_contributors(item,contributor_data):
            root = self.request.build_absolute_uri('/')
            for c in contributor_data:
                if c['profile_url'][:len(root)]==root:
                    rest = c['profile_url'][len(root):]
                    try:
                        match = resolve(rest)
                        if match.url_name != 'view_profile':
                            raise Resolver404()
                        pk = match.kwargs['pk']
                        user = User.objects.get(pk=pk)
                        Contributor.objects.create(item=item,user=user)
                    except (Resolver404,User.DoesNotExist):
                        Contributor.objects.create(item=item,name=c['name'],profile_url=c['profile_url'])
                else:
                    Contributor.objects.create(item=item,name=c['name'],profile_url=c['profile_url'])

        contributors = obj.data.get('contributors',[])
        add_contributors(ei,contributors)

        exam = NewExam()
        exam.editoritem = ei
        exam.save()

        exam_object = NumbasObject(source=content)

        groups = []
        for group in exam_object.data['question_groups']:
            qs = []
            for q in group['questions']:
                question_object = NumbasObject(data=q, version=exam_object.version)

                qei = EditorItem(
                    content=str(question_object),
                    author=ei.author
                )
                qei.set_licence(ei.licence)
                qei.project = ei.project
                qei.save()

                qo = NewQuestion()
                qo.editoritem = qei
                qo.save()

                extensions = Extension.objects.filter(location__in=exam_object.data['extensions'])
                qo.extensions.add(*extensions)
                qs.append(qo.pk)

                contributors = q.get('contributors',[])
                add_contributors(qei,contributors)

            groups.append(qs)
        exam.set_question_groups(groups)

        self.exam = exam

        return HttpResponseRedirect(self.get_success_url())