From 61b5e7f6f6016877a4d0ab93eaaabf2bf9b7e8c9 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@bioforsk.no> Date: Wed, 12 Nov 2014 13:26:29 +0100 Subject: [PATCH] Fixed message views --- messages/models.py | 16 ++++++++-------- messages/views.py | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/messages/models.py b/messages/models.py index ff2d4708..1ad23990 100644 --- a/messages/models.py +++ b/messages/models.py @@ -106,11 +106,11 @@ class Message: return messages @staticmethod - def get_messages(): + def get_messages(current_language=settings.VIPSLOGIC_LANGUAGE_CODE): messages = [] for item in Message.get_messages_as_json(): - message = Message.get_instance_from_dict(item) + message = Message.get_instance_from_dict(item, current_language) messages.append(message) return messages @@ -130,9 +130,9 @@ class Message: return request_result.json() @staticmethod - def get_instance_from_dict(the_dict): - message_locale = Message.get_message_locale(the_dict["messageLocaleSet"], settings.VIPSLOGIC_LANGUAGE_CODE) - message_illustration = Message.get_illustration(the_dict["messageIllustrationSet"], settings.VIPSLOGIC_LANGUAGE_CODE) + def get_instance_from_dict(the_dict,current_language=settings.VIPSLOGIC_LANGUAGE_CODE): + message_locale = Message.get_message_locale(the_dict["messageLocaleSet"], current_language) + message_illustration = Message.get_illustration(the_dict["messageIllustrationSet"], current_language) created_by = "" if message_locale.get("createdBy","") != "": created_by = "%s %s" %( @@ -143,9 +143,9 @@ class Message: return Message( the_dict["messageId"], the_dict["organizationId"], - message_locale.get("heading","MISSING HEADING FOR LOCALE '%s'" % settings.VIPSLOGIC_LANGUAGE_CODE), - message_locale.get("leadParagraph","MISSING LEAD PARAGRAPH FOR LOCALE '%s'" % settings.VIPSLOGIC_LANGUAGE_CODE), - message_locale.get("body","MISSING BODY TEXT FOR LOCALE '%s'" % settings.VIPSLOGIC_LANGUAGE_CODE), + message_locale.get("heading","MISSING HEADING FOR LOCALE '%s'" % current_language), + message_locale.get("leadParagraph","MISSING LEAD PARAGRAPH FOR LOCALE '%s'" % current_language), + message_locale.get("body","MISSING BODY TEXT FOR LOCALE '%s'" % current_language), datetime.strptime(the_dict["datePub"],settings.VIPSLOGIC_DATE_FORMAT) , datetime.strptime(the_dict["dateValidTo"],settings.VIPSLOGIC_DATE_FORMAT), message_illustration.get("file_name", None), diff --git a/messages/views.py b/messages/views.py index 3edbfaff..5f6d3778 100644 --- a/messages/views.py +++ b/messages/views.py @@ -17,12 +17,13 @@ # from django.shortcuts import render, get_object_or_404 +from django.utils import translation from messages.models import Message def index(request): context = { - 'messages' : Message.get_messages(), + 'messages' : Message.get_messages(translation.get_language()), } return render(request, 'messages/index.html', context) -- GitLab