From 6440ac48e86ee8aaf5d74e9cb8cf58b1e047e2d0 Mon Sep 17 00:00:00 2001 From: Grizzly Date: Sat, 10 Aug 2019 17:25:21 +0000 Subject: [PATCH] =?UTF-8?q?Inclusion=20des=20apps=20optionnels=20dans=20le?= =?UTF-8?q?=20navbar=20(je=20sais=20pas=20trop=20pourquoi=20=C3=A7a=20marc?= =?UTF-8?q?he=20=C3=A7a=20risque=20de=20casser)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- re2o/context_processors.py | 10 +++++++++- re2o/settings.py | 1 + templates/base.html | 6 +++--- tickets/views.py | 5 +++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/re2o/context_processors.py b/re2o/context_processors.py index 6beac564..739f4ab8 100644 --- a/re2o/context_processors.py +++ b/re2o/context_processors.py @@ -29,7 +29,8 @@ from django.contrib import messages from django.http import HttpRequest from preferences.models import GeneralOption, OptionalMachine from django.utils.translation import get_language - +from importlib import import_module +from re2o.settings_local import OPTIONNAL_APPS def context_user(request): """Fonction de context lorsqu'un user est logué (ou non), @@ -57,6 +58,13 @@ def context_user(request): 'ipv6_enabled': OptionalMachine.get_cached_value('ipv6'), } +def context_optionnal_apps(request): + """Fonction de context pour générer la navbar en fonction des + apps optionnels""" + optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS] + optionnal_templates_navbar_list = [app.views.navbar(request) for app in optionnal_apps] + return {'optionnal_templates_navbar_list':optionnal_templates_navbar_list} + def date_now(request): """Add the current date in the context for quick informations and diff --git a/re2o/settings.py b/re2o/settings.py index 14907570..ee219cfa 100644 --- a/re2o/settings.py +++ b/re2o/settings.py @@ -132,6 +132,7 @@ TEMPLATES = [ 'django.contrib.messages.context_processors.messages', 'django.template.context_processors.request', 're2o.context_processors.context_user', + 're2o.context_processors.context_optionnal_apps', 're2o.context_processors.date_now', ], }, diff --git a/templates/base.html b/templates/base.html index 6d39f8c8..67799c28 100644 --- a/templates/base.html +++ b/templates/base.html @@ -101,9 +101,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
  • {% trans "Manage the subscriptions" %}
  • {% acl_end %} - {% comment %} -
  • {% trans "Tickets" %}
  • - {% endcomment %} + {% for template in optionnal_templates_navbar_list%} + {{ template }} + {% endfor %} {% acl_end %} diff --git a/tickets/views.py b/tickets/views.py index f75b1766..e4ffda89 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -1,6 +1,7 @@ from django.contrib import messages from django.shortcuts import render, redirect from django.template.loader import render_to_string +from django.views.decorators.cache import cache_page from django.urls import reverse from django.forms import modelformset_factory from re2o.views import form @@ -128,3 +129,7 @@ def preferences(request): preferences = Preferences.objects.first() context = {'preferences':preferences} return render_to_string('tickets/preferences.html', context=context, request=request, using=None) + +def navbar(request): + """Vue cannonique d'affichage des tickets dans la navbar""" + return render_to_string('tickets/navbar.html')