root / snf-branding / synnefo_branding / utils.py @ 9a7d0680
History | View | Annotate | Download (901 Bytes)
1 |
from synnefo_branding import settings |
---|---|
2 |
from django.template.loader import render_to_string as django_render_to_string |
3 |
|
4 |
|
5 |
def get_branding_dict(prepend=None): |
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 |
|
15 |
|
16 |
def brand_message(msg, **extra_args): |
17 |
params = get_branding_dict() |
18 |
params.update(extra_args) |
19 |
return msg % params
|
20 |
|
21 |
|
22 |
def render_to_string(template_name, dictionary=None, context_instance=None): |
23 |
if not dictionary: |
24 |
dictionary = {} |
25 |
if isinstance(dictionary, dict): |
26 |
newdict = get_branding_dict("BRANDING")
|
27 |
newdict.update(dictionary) |
28 |
else:
|
29 |
newdict = dictionary |
30 |
return django_render_to_string(template_name, newdict, context_instance)
|