From 8ccffcf02cd5ba8352bc8182d7be13ea015332ca Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 24 Jan 2016 00:22:59 +0530 Subject: [PATCH] Add utility method to lazy format lazy string This method is useful to format strings that are lazy (such as those in Forms). --- plinth/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plinth/utils.py b/plinth/utils.py index edb76adc1..a8995332b 100644 --- a/plinth/utils.py +++ b/plinth/utils.py @@ -20,6 +20,7 @@ Miscelleneous utility method. """ import importlib +from django.utils.functional import lazy def import_from_gi(library, version): @@ -34,3 +35,12 @@ def import_from_gi(library, version): package.require_version(library, version) return importlib.import_module(package_name + '.repository.' + library) + + +def _format_lazy(string, *args, **kwargs): + """Lazily format a lazy string.""" + string = str(string) + return string.format(*args, **kwargs) + + +format_lazy = lazy(_format_lazy, str)