Added and applied the current() method to Language in the Mia core application.
This commit is contained in:
parent
ef4c8ea2ae
commit
94884e72b8
@ -26,7 +26,7 @@ from django.core.serializers.json import DjangoJSONEncoder
|
|||||||
from django.template import defaultfilters
|
from django.template import defaultfilters
|
||||||
from django.utils import dateformat
|
from django.utils import dateformat
|
||||||
from django.utils.timezone import localdate
|
from django.utils.timezone import localdate
|
||||||
from django.utils.translation import gettext, get_language
|
from django.utils.translation import gettext
|
||||||
|
|
||||||
from mia_core.utils import Language
|
from mia_core.utils import Language
|
||||||
|
|
||||||
@ -78,7 +78,6 @@ class Period:
|
|||||||
month_picker_params (str): The month-picker parameters, as a
|
month_picker_params (str): The month-picker parameters, as a
|
||||||
JSON text string
|
JSON text string
|
||||||
"""
|
"""
|
||||||
_language = None
|
|
||||||
_data_start = None
|
_data_start = None
|
||||||
_data_end = None
|
_data_end = None
|
||||||
_period = None
|
_period = None
|
||||||
@ -88,7 +87,6 @@ class Period:
|
|||||||
self._period = self.Parser(spec)
|
self._period = self.Parser(spec)
|
||||||
self._data_start = data_start
|
self._data_start = data_start
|
||||||
self._data_end = data_end
|
self._data_end = data_end
|
||||||
self._language = Language(get_language())
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def spec(self):
|
def spec(self):
|
||||||
@ -308,7 +306,7 @@ class Period:
|
|||||||
return None
|
return None
|
||||||
start = date(self._data_start.year, self._data_start.month, 1)
|
start = date(self._data_start.year, self._data_start.month, 1)
|
||||||
return DjangoJSONEncoder().encode({
|
return DjangoJSONEncoder().encode({
|
||||||
"locale": self._language.locale,
|
"locale": Language.current().locale,
|
||||||
"minDate": start,
|
"minDate": start,
|
||||||
"maxDate": self._data_end,
|
"maxDate": self._data_end,
|
||||||
"defaultDate": self.chosen_month,
|
"defaultDate": self.chosen_month,
|
||||||
|
@ -56,6 +56,10 @@ class Language:
|
|||||||
def default():
|
def default():
|
||||||
return Language(settings.LANGUAGE_CODE)
|
return Language(settings.LANGUAGE_CODE)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def current():
|
||||||
|
return Language(get_language())
|
||||||
|
|
||||||
|
|
||||||
def get_multi_language_attr(model, name):
|
def get_multi_language_attr(model, name):
|
||||||
"""Returns a multi-language attribute of a data model.
|
"""Returns a multi-language attribute of a data model.
|
||||||
@ -68,7 +72,7 @@ def get_multi_language_attr(model, name):
|
|||||||
(any): The attribute in this language, or in the default
|
(any): The attribute in this language, or in the default
|
||||||
language if there is no content in the current language.
|
language if there is no content in the current language.
|
||||||
"""
|
"""
|
||||||
language = Language(get_language())
|
language = Language.current()
|
||||||
title = getattr(model, name + "_" + language.db)
|
title = getattr(model, name + "_" + language.db)
|
||||||
if language.is_default:
|
if language.is_default:
|
||||||
return title
|
return title
|
||||||
|
Loading…
x
Reference in New Issue
Block a user