Replace string_concat() with format_lazy()
On Django 1.11 django.utils.translation.string_concat() is deprecated in favor of django.utils.text.format_lazy() and it has been removed on Django 2.1
This commit is contained in:
parent
777a7f6de5
commit
d5fce3b6e2
|
@ -1,3 +1,7 @@
|
||||||
|
from django.utils.text import format_lazy
|
||||||
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
|
|
||||||
def get_chunks(porders, ini, end, ix=0):
|
def get_chunks(porders, ini, end, ix=0):
|
||||||
if ix >= len(porders):
|
if ix >= len(porders):
|
||||||
return [[ini, end, []]]
|
return [[ini, end, []]]
|
||||||
|
@ -41,10 +45,10 @@ class Interval(object):
|
||||||
self.ini = ini
|
self.ini = ini
|
||||||
self.end = end
|
self.end = end
|
||||||
self.order = order
|
self.order = order
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return max((self.end-self.ini).days, 0)
|
return max((self.end-self.ini).days, 0)
|
||||||
|
|
||||||
def __sub__(self, other):
|
def __sub__(self, other):
|
||||||
remaining = []
|
remaining = []
|
||||||
if self.ini < other.ini:
|
if self.ini < other.ini:
|
||||||
|
@ -52,13 +56,13 @@ class Interval(object):
|
||||||
if self.end > other.end:
|
if self.end > other.end:
|
||||||
remaining.append(Interval(max(self.ini,other.end), self.end, self.order))
|
remaining.append(Interval(max(self.ini,other.end), self.end, self.order))
|
||||||
return remaining
|
return remaining
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<ini:{ini}/end:{end}>".format(
|
return "<ini:{ini}/end:{end}>".format(
|
||||||
ini=self.ini.strftime('%Y-%-m-%-d'),
|
ini=self.ini.strftime('%Y-%-m-%-d'),
|
||||||
end=self.end.strftime('%Y-%-m-%-d')
|
end=self.end.strftime('%Y-%-m-%-d')
|
||||||
)
|
)
|
||||||
|
|
||||||
def intersect(self, other, remaining_self=None, remaining_other=None):
|
def intersect(self, other, remaining_self=None, remaining_other=None):
|
||||||
if remaining_self is not None:
|
if remaining_self is not None:
|
||||||
remaining_self += (self - other)
|
remaining_self += (self - other)
|
||||||
|
@ -69,7 +73,7 @@ class Interval(object):
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def intersect_set(self, others, remaining_self=None, remaining_other=None):
|
def intersect_set(self, others, remaining_self=None, remaining_other=None):
|
||||||
intersections = []
|
intersections = []
|
||||||
for interval in others:
|
for interval in others:
|
||||||
|
@ -130,3 +134,16 @@ def compensate(order, compensations):
|
||||||
for __, compensation in ordered_intersections:
|
for __, compensation in ordered_intersections:
|
||||||
remaining_compensations.append(compensation)
|
remaining_compensations.append(compensation)
|
||||||
return remaining_compensations, applied_compensations
|
return remaining_compensations, applied_compensations
|
||||||
|
|
||||||
|
|
||||||
|
def get_rate_methods_help_text(rate_class):
|
||||||
|
method_help_texts = [
|
||||||
|
format_lazy('{}' * 4, *['<br> ', method.verbose_name, ': ', method.help_text])
|
||||||
|
for method in rate_class.get_methods().values()
|
||||||
|
]
|
||||||
|
prefix = ugettext_lazy("Algorithm used to interprete the rating table.")
|
||||||
|
help_text_items = [prefix] + method_help_texts
|
||||||
|
return format_lazy(
|
||||||
|
'{}' * len(help_text_items),
|
||||||
|
*help_text_items
|
||||||
|
)
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
import calendar
|
import calendar
|
||||||
import decimal
|
import decimal
|
||||||
|
from orchestra.contrib.services import helpers
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.module_loading import autodiscover_modules
|
from django.utils.module_loading import autodiscover_modules
|
||||||
from django.utils.translation import string_concat, ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from orchestra.core import caches, validators
|
from orchestra.core import caches, validators
|
||||||
from orchestra.utils.python import import_class
|
from orchestra.utils.python import import_class
|
||||||
|
|
||||||
from . import settings
|
from . import settings
|
||||||
from .handlers import ServiceHandler
|
from .handlers import ServiceHandler
|
||||||
|
from .helpers import get_rate_methods_help_text
|
||||||
|
|
||||||
|
|
||||||
autodiscover_modules('handlers')
|
autodiscover_modules('handlers')
|
||||||
|
@ -145,13 +147,12 @@ class Service(models.Model):
|
||||||
(ANUAL, _("Anual data")),
|
(ANUAL, _("Anual data")),
|
||||||
),
|
),
|
||||||
default=BILLING_PERIOD)
|
default=BILLING_PERIOD)
|
||||||
rate_algorithm = models.CharField(_("rate algorithm"), max_length=64,
|
rate_algorithm = models.CharField(
|
||||||
|
_("rate algorithm"), max_length=64,
|
||||||
choices=rate_class.get_choices(),
|
choices=rate_class.get_choices(),
|
||||||
default=rate_class.get_default(),
|
default=rate_class.get_default(),
|
||||||
help_text=string_concat(_("Algorithm used to interprete the rating table."), *[
|
help_text=get_rate_methods_help_text(rate_class),
|
||||||
string_concat('<br> ', method.verbose_name, ': ', method.help_text)
|
)
|
||||||
for name, method in rate_class.get_methods().items()
|
|
||||||
]))
|
|
||||||
on_cancel = models.CharField(_("on cancel"), max_length=16,
|
on_cancel = models.CharField(_("on cancel"), max_length=16,
|
||||||
help_text=_("Defines the cancellation behaviour of this service."),
|
help_text=_("Defines the cancellation behaviour of this service."),
|
||||||
choices=(
|
choices=(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from django.utils.translation import string_concat
|
from django.utils.text import format_lazy
|
||||||
|
|
||||||
from ..utils.python import AttrDict
|
from ..utils.python import AttrDict
|
||||||
|
|
||||||
|
@ -7,16 +7,16 @@ class Register(object):
|
||||||
def __init__(self, verbose_name=None):
|
def __init__(self, verbose_name=None):
|
||||||
self._registry = {}
|
self._registry = {}
|
||||||
self.verbose_name = verbose_name
|
self.verbose_name = verbose_name
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
return key in self._registry
|
return key in self._registry
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self._registry[key]
|
return self._registry[key]
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self._registry.values())
|
return iter(self._registry.values())
|
||||||
|
|
||||||
def register(self, model, **kwargs):
|
def register(self, model, **kwargs):
|
||||||
if model in self._registry:
|
if model in self._registry:
|
||||||
raise KeyError("%s already registered" % model)
|
raise KeyError("%s already registered" % model)
|
||||||
|
@ -31,14 +31,15 @@ class Register(object):
|
||||||
}
|
}
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
self._registry[model] = AttrDict(**defaults)
|
self._registry[model] = AttrDict(**defaults)
|
||||||
|
|
||||||
def register_view(self, view_name, **kwargs):
|
def register_view(self, view_name, **kwargs):
|
||||||
if 'verbose_name' not in kwargs:
|
if 'verbose_name' not in kwargs:
|
||||||
raise KeyError("%s verbose_name is required for views" % view_name)
|
raise KeyError("%s verbose_name is required for views" % view_name)
|
||||||
if 'verbose_name_plural' not in kwargs:
|
if 'verbose_name_plural' not in kwargs:
|
||||||
kwargs['verbose_name_plural'] = string_concat(kwargs['verbose_name'], 's')
|
kwargs['verbose_name_plural'] = format_lazy('{}' * 2, *[kwargs['verbose_name'], 's'])
|
||||||
|
|
||||||
self.register(view_name, **kwargs)
|
self.register(view_name, **kwargs)
|
||||||
|
|
||||||
def get(self, *args):
|
def get(self, *args):
|
||||||
if args:
|
if args:
|
||||||
return self._registry[args[0]]
|
return self._registry[args[0]]
|
||||||
|
|
Loading…
Reference in a new issue