diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index a7d15679..3e71c817 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -503,5 +503,9 @@ with this program; if not, write to the Free Software Foundation, Inc., +{% for template in optionnal_templates_list %} + {{ template }} +{% endfor %} + {% endblock %} diff --git a/preferences/views.py b/preferences/views.py index ecb3826e..471207e0 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -40,6 +40,8 @@ from django.utils.translation import ugettext as _ from reversion import revisions as reversion +from importlib import import_module +from re2o.settings_local import OPTIONNAL_APPS_RE2O from re2o.views import form from re2o.acl import can_create, can_edit, can_delete_set, can_view_all, can_delete @@ -94,6 +96,10 @@ def display_options(request): radiusoptions, _ = RadiusOption.objects.get_or_create() cotisationsoptions, _created = CotisationsOption.objects.get_or_create() document_template_list = DocumentTemplate.objects.order_by('name') + + optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS_RE2O] + optionnal_templates_list = [app.views.preferences(request) for app in optionnal_apps] + return form({ 'useroptions': useroptions, 'machineoptions': machineoptions, @@ -109,6 +115,7 @@ def display_options(request): 'switchmanagementcred_list': switchmanagementcred_list, 'radiusoptions' : radiusoptions, 'cotisationsoptions': cotisationsoptions, + 'optionnal_templates_list': optionnal_templates_list, 'document_template_list': document_template_list, }, 'preferences/display_preferences.html', request) diff --git a/re2o/context_processors.py b/re2o/context_processors.py index 6beac564..67a700be 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_RE2O def context_user(request): """Fonction de context lorsqu'un user est logué (ou non), @@ -57,6 +58,15 @@ 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_RE2O] + optionnal_templates_navbar_user_list = [app.views.navbar_user(request) for app in optionnal_apps] + optionnal_templates_navbar_logout_list = [app.views.navbar_logout(request) for app in optionnal_apps] + return {'optionnal_templates_navbar_user_list':optionnal_templates_navbar_user_list, + 'optionnal_templates_navbar_logout_list':optionnal_templates_navbar_logout_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 f2557b44..ee219cfa 100644 --- a/re2o/settings.py +++ b/re2o/settings.py @@ -62,6 +62,7 @@ DJANGO_CONTRIB_APPS = ( 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django.contrib.humanize', ) EXTERNAL_CONTRIB_APPS = ( 'bootstrap3', @@ -131,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/re2o/settings_local.example.py b/re2o/settings_local.example.py index 662c1447..bb0fd21e 100644 --- a/re2o/settings_local.example.py +++ b/re2o/settings_local.example.py @@ -108,5 +108,8 @@ GID_RANGES = { 'posix': [501, 600], } +# Some optionnal Re2o Apps +OPTIONNAL_APPS_RE2O = () + # Some Django apps you want to add in you local project -OPTIONNAL_APPS = () +OPTIONNAL_APPS = OPTIONNAL_APPS_RE2O + () diff --git a/re2o/templates/re2o/contact.html b/re2o/templates/re2o/contact.html index b20fe875..05b34655 100644 --- a/re2o/templates/re2o/contact.html +++ b/re2o/templates/re2o/contact.html @@ -31,6 +31,10 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block content %}

{% blocktrans %}Contact the organisation {{asso_name}}{% endblocktrans %}


+ +{% for template in optionnal_templates_contact_list %} + {{template}} +{% endfor %} {% for contact in contacts %} diff --git a/re2o/urls.py b/re2o/urls.py index 37497572..8af7335a 100644 --- a/re2o/urls.py +++ b/re2o/urls.py @@ -49,6 +49,8 @@ from django.contrib import admin from django.utils.translation import gettext_lazy as _ from django.views.generic import RedirectView +from .settings_local import OPTIONNAL_APPS_RE2O + from .views import index, about_page, contact_page # Admin site configuration @@ -83,6 +85,10 @@ urlpatterns = [ url(r'^admin/login/$', RedirectView.as_view(pattern_name='login')), url(r'^admin/', include(admin.site.urls)), ] + + +urlpatterns += [url(r'^{}/'.format(app), include('{}.urls'.format(app), namespace=app)) for app in OPTIONNAL_APPS_RE2O] + # Add debug_toolbar URLs if activated if 'debug_toolbar' in settings.INSTALLED_APPS: import debug_toolbar diff --git a/re2o/views.py b/re2o/views.py index aa85e997..17622fd5 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -43,6 +43,8 @@ from preferences.models import ( ) from .contributors import CONTRIBUTORS +from importlib import import_module +from re2o.settings_local import OPTIONNAL_APPS_RE2O def form(ctx, template, request): @@ -113,12 +115,16 @@ def contact_page(request): """ address = MailContact.objects.all() + optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS_RE2O] + optionnal_templates_contact_list = [app.views.contact(request) for app in optionnal_apps] + return render( request, "re2o/contact.html", { 'contacts': address, - 'asso_name': AssoOption.objects.first().name + 'asso_name': AssoOption.objects.first().name, + 'optionnal_templates_contact_list':optionnal_templates_contact_list, } ) diff --git a/templates/base.html b/templates/base.html index e58950ab..7a2074f2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -100,6 +100,10 @@ with this program; if not, write to the Free Software Foundation, Inc., {% can_view_app cotisations %}
  • {% trans "Manage the subscriptions" %}
  • {% acl_end %} + + {% for template in optionnal_templates_navbar_user_list%} + {{ template }} + {% endfor %} {% acl_end %} @@ -126,13 +130,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,