2 from django.http import HttpResponse, HttpResponseForbidden, Http404
4 def ajax_login_required(view_func):
5 def wrap(request,*args,**kwargs):
6 if request.user.is_authenticated():
7 return view_func(request,*args,**kwargs)
9 json = json.dumps({'login_required':True})
10 return HttpResponseForbidden(json, mimetype='application/json')
13 def ajax_method(view_func):
14 def wrap(request,*args,**kwargs):
15 if not request.is_ajax():
17 retval = view_func(request,*args,**kwargs)
18 if isinstance(retval, HttpResponse):
19 retval.mimetype = 'application/json'
22 json = json.dumps(retval)
23 return HttpResponse(json, mimetype='application/json')