Statistics
| Branch: | Tag: | Revision:

root / snf-branding / synnefo_branding / utils.py @ 6dd9cc0b

History | View | Annotate | Download (817 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
    newdict = get_branding_dict("BRANDING")
26
    newdict.update(dictionary)
27
    return django_render_to_string(template_name, newdict, context_instance)