Example #1
0
class CreateView(editor.views.editoritem.CreateView):
    
    """Create a question."""
    
    form_class = NewQuestionForm
    template_name = 'question/new.html'

    def form_valid(self, form):
        with transaction.atomic(), reversion.create_revision():
            ei = form.save()
            content = ei.get_parsed_content()
            content.data['partsMode'] = form.cleaned_data.get('parts_mode')
            ei.content = str(content)
            ei.set_licence(ei.project.default_licence)
            ei.save()
            self.question = NewQuestion()
            self.question.editoritem = ei
            self.question.save()
            reversion.set_user(ei.author)

        return redirect(self.get_success_url())
    
    def get_success_url(self):
        return reverse('question_edit', args=(self.question.pk,
                                              self.question.editoritem.slug,))
Example #2
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())
Example #3
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())
Example #4
0
class CreateView(editor.views.editoritem.CreateView):

    """Create a question."""

    form_class = NewQuestionForm
    template_name = "question/new.html"

    def form_valid(self, form):
        with transaction.atomic(), reversion.create_revision():
            ei = form.save()
            ei.set_licence(ei.project.default_licence)
            ei.save()
            self.question = NewQuestion()
            self.question.editoritem = ei
            self.question.save()

        return redirect(self.get_success_url())

    def get_success_url(self):
        return reverse("question_edit", args=(self.question.pk, self.question.editoritem.slug))
Example #5
0
class CreateView(editor.views.editoritem.CreateView):
    
    """Create a question."""
    
    form_class = NewQuestionForm
    template_name = 'question/new.html'

    def form_valid(self, form):
        with transaction.atomic(), reversion.create_revision():
            ei = form.save()
            ei.set_licence(ei.project.default_licence)
            ei.save()
            self.question = NewQuestion()
            self.question.editoritem = ei
            self.question.save()

        return redirect(self.get_success_url())
    
    def get_success_url(self):
        return reverse('question_edit', args=(self.question.pk,
                                              self.question.editoritem.slug,))
Example #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)
        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())
Example #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)
        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())