diff --git a/src/bornhack/settings.py b/src/bornhack/settings.py index 27d6caf2..cf3ca436 100644 --- a/src/bornhack/settings.py +++ b/src/bornhack/settings.py @@ -1,12 +1,27 @@ import os +import wrapt +import django.views + from .environment_settings import * + def local_dir(entry): return os.path.join( os.path.dirname(os.path.dirname(__file__)), 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__)) WSGI_APPLICATION = 'bornhack.wsgi.application' diff --git a/src/requirements/production.txt b/src/requirements/production.txt index b44a6ece..f7c8dd10 100644 --- a/src/requirements/production.txt +++ b/src/requirements/production.txt @@ -37,3 +37,5 @@ six==1.10.0 sqlparse==0.2.2 venusian==1.0 webencodings==0.5 + +wrapt==1.10.11