Browse Source

tex-html: stahování obsahu pro texání

remotes/origin/bug
Matěj Kocián 9 years ago
parent
commit
b9f95bc037
  1. 4
      seminar/urls.py
  2. 48
      seminar/views.py

4
seminar/urls.py

@ -47,9 +47,11 @@ urlpatterns = [
staff_member_required(views.StavDatabazeView), name='stav_databaze'), staff_member_required(views.StavDatabazeView), name='stav_databaze'),
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/obalkovani$', url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/obalkovani$',
staff_member_required(views.obalkovaniView), name='seminar_cislo_resitel_obalkovani'), staff_member_required(views.obalkovaniView), name='seminar_cislo_resitel_obalkovani'),
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/tex-download.json$',
staff_member_required(views.texDownloadView), name='seminar_tex_download'),
url(r'^soustredeni/(?P<soustredeni>\d+)/obalky.pdf', url(r'^soustredeni/(?P<soustredeni>\d+)/obalky.pdf',
staff_member_required(views.soustredeniObalkyView), name='seminar_soustredeni_obalky'), staff_member_required(views.soustredeniObalkyView), name='seminar_soustredeni_obalky'),
url(r'^tex-upload/login/$', views.LoginView, name='seminar_login'), url(r'^tex-upload/login/$', views.LoginView, name='seminar_login'),
url(r'^tex-upload/$', staff_member_required(views.TexUploadView), name='seminar_tex_upload'), url(r'^tex-upload/$', staff_member_required(views.texUploadView), name='seminar_tex_upload'),
] ]

48
seminar/views.py

@ -516,7 +516,7 @@ def LoginView(request):
@ensure_csrf_cookie @ensure_csrf_cookie
def TexUploadView(request): def texUploadView(request):
def uloz_soubory(files, rocnik, cislo): def uloz_soubory(files, rocnik, cislo):
for filename, f in files: for filename, f in files:
@ -597,8 +597,7 @@ def TexUploadView(request):
else: else:
problem.text_zadani = html problem.text_zadani = html
problem.nazev = meta["nazev"] problem.nazev = meta["nazev"]
if "body" in meta: problem.body = meta["body"]
problem.body = meta["body"]
problem.save() problem.save()
@ -624,3 +623,46 @@ def TexUploadView(request):
# Pošleme zpátky traceback, ať uživatel ví, v čem je problém # Pošleme zpátky traceback, ať uživatel ví, v čem je problém
tb = "".join(traceback.format_exception(type(e), e, sys.exc_info()[2])) tb = "".join(traceback.format_exception(type(e), e, sys.exc_info()[2]))
return JsonResponse({"error": tb}) return JsonResponse({"error": tb})
def texDownloadView(request, rocnik, cislo):
"""View posílající JSON se zadanými a řešenými problémy pro založení čísla
"""
cislo = Cislo.objects.get(rocnik__rocnik=rocnik, cislo=cislo)
zadane = Problem.objects.filter(
cislo_zadani=cislo,
stav=Problem.STAV_ZADANY
)
resene = Problem.objects.filter(
cislo_reseni=cislo,
stav=Problem.STAV_ZADANY,
typ=Problem.TYP_ULOHA
)
pred_pohadky = Pohadka.objects.filter(uloha__cislo_zadani=cislo, pred=True)
po_pohadky = Pohadka.objects.filter(uloha__cislo_zadani=cislo, pred=False)
response = {
"zadane": [
{
"nazev": p.nazev,
"typ": p.typ,
"kod": p.kod,
"body": p.body,
"zadani": p.text_zadani,
"pred_pohadky": [x.text for x in pred_pohadky.filter(uloha=p)],
"po_pohadky": [x.text for x in po_pohadky.filter(uloha=p)],
} for p in zadane
],
"resene": [
{
"nazev": p.nazev,
"typ": p.typ,
"kod": p.kod,
"body": p.body,
"zadani": p.text_zadani,
"reseni": p.text_reseni,
"cislo_zadani": p.cislo_zadani.cislo,
} for p in resene
],
}
return JsonResponse(response)

Loading…
Cancel
Save