Exemple #1
0
 def form_valid(self, form):
     form.save()
     proof = Proof.objects.get(id=self.proof_id)
     proof.proof_display = newtexcode(proof.proof_code,
                                      'proofblock_' + str(proof.pk), "")
     compileasy(proof.proof_code, 'proofblock_' + str(proof.pk))
     return redirect('/handouts/edit/' + str(self.handout_id) + '/')
Exemple #2
0
 def save(self, commit=True):
     instance = super(TheoremForm, self).save(commit=False)
     instance.theorem_display = newtexcode(
         instance.theorem_code, 'theoremblock_' + str(instance.pk), "")
     if commit:
         instance.save()
     return instance
Exemple #3
0
 def save(self, commit=True):
     instance = super(TextBlockForm, self).save(commit=False)
     instance.text_display = newtexcode(instance.text_code,
                                        'textblock_' + str(instance.pk), "")
     if commit:
         instance.save()
     return instance
Exemple #4
0
 def form_valid(self, form):
     form.save()
     theorem = Theorem.objects.get(id=self.theorem_id)
     theorem.theorem_display = newtexcode(theorem.theorem_code,
                                          'theoremblock_' + str(theorem.pk),
                                          "")
     compileasy(theorem.theorem_code, 'theoremblock_' + str(theorem.pk))
     return redirect('/handouts/edit/' + str(self.handout_id) + '/')
Exemple #5
0
 def form_valid(self, form):
     form.save()
     textblock = TextBlock.objects.get(id=self.textblock_id)
     textblock.text_display = newtexcode(textblock.text_code,
                                         'textblock_' + str(textblock.pk),
                                         "")
     compileasy(textblock.text_code, 'textblock_' + str(textblock.pk))
     return redirect('/handouts/edit/' + str(self.handout_id) + '/')
Exemple #6
0
 def save(self, commit=True):
     instance = super(ProofForm, self).save(commit=False)
     instance.proof_display = newtexcode(instance.proof_code,
                                         'proofblock_' + str(instance.pk),
                                         "")
     if commit:
         instance.save()
     return instance
Exemple #7
0
def save_proof_response(request,**kwargs):
    resp_pk = request.POST.get('er-pk','')
    response_code = request.POST.get('response_text','')
    resp = get_object_or_404(Response,pk = resp_pk)
    resp.response_code = response_code
    resp.attempted = 1
    resp.display_response = newtexcode(resp.response_code, 'response_'+str(resp.pk), "")
    resp.modified_date = timezone.now()
    resp.save()
    compileasy(resp.response_code,'response_'+str(resp.pk))
    mod_date = render_to_string("student/problemset/date-snippet.html",{'resp':resp})
    return JsonResponse({'display_response':render_to_string("student/problemset/proof-response-snippet.html",{'resp':resp,'problem_label':resp.publishedproblem_object.pk}),'po_pk':resp.publishedproblem_object.pk,'mod-date':mod_date})
