|
|
|
|
@@ -57,54 +57,13 @@ def user_processor(request, context):
|
|
|
|
|
context['user_group'] = request.user.groups.first()
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
class WebsiteTemplateMixin(TemplateResponseMixin):
|
|
|
|
|
""" Mixin for easy integration of 'website' templates
|
|
|
|
|
|
|
|
|
|
Each child can specify:
|
|
|
|
|
- title : title of the page
|
|
|
|
|
- header : header of the page
|
|
|
|
|
- header_small : sub-header of the page
|
|
|
|
|
|
|
|
|
|
If 'content_template' is not defined, value will fallback to template_name
|
|
|
|
|
in child view.
|
|
|
|
|
"""
|
|
|
|
|
base_template = "base_site.html"
|
|
|
|
|
content_template = None
|
|
|
|
|
class NavbarMixin(object):
|
|
|
|
|
|
|
|
|
|
registered_apps = ['maraudes', 'suivi']
|
|
|
|
|
app_name = None
|
|
|
|
|
_user_menu = []
|
|
|
|
|
_admin_menu = []
|
|
|
|
|
_groups = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Configuration:
|
|
|
|
|
stylesheets = ['base.css']
|
|
|
|
|
navbar_apps = ['maraudes', 'suivi']
|
|
|
|
|
page_blocks = ['header', 'header_small', 'title']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
self.user = None
|
|
|
|
|
self._page_blocks = []
|
|
|
|
|
if not hasattr(self, "PageInfo"):
|
|
|
|
|
raise ImproperlyConfigured("You must define a PageInfo on ", self)
|
|
|
|
|
for attr, val in self.PageInfo.__dict__.items():
|
|
|
|
|
if attr[0] is not "_" and type(val) is str:
|
|
|
|
|
setattr(self, attr, Template(val))
|
|
|
|
|
self._page_blocks.append(attr)
|
|
|
|
|
|
|
|
|
|
def get_template_names(self):
|
|
|
|
|
""" Ensure same template for all children views. """
|
|
|
|
|
return [self.base_template]
|
|
|
|
|
|
|
|
|
|
def get_content_template(self):
|
|
|
|
|
# Ensure easy integration with generic views
|
|
|
|
|
if hasattr(self, 'template_name'):
|
|
|
|
|
self.content_template = self.template_name
|
|
|
|
|
else:
|
|
|
|
|
raise ImproperlyConfigured(self, "has no template defined !")
|
|
|
|
|
return self.content_template
|
|
|
|
|
|
|
|
|
|
def get_apps_config(self):
|
|
|
|
|
""" Load additionnal config data on each app registered in navbar
|
|
|
|
|
@@ -117,7 +76,7 @@ class WebsiteTemplateMixin(TemplateResponseMixin):
|
|
|
|
|
'maraudes': 'road',
|
|
|
|
|
'suivi': 'eye-open',
|
|
|
|
|
}
|
|
|
|
|
app_names = self.Configuration.navbar_apps
|
|
|
|
|
app_names = self.registered_apps
|
|
|
|
|
self._apps = []
|
|
|
|
|
for name in app_names:
|
|
|
|
|
app_config = apps.get_app_config(name)
|
|
|
|
|
@@ -162,6 +121,55 @@ class WebsiteTemplateMixin(TemplateResponseMixin):
|
|
|
|
|
return self._user_menu + self._admin_menu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WebsiteTemplateMixin(NavbarMixin, TemplateResponseMixin):
|
|
|
|
|
""" Mixin for easy integration of 'website' templates
|
|
|
|
|
|
|
|
|
|
Each child can specify:
|
|
|
|
|
- title : title of the page
|
|
|
|
|
- header : header of the page
|
|
|
|
|
- header_small : sub-header of the page
|
|
|
|
|
|
|
|
|
|
If 'content_template' is not defined, value will fallback to template_name
|
|
|
|
|
in child view.
|
|
|
|
|
"""
|
|
|
|
|
base_template = "base_site.html"
|
|
|
|
|
content_template = None
|
|
|
|
|
|
|
|
|
|
_user_menu = []
|
|
|
|
|
_admin_menu = []
|
|
|
|
|
_groups = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Configuration:
|
|
|
|
|
stylesheets = ['base.css']
|
|
|
|
|
page_blocks = ['header', 'header_small', 'title']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
self.user = None
|
|
|
|
|
self._page_blocks = []
|
|
|
|
|
if not hasattr(self, "PageInfo"):
|
|
|
|
|
raise ImproperlyConfigured("You must define a PageInfo on ", self)
|
|
|
|
|
for attr, val in self.PageInfo.__dict__.items():
|
|
|
|
|
if attr[0] is not "_" and type(val) is str:
|
|
|
|
|
setattr(self, attr, Template(val))
|
|
|
|
|
self._page_blocks.append(attr)
|
|
|
|
|
|
|
|
|
|
def get_template_names(self):
|
|
|
|
|
""" Ensure same template for all children views. """
|
|
|
|
|
return [self.base_template]
|
|
|
|
|
|
|
|
|
|
def get_content_template(self):
|
|
|
|
|
# Ensure easy integration with generic views
|
|
|
|
|
if hasattr(self, 'template_name'):
|
|
|
|
|
self.content_template = self.template_name
|
|
|
|
|
else:
|
|
|
|
|
raise ImproperlyConfigured(self, "has no template defined !")
|
|
|
|
|
return self.content_template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _update_context_with_rendered_blocks(self, context):
|
|
|
|
|
""" Render text for existing PageInfo attributes.
|
|
|
|
|
See Configuration.page_blocks for valid attribute names """
|
|
|
|
|
@@ -205,9 +213,4 @@ class WebsiteAjaxTemplateMixin(WebsiteTemplateMixin):
|
|
|
|
|
return [self.ajax_template]
|
|
|
|
|
return super().get_template_names()
|
|
|
|
|
|
|
|
|
|
class WebsiteProtectedMixin(WebsiteTemplateMixin, PermissionRequiredMixin):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
class WebsiteProtectedWithAjaxMixin(WebsiteAjaxTemplateMixin, PermissionRequiredMixin):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|