X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/162b4fd442c169a61d2f5b2b3bd613546c8472da..267af854023b396c34cdc2b6ff162dc4a40fb61c:/forum/views/decorators.py?ds=sidebyside diff --git a/forum/views/decorators.py b/forum/views/decorators.py index 2219f98..9cb8cbd 100644 --- a/forum/views/decorators.py +++ b/forum/views/decorators.py @@ -1,17 +1,30 @@ -from django.http import HttpResponse, HttpResponseRedirect, Http404 +# -*- coding: utf-8 -*- + +import logging + +from datetime import datetime + +from django.http import HttpResponse, HttpResponseRedirect from django.utils import simplejson -from django.core.paginator import Paginator, EmptyPage from django.shortcuts import render_to_response from django.core.urlresolvers import reverse from django.template import RequestContext -from django.utils.translation import ungettext, ugettext as _ +from django.utils.translation import ugettext as _ + from forum.modules import ui, decorate -import logging +from forum.settings import ONLINE_USERS + +def login_required(func, request, *args, **kwargs): + if not request.user.is_authenticated(): + return HttpResponseRedirect(reverse('auth_signin')) + else: + return func(request, *args, **kwargs) def render(template=None, tab=None, tab_title='', weight=500, tabbed=True): - def decorator(func): - def decorated(func, request, *args, **kwargs): - context = func(request, *args, **kwargs) + def decorator(func): + def decorated(context, request, *args, **kwargs): + if request.user.is_authenticated(): + ONLINE_USERS[request.user] = datetime.now() if isinstance(context, HttpResponse): return context @@ -22,11 +35,11 @@ def render(template=None, tab=None, tab_title='', weight=500, tabbed=True): return render_to_response(context.pop('template', template), context, context_instance=RequestContext(request)) - if tabbed and tab: + if tabbed and tab and tab_title: ui.register(ui.PAGE_TOP_TABS, ui.PageTab(tab, tab_title, lambda: reverse(func.__name__), weight=weight)) - return decorate.withfn(decorated)(func) + return decorate.result.withfn(decorated, needs_params=True)(func) return decorator