diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2009-12-08 22:50:45 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2009-12-08 22:50:45 -0500 |
commit | 9655bd421022dd6488b21184cc9fd0242c6b345e (patch) | |
tree | 8d9e58419b50630adc537ac92907d04946edc925 /utils/decorators.py | |
parent | 932b13188b08871e4f541f46c1dbb4eca693adfa (diff) | |
download | askbot-9655bd421022dd6488b21184cc9fd0242c6b345e.tar.gz askbot-9655bd421022dd6488b21184cc9fd0242c6b345e.tar.bz2 askbot-9655bd421022dd6488b21184cc9fd0242c6b345e.zip |
added interesting and ignored tag selectors (works) and per-tag subscription (not tested yet)
Diffstat (limited to 'utils/decorators.py')
-rw-r--r-- | utils/decorators.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/utils/decorators.py b/utils/decorators.py new file mode 100644 index 00000000..e4e7acb3 --- /dev/null +++ b/utils/decorators.py @@ -0,0 +1,25 @@ +from django.http import HttpResponse, HttpResponseForbidden, Http404 +from django.utils import simplejson + +def ajax_login_required(view_func): + def wrap(request,*args,**kwargs): + if request.user.is_authenticated(): + return view_func(request,*args,**kwargs) + else: + json = simplejson.dumps({'login_required':True}) + return HttpResponseForbidden(json,mimetype='application/json') + return wrap + +def ajax_method(view_func): + def wrap(request,*args,**kwargs): + if not request.is_ajax(): + raise Http404 + retval = view_func(request,*args,**kwargs) + if isinstance(retval, HttpResponse): + retval.mimetype = 'application/json' + return retval + else: + json = simplejson.dumps(retval) + return HttpResponse(json,mimetype='application/json') + return wrap + |