|
|
|
@ -10,10 +10,22 @@ from django.template.loader import render_to_string
@@ -10,10 +10,22 @@ from django.template.loader import render_to_string
|
|
|
|
|
from benevalibre.accounts.models import User |
|
|
|
|
from benevalibre.instance.models import InstanceMessage |
|
|
|
|
|
|
|
|
|
from . import utils |
|
|
|
|
from .html import fa_icon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PageMixin: |
|
|
|
|
class BasePage: |
|
|
|
|
def get_instance_messages(self): |
|
|
|
|
return filter( |
|
|
|
|
lambda m: m.should_be_displayed(self.request.user), |
|
|
|
|
InstanceMessage.objects.exclude( |
|
|
|
|
id__in=utils.get_dismissed_instance_messages(self.request) |
|
|
|
|
) |
|
|
|
|
or [], |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PageMixin(BasePage): |
|
|
|
|
""" |
|
|
|
|
Mixin to apply to the views which render a page. It adds to the context a |
|
|
|
|
`page` object which ease the attributes definition and access. |
|
|
|
@ -57,12 +69,6 @@ class PageMixin:
@@ -57,12 +69,6 @@ class PageMixin:
|
|
|
|
|
""" |
|
|
|
|
return [] |
|
|
|
|
|
|
|
|
|
def get_instance_messages(self): |
|
|
|
|
return filter( |
|
|
|
|
lambda m: m.should_be_displayed(self.request.user), |
|
|
|
|
InstanceMessage.objects.all() or [] |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def get_page_context(self): |
|
|
|
|
"""Provide the context to by used for this page.""" |
|
|
|
|
return { |
|
|
|
@ -79,7 +85,7 @@ class PageMixin:
@@ -79,7 +85,7 @@ class PageMixin:
|
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CruditorPageMixin: |
|
|
|
|
class CruditorPageMixin(BasePage): |
|
|
|
|
""" |
|
|
|
|
Mixin to apply to the views based on `django-cruditor` - and which inherit |
|
|
|
|
from `cruditor.mixins.CruditorView`. It customizes and extends the default |
|
|
|
@ -113,12 +119,6 @@ class CruditorPageMixin:
@@ -113,12 +119,6 @@ class CruditorPageMixin:
|
|
|
|
|
cruditor['header_title'] = self.get_header_title() or cruditor['title'] |
|
|
|
|
return cruditor |
|
|
|
|
|
|
|
|
|
def get_instance_messages(self): |
|
|
|
|
return filter( |
|
|
|
|
lambda m: m.should_be_displayed(self.request.user), |
|
|
|
|
InstanceMessage.objects.all() or [] |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super().get_context_data(**kwargs) |
|
|
|
|
# Use the same values as cruditor for the page context. |
|
|
|
@ -127,7 +127,7 @@ class CruditorPageMixin:
@@ -127,7 +127,7 @@ class CruditorPageMixin:
|
|
|
|
|
**{ |
|
|
|
|
'tablebuttons': self.get_tablebuttons(), |
|
|
|
|
'instancemessages': self.get_instance_messages(), |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|