Stripped personal data from development repository
Samo Penic
2019-02-20 83c3f647c35477564b77cbc5b36d37d793d5442a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from .berkitext import getNaloga
from aoi_gen import Problem, Template, BerkiParse
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
 
register = template.Library()
 
 
@register.filter
@stringfilter
def getHTMLText(value):
    try:
        parser = BerkiParse.BerkiParse(value)
        parser.parseSections()
        problem_source = Problem.ProblemSource(parser=parser)
        problem = Problem.Problem(source=problem_source)
    except:
        return mark_safe(
            "<p class='problem_text'>Error parsing and generating problem</p>"
        )
    ret_text = "<p class='problem_text'>{}</p>".format(problem.problem["introduction"])
    try:
        if len(problem.problem["subproblems"]) > 0:
            ret_text += "<ul>"
            for sp, sol in zip(
                problem.problem["subproblems"], problem.problem["solutions"]
            ):
                ret_text += "<li><p class='problem_text'>{}</p>".format(sp)
                for i, soltext in enumerate(sol["shuffled"]):
                    ret_text += "<div class='{}'>{}) {} </div>".format(
                        "ans_correct" if soltext[1] == "1" else "ans_wrong",
                        chr(ord("a") + i),
                        soltext[0].format_as_tex(glyph=sol["glyph"], unit=sol["unit"]),
                    )
                ret_text += "</li>"
            ret_text += "</ul>"
        else:
            soltext = problem.problem["solutions"][0]
            for i, soltext in enumerate(soltext["shuffled"]):
                ret_text += "<div class='{}'>{}) {}</div>".format(
                    "ans_correct" if soltext[1] == "1" else "ans_wrong",
                    chr(ord("a") + i),
                    soltext[0].format_as_tex(glyph=problem.problem["solutions"][0]["glyph"],
                                             unit=problem.problem["solutions"][0]["unit"]),
                )
    except:
        ret_text+="Error finding texts and results!"
    return mark_safe(ret_text)
    # pr=getNaloga(value)
    # problem = "<p class='problem_text'>"+pr['text']+"</p>"
    # for i,ca in enumerate(pr['correct']):
    #     problem +="<div class='ans_correct'>"+chr(ord('a')+i)+") "+ca+'</div>'
    # for j,ca in enumerate(pr['wrong']):
    #     problem +='<div class="ans_wrong">'+chr(ord('a')+i+j+1)+") "+ca+'</div>'
    # return mark_safe(problem)