Přesunutí "switche view podle GET/POST" ze seminar.utils do various.utils
This commit is contained in:
parent
15b17023de
commit
9c68eac050
3 changed files with 30 additions and 29 deletions
|
@ -2,7 +2,7 @@ from django.urls import path
|
||||||
|
|
||||||
from personalni.utils import org_required, resitel_required, \
|
from personalni.utils import org_required, resitel_required, \
|
||||||
resitel_or_org_required
|
resitel_or_org_required
|
||||||
from seminar.utils import viewMethodSwitch
|
from various.utils import viewMethodSwitch
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
from django import views as DjangoViews
|
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
|
@ -98,30 +97,3 @@ def seznam_problemu():
|
||||||
node = t.get_parent(node)
|
node = t.get_parent(node)
|
||||||
|
|
||||||
return problemy
|
return problemy
|
||||||
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from django import views as DjangoViews
|
||||||
|
|
||||||
bez_diakritiky = ({}
|
bez_diakritiky = ({}
|
||||||
# FIXME: funguje jen pro český a slovenský text, jinak jsou špatně
|
# FIXME: funguje jen pro český a slovenský text, jinak jsou špatně
|
||||||
# transliterace. Potenciální řešení:
|
# transliterace. Potenciální řešení:
|
||||||
|
@ -52,3 +54,30 @@ def from_roman(rom):
|
||||||
if rom.upper().startswith(n):
|
if rom.upper().startswith(n):
|
||||||
return i + from_roman(rom[len(n):])
|
return i + from_roman(rom[len(n):])
|
||||||
raise Exception('Invalid roman numeral: "%s"', rom)
|
raise Exception('Invalid roman numeral: "%s"', rom)
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
Loading…
Reference in a new issue