mirror of
https://github.com/nikdoof/vapemap.git
synced 2026-01-30 09:38:24 +00:00
Initial installation and mixins for django-waffle
This commit is contained in:
@@ -1,6 +1,42 @@
|
|||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from haystack.query import SearchQuerySet
|
from haystack.query import SearchQuerySet
|
||||||
from haystack.inputs import AutoQuery
|
from haystack.inputs import AutoQuery
|
||||||
|
from waffle import switch_is_active, flag_is_active
|
||||||
|
|
||||||
|
|
||||||
|
class WaffleSwitchMixin(object):
|
||||||
|
"""
|
||||||
|
Checks that as switch is active, or 404. Operates like the FBV decorator waffle_switch
|
||||||
|
"""
|
||||||
|
waffle_switch = None
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
if self.waffle_switch.startswith('!'):
|
||||||
|
active = not switch_is_active(self.waffle_switch[1:])
|
||||||
|
else:
|
||||||
|
active = switch_is_active(self.waffle_switch)
|
||||||
|
|
||||||
|
if not active:
|
||||||
|
raise Http404
|
||||||
|
return super(WaffleSwitchMixin, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class WaffleFlagMixin(object):
|
||||||
|
"""
|
||||||
|
Checks that as flag is active, or 404. Operates like the FBV decorator waffle_flag
|
||||||
|
"""
|
||||||
|
waffle_flag = None
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
if self.waffle_flag.startswith('!'):
|
||||||
|
active = not flag_is_active(request, self.waffle_flag[1:])
|
||||||
|
else:
|
||||||
|
active = flag_is_active(request, self.waffle_flag)
|
||||||
|
|
||||||
|
if not active:
|
||||||
|
raise Http404
|
||||||
|
return super(WaffleFlagMixin, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class EditorCheckMixin(object):
|
class EditorCheckMixin(object):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ INSTALLED_APPS = [
|
|||||||
'gunicorn',
|
'gunicorn',
|
||||||
'raven.contrib.django.raven_compat',
|
'raven.contrib.django.raven_compat',
|
||||||
'south',
|
'south',
|
||||||
|
'waffle',
|
||||||
'storages',
|
'storages',
|
||||||
'markdown_deux',
|
'markdown_deux',
|
||||||
'epiceditor',
|
'epiceditor',
|
||||||
@@ -88,6 +89,7 @@ MIDDLEWARE_CLASSES = [
|
|||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
|
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
|
||||||
|
'waffle.middleware.WaffleMiddleware',
|
||||||
]
|
]
|
||||||
|
|
||||||
TEMPLATE_CONTEXT_PROCESSORS += (
|
TEMPLATE_CONTEXT_PROCESSORS += (
|
||||||
|
|||||||
@@ -18,4 +18,5 @@ gevent
|
|||||||
psycopg2
|
psycopg2
|
||||||
django-storages
|
django-storages
|
||||||
boto
|
boto
|
||||||
raven>=3
|
raven>=3
|
||||||
|
django-waffle>=0.9.1
|
||||||
Reference in New Issue
Block a user