X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/162b4fd442c169a61d2f5b2b3bd613546c8472da..f32668123bbf48a0b73e90024bc09aa60e903ea0:/forum/views/decorators.py?ds=inline diff --git a/forum/views/decorators.py b/forum/views/decorators.py index 2219f98..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(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 +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 decorate.withfn(decorated)(func) + return decorate.result.withfn(decorated, needs_params=True)(func) return decorator