forked from benadida/helios-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_utils.py
31 lines (22 loc) · 827 Bytes
/
view_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Utilities for single election views
Ben Adida (2009-07-18)
"""
from django.template import Context, Template, loader
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response
from helios_auth.security import get_user
from django.conf import settings
##
## template abstraction
##
def render_template(request, template_name, vars = {}):
t = loader.get_template(template_name + '.html')
vars_with_user = vars.copy()
vars_with_user['user'] = get_user(request)
vars_with_user['settings'] = settings
vars_with_user['CURRENT_URL'] = request.path
# csrf protection
if request.session.has_key('csrf_token'):
vars_with_user['csrf_token'] = request.session['csrf_token']
return render_to_response('server_ui/templates/%s.html' % template_name, vars_with_user)