Introduce wrapt and monkeypatch django.views.View so we have a setup method to override. (#279)
This commit is contained in:
parent
9b2640ea07
commit
0a81a88e93
|
@ -1,12 +1,27 @@
|
||||||
import os
|
import os
|
||||||
|
import wrapt
|
||||||
|
import django.views
|
||||||
|
|
||||||
from .environment_settings import *
|
from .environment_settings import *
|
||||||
|
|
||||||
|
|
||||||
def local_dir(entry):
|
def local_dir(entry):
|
||||||
return os.path.join(
|
return os.path.join(
|
||||||
os.path.dirname(os.path.dirname(__file__)),
|
os.path.dirname(os.path.dirname(__file__)),
|
||||||
entry
|
entry
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# We do this hacky monkeypatching to enable us to define a setup method
|
||||||
|
# on class based views for setting up variables without touching the dispatch
|
||||||
|
# method.
|
||||||
|
@wrapt.patch_function_wrapper(django.views.View, 'dispatch')
|
||||||
|
def monkey_patched_dispatch(wrapped, instance, args, kwargs):
|
||||||
|
if hasattr(instance, 'setup'):
|
||||||
|
instance.setup(*args, **kwargs)
|
||||||
|
return wrapped(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
DJANGO_BASE_PATH = os.path.dirname(os.path.dirname(__file__))
|
DJANGO_BASE_PATH = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
|
||||||
WSGI_APPLICATION = 'bornhack.wsgi.application'
|
WSGI_APPLICATION = 'bornhack.wsgi.application'
|
||||||
|
|
|
@ -37,3 +37,5 @@ six==1.10.0
|
||||||
sqlparse==0.2.2
|
sqlparse==0.2.2
|
||||||
venusian==1.0
|
venusian==1.0
|
||||||
webencodings==0.5
|
webencodings==0.5
|
||||||
|
|
||||||
|
wrapt==1.10.11
|
||||||
|
|
Loading…
Reference in a new issue