0001-misc-drop-unused-template-variable-model-31205.patch
passerelle/base/admin.py | ||
---|---|---|
1 | 1 |
from django.contrib import admin |
2 | 2 | |
3 |
from .models import ApiUser, TemplateVar, AccessRight
|
|
3 |
from .models import ApiUser, AccessRight |
|
4 | 4 | |
5 | 5 |
admin.site.register(ApiUser) |
6 |
admin.site.register(TemplateVar) |
|
7 | 6 |
admin.site.register(AccessRight) |
passerelle/base/context_processors.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 | ||
3 |
from django.conf import settings |
|
4 |
from .models import TemplateVar |
|
5 | ||
6 |
def template_vars(request): |
|
7 |
""" |
|
8 |
returns a dict with all the template vars, build from settings and database |
|
9 |
""" |
|
10 |
vars = {} |
|
11 |
if hasattr(settings, 'TEMPLATE_VARS'): |
|
12 |
vars.update(settings.TEMPLATE_VARS) |
|
13 |
vars.update(dict((obj.name, obj.value) for obj in TemplateVar.objects.all())) |
|
14 | ||
15 |
return vars |
passerelle/base/models.py | ||
---|---|---|
86 | 86 |
api_user.save() |
87 | 87 | |
88 | 88 | |
89 |
class TemplateVar(models.Model): |
|
90 |
name = models.CharField(max_length=64) |
|
91 |
value = models.CharField(max_length=128) |
|
92 | ||
93 |
def __unicode__(self): |
|
94 |
return u'%s - %s' % (self.name, self.value) |
|
95 | ||
96 | ||
97 | 89 |
class InheritanceManager(ModelUtilsInheritanceManager): |
98 | 90 | |
99 | 91 |
def get_slug(self, slug, request=None): |
passerelle/settings.py | ||
---|---|---|
100 | 100 |
'django.template.context_processors.tz', |
101 | 101 |
'django.contrib.messages.context_processors.messages', |
102 | 102 |
'django.template.context_processors.request', |
103 |
'passerelle.base.context_processors.template_vars', |
|
104 | 103 |
], |
105 | 104 |
}, |
106 | 105 |
}, |
passerelle/utils/__init__.py | ||
---|---|---|
39 | 39 |
from zeep.cache import InMemoryCache |
40 | 40 |
from zeep.transports import Transport |
41 | 41 | |
42 |
from passerelle.base.context_processors import template_vars |
|
43 | 42 |
from passerelle.base.models import ApiUser, AccessRight, BaseResource |
44 | 43 |
from passerelle.base.signature import check_query, check_url |
45 | 44 | |
46 | 45 | |
47 |
def get_template_vars(): |
|
48 |
""" |
|
49 |
returns the template vars as dict, to be used in apps code |
|
50 |
""" |
|
51 |
from django.http import HttpRequest |
|
52 |
return template_vars(HttpRequest()) |
|
53 | ||
54 | ||
55 |
def render_template_vars(value): |
|
56 |
""" |
|
57 |
renders the template vars in a string |
|
58 |
""" |
|
59 |
template = Template(value) |
|
60 |
return template.render(Context(get_template_vars())) |
|
61 | ||
62 | ||
63 | 46 |
def response_for_json(request, data): |
64 | 47 |
response = HttpResponse(content_type='application/json') |
65 | 48 |
json_str = json.dumps(data) |
66 |
- |