Created
September 16, 2010 10:04
-
-
Save stephrdev/582199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render_to_response | |
from django.template import RequestContext | |
from django.http import HttpResponse | |
from django.utils import simplejson | |
from random import choice | |
import string | |
def render_tuple(f): | |
def wrap(request, *args, **kwargs): | |
context = f(request, *args, **kwargs) | |
if not isinstance(context, tuple): | |
return context | |
if context[0] == 'json': | |
return HttpResponse(simplejson.dumps(context[1]), | |
mimetype='application/json') | |
elif context[0] == 'jsonp': | |
return HttpResponse('%s(%s)' % (context[1], simplejson.dumps(context[2])), | |
mimetype='application/json') | |
else: | |
return render_to_response( | |
context[0], | |
context[1], | |
context_instance=RequestContext(request), | |
) | |
return wrap | |
def pwgen(length): | |
return ''.join([choice(string.letters + string.digits) for i in range(length)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment