-
Notifications
You must be signed in to change notification settings - Fork 27
/
shortcuts.py
41 lines (26 loc) · 1018 Bytes
/
shortcuts.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
32
33
34
35
36
37
38
39
40
41
import json
from django.template.loader import select_template
from django.template import RequestContext
from django.http import HttpResponse, HttpResponseRedirect as redirect
from django.shortcuts import get_object_or_404
from django.views.decorators.cache import cache_page
from django.http import Http404
def render(request, template, params={}):
ctx = RequestContext(request, params)
if not isinstance(template, (list, tuple)):
template = [template]
return HttpResponse(select_template(template).render(ctx))
def jsonify(object):
return HttpResponse("(%s)" % json.dumps(object))
def plaintext(string):
return HttpResponse(unicode(string))
def flash(request, message):
request.session['flashes'] = request.session.get('flashes', []) + [message]
def get_flashes(request):
flashes = request.session.get('flashes', [])
request.session['flashes'] = []
return flashes
def contexter(request):
return {
"flashes": get_flashes(request),
}