Exemple #8
0
def handouteditview(request, pk):
    h = get_object_or_404(Handout, pk=pk)
    if request.method == "POST":
        form = request.POST
        if "addsection" in form:
            s = Section(name=form.get("section-name", ""))
            s.save()
            d = DocumentElement(content_object=s,
                                chapter_number=h.order,
                                section_number=h.top_section_number + 1,
                                order=h.top_order_number + 1)
            d.save()
            h.top_section_number = h.top_section_number + 1
            h.top_subsection_number = 0
            h.top_order_number = h.top_order_number + 1
            h.top_theorem_number = 0
            h.document_elements.add(d)
            h.save()
        if "addsubsection" in form:
            s = SubSection(name=form.get("subsection-name", ""))
            s.save()
            d = DocumentElement(content_object=s,
                                chapter_number=h.order,
                                section_number=h.top_section_number,
                                subsection_number=h.top_subsection_number + 1,
                                order=h.top_order_number + 1)
            d.save()
            h.top_subsection_number = h.top_subsection_number + 1
            h.top_order_number = h.top_order_number + 1
            h.top_theorem_number = 0
            h.document_elements.add(d)
            h.save()
        if "addtextblock" in form:
            textbl = form.get("codetextblock", "")
            tb = TextBlock(text_code=textbl, text_display="")
            tb.save()
            tb.text_display = newtexcode(textbl, 'textblock_' + str(tb.pk), "")
            tb.save()
            compileasy(tb.text_code, 'textblock_' + str(tb.pk))
            d = DocumentElement(content_object=tb,
                                chapter_number=h.order,
                                section_number=h.top_section_number,
                                subsection_number=h.top_subsection_number,
                                order=h.top_order_number + 1)
            d.save()
            h.top_order_number = h.top_order_number + 1
            h.document_elements.add(d)
            h.save()
        if "addtheorem" in form:
            thmbl = form.get("codetheoremblock", "")
            prefix = form.get("theorem-prefix", "")
            thmname = form.get("theorem-name", "")
            th = Theorem(theorem_code=thmbl,
                         theorem_display="",
                         prefix=prefix,
                         name=thmname,
                         theorem_number=h.top_theorem_number + 1)
            th.save()
            th.theorem_display = newtexcode(thmbl,
                                            'theoremblock_' + str(th.pk), "")
            th.save()
            d = DocumentElement(content_object=th,
                                chapter_number=h.order,
                                section_number=h.top_section_number,
                                subsection_number=h.top_subsection_number,
                                order=h.top_order_number + 1)
            d.save()
            h.top_order_number = h.top_order_number + 1
            h.top_theorem_number = h.top_theorem_number + 1
            h.document_elements.add(d)
            h.save()
        if "addproof" in form:
            proofbl = form.get("codeproofblock", "")
            prefix = form.get("proof-prefix", "")
            pf = Proof(proof_code=proofbl, proof_display="", prefix=prefix)
            pf.save()
            pf.proof_display = newtexcode(proofbl, 'proofblock_' + str(pf.pk),
                                          "")
            pf.save()
            d = DocumentElement(content_object=pf,
                                chapter_number=h.order,
                                section_number=h.top_section_number,
                                subsection_number=h.top_subsection_number,
                                order=h.top_order_number + 1)
            d.save()
            h.top_order_number = h.top_order_number + 1
            h.document_elements.add(d)
            h.save()
        if "addproblemset" in form:
            radio = form.get("neworold", "")
            if radio == "new-problem-set":
                t = NewTest(name=form.get("problem-set-name", ""))
                t.save()
            else:
                testtocopy = NewTest.objects.get(
                    pk=form.get("existing-problem-set", ""))
                t = NewTest(name=testtocopy.name)
                t.save()
                for p in testtocopy.problems.all():
                    sp = SortableProblem(order=p.order,
                                         problem=p.problem,
                                         newtest_pk=t.pk)
                    sp.save()
                    t.problems.add(sp)
            d = DocumentElement(content_object=t,
                                chapter_number=h.order,
                                section_number=h.top_section_number,
                                subsection_number=h.top_subsection_number,
                                order=h.top_order_number + 1)
            d.save()
            h.top_order_number = h.top_order_number + 1
            h.document_elements.add(d)
            h.save()


#redirect to edit newtest view?
#        if "addimage" in form:
#            form = ImageForm(request.POST, request.FILES)
#            if form.is_valid():
#                m = ImageModel(image=form.cleaned_data['image'])
#                m.save()
#                d=DocumentElement(content_object=m,chapter_number=h.order,section_number=h.top_section_number,subsection_number=h.top_subsection_number,order=h.top_order_number+1)
#                d.save()
#                h.top_order_number = h.top_order_number+1
#                h.document_elements.add(d)
#                h.save()
        if 'save' in form:
            if 'docinput' in form:
                D = list(h.document_elements.all())
                D = sorted(D, key=lambda x: x.order)
                doc_element_inputs = form.getlist(
                    'docinput')  #could be an issue if no doc_elements
                section_num = 0
                subsection_num = 0
                theorem_num = 1
                for d in D:
                    if 'element_' + str(d.pk) not in doc_element_inputs:
                        d.delete()
                for i in range(0, len(doc_element_inputs)):
                    d = h.document_elements.get(
                        pk=doc_element_inputs[i].split('_')[1])
                    d.order = i + 1
                    if d.content_type.model == "section":
                        section_num += 1
                        subsection_num = 0
                        theorem_num = 1
                    elif d.content_type.model == "subsection":
                        subsection_num += 1
                        theorem_num = 1
                    elif d.content_type.model == "theorem":
                        th = d.content_object
                        th.theorem_number = theorem_num
                        th.save()
                        h.top_theorem_number = theorem_num
                        h.save()
                        theorem_num += 1
                    d.section_number = section_num
                    d.subsection_number = subsection_num
                    d.save()
    doc_elements = list(h.document_elements.all())
    doc_elements = sorted(doc_elements, key=lambda x: x.order)
    return render(
        request, 'handouts/handouteditview.html', {
            'doc_elements': doc_elements,
            'nbar': 'viewmytests',
            'handout': h,
            'mynewtests': request.user.userprofile.newtests.all()
        })