Revision 6dd9cc0b
b/snf-branding/synnefo_branding/utils.py | ||
---|---|---|
1 | 1 |
from synnefo_branding import settings |
2 | 2 |
from django.template.loader import render_to_string as django_render_to_string |
3 | 3 |
|
4 |
|
|
4 | 5 |
def get_branding_dict(prepend=None): |
5 |
dct = {} |
|
6 |
for key in dir(settings): |
|
7 |
if key == key.upper(): |
|
8 |
newkey = key.lower() |
|
9 |
if prepend: |
|
10 |
newkey = '%s_%s' % (prepend, newkey) |
|
11 |
dct[newkey.upper()] = getattr(settings, key) |
|
12 |
return dct |
|
6 |
dct = {} |
|
7 |
for key in dir(settings): |
|
8 |
if key == key.upper(): |
|
9 |
newkey = key.lower() |
|
10 |
if prepend: |
|
11 |
newkey = '%s_%s' % (prepend, newkey) |
|
12 |
dct[newkey.upper()] = getattr(settings, key) |
|
13 |
return dct |
|
14 |
|
|
13 | 15 |
|
14 | 16 |
def brand_message(msg, **extra_args): |
15 |
params = get_branding_dict() |
|
16 |
params.update(extra_args) |
|
17 |
return msg % params |
|
17 |
params = get_branding_dict() |
|
18 |
params.update(extra_args) |
|
19 |
return msg % params |
|
20 |
|
|
18 | 21 |
|
19 | 22 |
def render_to_string(template_name, dictionary=None, context_instance=None): |
20 |
if not dictionary: |
|
21 |
dictionary = {} |
|
22 |
newdict = get_branding_dict("BRANDING") |
|
23 |
newdict.update(dictionary) |
|
24 |
return django_render_to_string(template_name, newdict, context_instance) |
|
23 |
if not dictionary: |
|
24 |
dictionary = {} |
|
25 |
newdict = get_branding_dict("BRANDING") |
|
26 |
newdict.update(dictionary) |
|
27 |
return django_render_to_string(template_name, newdict, context_instance) |
Also available in: Unified diff