From 1d5455f8f9f1c895c0f3612dd5af43efaae82662 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 15 Apr 2012 11:24:40 +0200 Subject: [PATCH] frontpage --- openslides/templates/front_page.html | 16 +++++++++++++ openslides/urls.py | 8 +++---- openslides/utils/views.py | 36 ++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 openslides/templates/front_page.html diff --git a/openslides/templates/front_page.html b/openslides/templates/front_page.html new file mode 100644 index 000000000..063eebc94 --- /dev/null +++ b/openslides/templates/front_page.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% load i18n %} + +{% block title %}{{ block.super }} – {{ item.title }}{% endblock %} + +{% block content %} +

{% trans 'Wellcome' %}

+ {{ wellcome_text|safe }} + + +{% endblock %} diff --git a/openslides/urls.py b/openslides/urls.py index 50ffba577..ea8000655 100644 --- a/openslides/urls.py +++ b/openslides/urls.py @@ -12,18 +12,16 @@ from django.conf.urls.defaults import patterns, url, include from django.conf import settings -from django.views.generic import RedirectView from django.utils.importlib import import_module import settings +from utils.views import FrontPage + handler500 = 'openslides.utils.views.server_error' urlpatterns = patterns('', # frontpage - (r'^$', RedirectView.as_view( - url='projector/control', - permanent = False, - )), + (r'^$', FrontPage.as_view()), (r'^agenda/', include('agenda.urls')), (r'^application/', include('application.urls')), diff --git a/openslides/utils/views.py b/openslides/utils/views.py index 8972465b6..bdfc78e3f 100644 --- a/openslides/utils/views.py +++ b/openslides/utils/views.py @@ -33,6 +33,7 @@ from django.template.loader import render_to_string from django.contrib.auth.decorators import login_required from django.utils.decorators import method_decorator from django.dispatch import receiver +from django.utils.importlib import import_module from django.views.generic import ( TemplateView as _TemplateView, RedirectView as _RedirectView, @@ -52,6 +53,8 @@ from utils import render_to_forbitten from openslides.utils.signals import template_manipulation from pdf import firstPage, laterPages +import settings + NO_PERMISSION_REQUIRED = 'No permission required' View = _View @@ -74,13 +77,14 @@ class LoginMixin(object): class PermissionMixin(object): permission_required = NO_PERMISSION_REQUIRED - def dispatch(self, request, *args, **kwargs): + def has_permission(self, request): if self.permission_required == NO_PERMISSION_REQUIRED: - has_permission = True + return True else: - has_permission = request.user.has_perm(self.permission_required) + return request.user.has_perm(self.permission_required) - if not has_permission: + def dispatch(self, request, *args, **kwargs): + if not self.has_permission(request): if not request.user.is_authenticated(): path = request.get_full_path() return HttpResponseRedirect("%s?next=%s" % (settings.LOGIN_URL, path)) @@ -255,6 +259,30 @@ class PDFView(PermissionMixin, View): return self.render_to_response(self.get_filename()) +class FrontPage(TemplateView): + template_name = 'front_page.html' + + def has_permission(self, request): + if request.user.is_authenticated() or config['system_enable_anonymous']: + return True + return False + + def get_context_data(self, **kwargs): + context = super(FrontPage, self).get_context_data(**kwargs) + apps = [] + for app in settings.INSTALLED_APPS: + try: + mod = import_module(app + '.views') + tab = mod.register_tab(self.request) + except (ImportError, AttributeError): + continue + if self.request.user.has_perm(tab.permission): + apps.append(tab) + context['apps'] = apps + #context['wellcome_text'] = config['wellcome_text'] + return context + + def server_error(request, template_name='500.html'): """ 500 error handler.