Revision a2110608 snf-branding/synnefo_branding/utils.py
b/snf-branding/synnefo_branding/utils.py | ||
---|---|---|
1 | 1 |
from synnefo_branding import settings |
2 |
from django.template.loader import render_to_string as django_render_to_string |
|
2 | 3 |
|
3 |
def get_branding_dict(): |
|
4 |
def get_branding_dict(prepend=None):
|
|
4 | 5 |
dct = {} |
5 | 6 |
for key in dir(settings): |
6 | 7 |
if key == key.upper(): |
7 |
dct[key.lower()] = getattr(settings, key) |
|
8 |
newkey = key.lower() |
|
9 |
if prepend: |
|
10 |
newkey = '%s_%s' % (prepend, newkey) |
|
11 |
dct[newkey.upper()] = getattr(settings, key) |
|
8 | 12 |
return dct |
9 | 13 |
|
10 | 14 |
def brand_message(msg, **extra_args): |
11 | 15 |
params = get_branding_dict() |
12 | 16 |
params.update(extra_args) |
13 | 17 |
return msg % params |
18 |
|
|
19 |
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) |
Also available in: Unified diff