8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Merge branch 'translate_global_msg' into 'dev'

Allows to display a French or English general message based on user's language choice.

See merge request federez/re2o!252
This commit is contained in:
chirac 2018-08-12 18:13:00 +02:00
commit 6b484da4d3
3 changed files with 42 additions and 3 deletions

View file

@ -0,0 +1,30 @@
# -*- 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.RenameField(
model_name='generaloption',
old_name='general_message',
new_name='general_message_fr',
),
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.AlterField(
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)'),
),
]

View file

@ -217,10 +217,15 @@ class GeneralOption(AclMixin, PreferencesModel):
temps 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)

View file

@ -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():