2023-11-21 12:56:09 +00:00
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
2023-11-21 11:48:39 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from django.views.generic.base import ContextMixin
|
|
|
|
|
|
|
|
from orchestra import get_version
|
2023-11-21 12:56:09 +00:00
|
|
|
|
2023-11-21 11:48:39 +00:00
|
|
|
from . import api
|
|
|
|
from .auth import SESSION_KEY_TOKEN
|
|
|
|
|
|
|
|
|
|
|
|
class CustomContextMixin(ContextMixin):
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
# generate services menu items
|
|
|
|
services_menu = [
|
2024-06-19 11:41:34 +00:00
|
|
|
{'icon': 'home', 'pattern_name': 'musician:dashboard', 'title': _('Dashboard')},
|
|
|
|
{'icon': 'globe-europe', 'pattern_name': 'musician:domain-list', 'title': _('Domains')},
|
2023-11-21 11:48:39 +00:00
|
|
|
{'icon': 'envelope', 'pattern_name': 'musician:address-list', 'title': _('Mails')},
|
|
|
|
{'icon': 'mail-bulk', 'pattern_name': 'musician:mailing-lists', 'title': _('Mailing lists')},
|
|
|
|
{'icon': 'database', 'pattern_name': 'musician:database-list', 'title': _('Databases')},
|
|
|
|
{'icon': 'fire', 'pattern_name': 'musician:saas-list', 'title': _('SaaS')},
|
2024-04-29 19:01:51 +00:00
|
|
|
{'icon': 'globe', 'pattern_name': 'musician:website-list', 'title': _('Websites')},
|
|
|
|
{'icon': 'folder', 'pattern_name': 'musician:webapp-list', 'title': _('Webapps'), 'indent': True},
|
2024-05-03 07:12:55 +00:00
|
|
|
{'icon': 'user', 'pattern_name': 'musician:systemuser-list', 'title': _('Users'), 'indent': True},
|
2023-11-21 11:48:39 +00:00
|
|
|
]
|
|
|
|
context.update({
|
|
|
|
'services_menu': services_menu,
|
|
|
|
'version': get_version(),
|
|
|
|
'languages': settings.LANGUAGES,
|
|
|
|
})
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class ExtendedPaginationMixin:
|
|
|
|
paginate_by = 20
|
|
|
|
paginate_by_kwarg = 'per_page'
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context.update({
|
|
|
|
'per_page_values': [5, 10, 20, 50],
|
|
|
|
'per_page_param': self.paginate_by_kwarg,
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
def get_paginate_by(self, queryset):
|
|
|
|
per_page = self.request.GET.get(self.paginate_by_kwarg) or self.paginate_by
|
|
|
|
try:
|
|
|
|
paginate_by = int(per_page)
|
|
|
|
except ValueError:
|
|
|
|
paginate_by = self.paginate_by
|
|
|
|
return paginate_by
|
|
|
|
|
|
|
|
|
2023-11-21 12:56:09 +00:00
|
|
|
class UserTokenRequiredMixin(LoginRequiredMixin):
|
2023-11-21 11:48:39 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2023-11-22 10:56:09 +00:00
|
|
|
|
|
|
|
self.orchestra = api.OrchestraConnector(self.request)
|
2023-11-21 11:48:39 +00:00
|
|
|
context.update({
|
2023-11-22 10:56:09 +00:00
|
|
|
'profile': self.orchestra.retrieve_profile(),
|
2023-11-21 11:48:39 +00:00
|
|
|
})
|
|
|
|
return context
|