Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def ajax_login_required(view_func):
- def wrap(request, *args, **kwargs):
- if request.user.is_authenticated():
- return view_func(request, *args, **kwargs)
- json = simplejson.dumps({ 'not_authenticated': True })
- return HttpResponse(json, mimetype='application/json')
- wrap.__doc__ = view_func.__doc__
- wrap.__dict__ = view_func.__dict__
- return wrap
- @ajax_login_required
- def ajax_update_module(request, module_slug, action):
- # Etc ...
- return HttpResponse(json, mimetype='application/json')
- $.post('/restricted-url/', data, function(json) {
- if (json.not_authenticated) {
- alert('Not authorized.'); // Or something in a message DIV
- return;
- }
- // Etc ...
- });
- <a href="{{link}}" onclick="return login_popup()">
Add Comment
Please, Sign In to add comment