Compare commits
2 commits
d55199d6ae
...
be8c9810e4
Author | SHA1 | Date | |
---|---|---|---|
be8c9810e4 | |||
47894ce335 |
5 changed files with 32 additions and 23 deletions
|
@ -54,7 +54,7 @@ SESSION_EXPIRE_AT_BROWSER_CLOSE = True
|
||||||
DOBA_ODHLASENI_PRI_ZASKRTNUTI_NEODHLASOVAT = 365 * 24 * 3600 # rok
|
DOBA_ODHLASENI_PRI_ZASKRTNUTI_NEODHLASOVAT = 365 * 24 * 3600 # rok
|
||||||
|
|
||||||
# View pro chybu s CSRF tokenem (např. se sušenkami)
|
# View pro chybu s CSRF tokenem (např. se sušenkami)
|
||||||
CSRF_FAILURE_VIEW = 'various.views.csrf_error'
|
CSRF_FAILURE_VIEW = 'various.views.csrf.csrf_error'
|
||||||
|
|
||||||
# Modules configuration
|
# Modules configuration
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.contrib.staticfiles.finders import find
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
import various.views
|
import various.views.generic
|
||||||
from seminar.views import obalkyView
|
from seminar.views import obalkyView
|
||||||
|
|
||||||
from .models import Soustredeni, Soustredeni_Ucastnici
|
from .models import Soustredeni, Soustredeni_Ucastnici
|
||||||
|
@ -38,7 +38,10 @@ class KonkretniSoustredeniMixin:
|
||||||
self.soustredeni = get_object_or_404(Soustredeni, id=soustredeni_id)
|
self.soustredeni = get_object_or_404(Soustredeni, id=soustredeni_id)
|
||||||
|
|
||||||
|
|
||||||
class SoustredeniUcastniciBaseView(KonkretniSoustredeniMixin, various.views.NeprazdnyListView):
|
class SoustredeniUcastniciBaseView(
|
||||||
|
KonkretniSoustredeniMixin,
|
||||||
|
various.views.generic.NeprazdnyListView,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Slouží jako ListView účastníků soustředění
|
Slouží jako ListView účastníků soustředění
|
||||||
+ háže inteligentní chybu při soustředění bez účastníků
|
+ háže inteligentní chybu při soustředění bez účastníků
|
||||||
|
@ -82,7 +85,10 @@ class SoustredeniUcastniciExportView(SoustredeniUcastniciBaseView):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class SoustredeniStvrzenkyView(various.views.TeXResponseMixin, SoustredeniUcastniciBaseView):
|
class SoustredeniStvrzenkyView(
|
||||||
|
various.views.generic.TeXResponseMixin,
|
||||||
|
SoustredeniUcastniciBaseView,
|
||||||
|
):
|
||||||
template_name = 'soustredeni/stvrzenky.tex'
|
template_name = 'soustredeni/stvrzenky.tex'
|
||||||
dalsi_potrebne_soubory = [find('images/logomm.pdf')]
|
dalsi_potrebne_soubory = [find('images/logomm.pdf')]
|
||||||
|
|
||||||
|
|
0
various/views/__init__.py
Normal file
0
various/views/__init__.py
Normal file
11
various/views/csrf.py
Normal file
11
various/views/csrf.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from django.http import HttpResponseForbidden
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
|
||||||
|
def csrf_error(request, reason=""):
|
||||||
|
""" Jednoduchý „template view“ (třída to být nemůže) pro CSRF chyby """
|
||||||
|
return render(
|
||||||
|
request, 'various/403_csrf.html',
|
||||||
|
{"url": request.META.get("HTTP_REFERER", None), "reason": reason},
|
||||||
|
status=HttpResponseForbidden.status_code,
|
||||||
|
)
|
|
@ -1,23 +1,19 @@
|
||||||
|
"""
|
||||||
|
Stejně jako je `django.views.generic` jsou zde generické Views
|
||||||
|
a pár mixinů, které upravují chování Views.
|
||||||
|
"""
|
||||||
|
|
||||||
import http
|
import http
|
||||||
import tempfile
|
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from django.http import HttpResponseForbidden, HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.views import generic
|
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
from django.views import generic
|
||||||
|
|
||||||
def csrf_error(request, reason=""):
|
|
||||||
""" Jednoduchý „template view“ (třída to být nemůže) pro CSRF chyby """
|
|
||||||
return render(
|
|
||||||
request, 'various/403_csrf.html',
|
|
||||||
{"url": request.META.get("HTTP_REFERER", None), "reason": reason},
|
|
||||||
status=HttpResponseForbidden.status_code,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class NeprazdnyListView(generic.ListView):
|
class NeprazdnyListView(generic.ListView):
|
||||||
|
@ -45,9 +41,7 @@ class NeprazdnyListView(generic.ListView):
|
||||||
return render(request, 'universal.html', {
|
return render(request, 'universal.html', {
|
||||||
'title': self.if_prazdny_title,
|
'title': self.if_prazdny_title,
|
||||||
'text': self.if_prazdny_text,
|
'text': self.if_prazdny_text,
|
||||||
},
|
}, status=http.HTTPStatus.NOT_FOUND)
|
||||||
status=http.HTTPStatus.NOT_FOUND,
|
|
||||||
)
|
|
||||||
|
|
||||||
return self.render(request, *args, **kwargs)
|
return self.render(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -81,5 +75,3 @@ class TeXResponseMixin:
|
||||||
with open(tempdir / "main.pdf", "rb") as pdffile:
|
with open(tempdir / "main.pdf", "rb") as pdffile:
|
||||||
response = HttpResponse(pdffile.read(), content_type='application/pdf', **response_kwargs)
|
response = HttpResponse(pdffile.read(), content_type='application/pdf', **response_kwargs)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue