forked from mysteryjeans/doorstep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
67 lines (49 loc) · 1.96 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from __future__ import unicode_literals
from django.views.generic import TemplateView
from doorsale.models import SysConfig
class BaseView(TemplateView):
"""
Base view for all Doorsale views
Provide site context variables from settings and apply decoractors to views
"""
# Pipeline CSS style package name
style_name = 'base'
# Base template to extend in drived views
base_template_name = 'doorsale/base.html'
# Decorators applied to generated view
decorators = []
def get_context_data(self, **kwargs):
context = super(BaseView, self).get_context_data(**kwargs)
# Settings context data for base template
context['request'] = self.request
context['style_name'] = self.style_name
context['base_template_name'] = self.base_template_name
context['SITE_NAME'] = self.get_config('SITE_NAME')
context['SITE_TITLE'] = self.get_config('SITE_TITLE')
context['SITE_DESCRIPTION'] = self.get_config('SITE_DESCRIPTION')
context['COPYRIGHT'] = self.get_config('COPYRIGHT')
context['SUPPORT_EMAIL'] = self.get_config('SUPPORT_EMAIL')
if hasattr(self, 'page_title'):
context['page_title'] = self.page_title
return context
@classmethod
def get_decorators(cls):
"""
Returns list of decorators defined as attribute of class
Generic base views should override get_decorators method instead of defining decorators attribute
"""
return cls.decorators
@classmethod
def as_view(cls, **initkwargs):
"""
Returns view function
Decorators will be applied defined at class level
"""
view = super(BaseView, cls).as_view(**initkwargs)
# Applying decorators to generated view
for decorator in cls.get_decorators():
view = decorator(view)
return view
@staticmethod
def get_config(name):
return SysConfig.get_config(name)