|
|
@ -5,6 +5,7 @@ import datetime |
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
from django.contrib.auth.decorators import permission_required |
|
|
|
from html.parser import HTMLParser |
|
|
|
from django import views as DjangoViews |
|
|
|
|
|
|
|
from django.contrib.auth.models import AnonymousUser |
|
|
|
from django.contrib.contenttypes.models import ContentType |
|
|
@ -191,3 +192,30 @@ def aktivniResitele(cislo, pouze_letosni=False): |
|
|
|
else: |
|
|
|
# spojíme querysety s řešiteli loni a letos do daného čísla |
|
|
|
return (resi_v_rocniku(loni) | resi_v_rocniku(letos, cislo)).distinct() |
|
|
|
|
|
|
|
def viewMethodSwitch(get, post): |
|
|
|
""" |
|
|
|
Vrátí view, který zavolá různé jiné views podle toho, kterou metodou je zavolán. |
|
|
|
|
|
|
|
Inspirováno https://docs.djangoproject.com/en/3.1/topics/class-based-views/mixins/#an-alternative-better-solution, jen jsem to udělal genericky. |
|
|
|
|
|
|
|
Parametry: |
|
|
|
post view pro metodu POST |
|
|
|
get view pro metodu GET |
|
|
|
|
|
|
|
V obou případech se míní už view jakožto funkce, takže u class-based views se už má použít .as_view() |
|
|
|
|
|
|
|
TODO: Podpora i pro metodu HEAD? A možná i pro FILES? |
|
|
|
""" |
|
|
|
|
|
|
|
theGetView = get |
|
|
|
thePostView = post |
|
|
|
|
|
|
|
class NewView(DjangoViews.View): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
return theGetView(request, *args, **kwargs) |
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
return thePostView(request, *args, **kwargs) |
|
|
|
|
|
|
|
return NewView.as_view() |
|
|
|
|
|
|
|