X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/5c27752e396ef1b6e794a489b577b0f7be3126b6..7395cbba715aeda5b5d0927f33d4949b05803865:/forum/views/decorators.py?ds=sidebyside diff --git a/forum/views/decorators.py b/forum/views/decorators.py index d86a62e..20eb45c 100644 --- a/forum/views/decorators.py +++ b/forum/views/decorators.py @@ -6,12 +6,21 @@ from django.core.urlresolvers import reverse from django.template import RequestContext from django.utils.translation import ungettext, ugettext as _ from forum.modules import ui, decorate +from datetime import datetime, date +from forum.settings import ONLINE_USERS import logging +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(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 +31,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 decorated + return decorate.result.withfn(decorated, needs_params=True)(func) return decorator