0004-utils-add-a-lazy_label-helper-30252.patch
src/authentic2/utils.py | ||
---|---|---|
3 | 3 |
import time |
4 | 4 |
import logging |
5 | 5 |
import urllib |
6 |
import six |
|
7 | 6 |
import urlparse |
8 | 7 |
import uuid |
9 | 8 |
import datetime |
... | ... | |
24 | 23 |
from django import forms |
25 | 24 |
from django.forms.utils import ErrorList, to_current_timezone |
26 | 25 |
from django.utils import timezone |
27 |
from django.utils import html, http |
|
26 |
from django.utils import html, http, six, encoding
|
|
28 | 27 |
from django.utils.translation import ugettext as _, ungettext |
29 | 28 |
from django.shortcuts import resolve_url |
30 | 29 |
from django.template.loader import render_to_string, TemplateDoesNotExist |
... | ... | |
33 | 32 |
from django.core.urlresolvers import reverse, NoReverseMatch |
34 | 33 |
from django.utils.formats import localize |
35 | 34 |
from django.contrib import messages |
36 |
from django.utils.functional import empty |
|
35 |
from django.utils.functional import empty, allow_lazy
|
|
37 | 36 |
from django.utils.http import urlsafe_base64_encode |
38 | 37 |
from django.utils.encoding import iri_to_uri, force_bytes, uri_to_iri |
39 | 38 |
from django.shortcuts import render |
... | ... | |
1085 | 1084 |
if can is False: |
1086 | 1085 |
return can |
1087 | 1086 |
return True |
1087 | ||
1088 | ||
1089 |
def lazy_label(default, func): |
|
1090 |
'''Allow using a getter for a label, with late binding. |
|
1091 | ||
1092 |
ex.: lazy_label(_('Default label'), lambda: app_settings.CUSTOM_LABEL) |
|
1093 |
''' |
|
1094 |
return encoding.force_text(func() or default) |
|
1095 |
lazy_label = allow_lazy(lazy_label, six.text_type) |
|
1088 |
- |