From cd13c5240afc9b37b87ecd819709698d863325d7 Mon Sep 17 00:00:00 2001 From: Maxime Bombar Date: Sat, 11 Aug 2018 15:24:58 +0200 Subject: [PATCH] Allows to display a French or English general message based on user's language choice. --- .../migrations/0048_auto_20180811_1515.py | 29 +++++++++++++++++++ preferences/models.py | 9 ++++-- re2o/context_processors.py | 6 +++- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 preferences/migrations/0048_auto_20180811_1515.py diff --git a/preferences/migrations/0048_auto_20180811_1515.py b/preferences/migrations/0048_auto_20180811_1515.py new file mode 100644 index 00000000..9e0b7e51 --- /dev/null +++ b/preferences/migrations/0048_auto_20180811_1515.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-08-11 13:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0047_mailcontact'), + ] + + operations = [ + migrations.RemoveField( + model_name='generaloption', + name='general_message', + ), + migrations.AddField( + model_name='generaloption', + name='general_message_en', + field=models.TextField(blank=True, default='', help_text='General message displayed on the English version of the website.'), + ), + migrations.AddField( + model_name='generaloption', + name='general_message_fr', + field=models.TextField(blank=True, default='', help_text='Message général affiché sur le site (maintenance, etc)'), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index 9226bd4a..ed4cd1e0 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -217,10 +217,15 @@ class GeneralOption(AclMixin, PreferencesModel): temps où les liens sont valides""" PRETTY_NAME = "Options générales" - general_message = models.TextField( + general_message_fr = models.TextField( default="", blank=True, - help_text="Message général affiché sur le site (maintenance, etc" + help_text="Message général affiché sur le site (maintenance, etc)" + ) + general_message_en = models.TextField( + default="", + blank=True, + help_text="General message displayed on the English version of the website." ) search_display_page = models.IntegerField(default=15) pagination_number = models.IntegerField(default=25) diff --git a/re2o/context_processors.py b/re2o/context_processors.py index ceb03be2..7cb965cc 100644 --- a/re2o/context_processors.py +++ b/re2o/context_processors.py @@ -28,13 +28,17 @@ import datetime from django.contrib import messages from preferences.models import GeneralOption, OptionalMachine +from django.utils.translation import get_language def context_user(request): """Fonction de context lorsqu'un user est logué (ou non), renvoie les infos sur l'user, la liste de ses droits, ses machines""" user = request.user - global_message = GeneralOption.get_cached_value('general_message') + if get_language()=='fr': + global_message = GeneralOption.get_cached_value('general_message_fr') + else: + global_message = GeneralOption.get_cached_value('general_message_en') if global_message: messages.warning(request, global_message) if user.is_authenticated():