OpenSlides/openslides/config/views.py

100 lines
3.6 KiB
Python
Raw Normal View History

2011-07-31 10:46:29 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.config.views
2011-07-31 10:46:29 +02:00
~~~~~~~~~~~~~~~~~~~~~~~
Views for the config app.
2011-07-31 10:46:29 +02:00
:copyright: 2011 by the OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.contrib.auth.models import Group, Permission
2011-07-31 10:46:29 +02:00
from django.utils.translation import ugettext as _
2012-03-16 14:31:59 +01:00
from django.template.loader import render_to_string
2012-02-15 12:04:11 +01:00
from openslides import get_version
2011-07-31 10:46:29 +02:00
from utils.utils import template, permission_required
from utils.views import FormView, TemplateView
2012-03-18 17:11:58 +01:00
from utils.template import Tab
2012-02-15 12:04:11 +01:00
from forms import GeneralConfigForm
2012-03-16 14:31:59 +01:00
from models import config
2012-03-18 17:11:58 +01:00
2011-07-31 10:46:29 +02:00
2012-03-16 14:31:59 +01:00
class GeneralConfig(FormView):
permission_required = 'config.can_manage_config'
form_class = GeneralConfigForm
template_name = 'config/general.html'
2012-03-16 14:31:59 +01:00
def get_initial(self):
return {
2012-02-15 12:04:11 +01:00
'event_name': config['event_name'],
'event_description': config['event_description'],
'event_date': config['event_date'],
'event_location': config['event_location'],
'event_organizer': config['event_organizer'],
2012-04-15 13:26:01 +02:00
'frontpage_title': config['frontpage_title'],
'frontpage_welcometext': config['frontpage_welcometext'],
'system_enable_anonymous': config['system_enable_anonymous'],
2012-03-16 14:31:59 +01:00
}
def form_valid(self, form):
2012-04-15 13:26:01 +02:00
# event
2012-03-16 14:31:59 +01:00
config['event_name'] = form.cleaned_data['event_name']
config['event_description'] = form.cleaned_data['event_description']
config['event_date'] = form.cleaned_data['event_date']
config['event_location'] = form.cleaned_data['event_location']
config['event_organizer'] = form.cleaned_data['event_organizer']
2012-04-15 13:26:01 +02:00
# frontpage
config['frontpage_welcometext'] = form.cleaned_data['frontpage_welcometext']
config['frontpage_welcometext'] = form.cleaned_data['frontpage_welcometext']
# system
2012-03-16 14:31:59 +01:00
if form.cleaned_data['system_enable_anonymous']:
config['system_enable_anonymous'] = True
# check for Anonymous group and (re)create it as needed
try:
anonymous = Group.objects.get(name='Anonymous')
except Group.DoesNotExist:
default_perms = [u'can_see_agenda', u'can_see_projector', u'can_see_application']
anonymous = Group()
anonymous.name = 'Anonymous'
anonymous.save()
anonymous.permissions = Permission.objects.filter(codename__in=default_perms)
anonymous.save()
messages.success(self.request, _('Anonymous access enabled. Please modify the "Anonymous" group to fit your required permissions.'))
2011-11-14 23:40:19 +01:00
else:
2012-03-16 14:31:59 +01:00
config['system_enable_anonymous'] = False
2012-04-15 13:26:01 +02:00
messages.success(self.request, _('General settings successfully saved.'))
return super(GeneralConfig, self).form_valid(form)
class VersionConfig(TemplateView):
permission_required = 'config.can_manage_config'
template_name = 'config/version.html'
def get_context_data(self, **kwargs):
context = super(VersionConfig, self).get_context_data(**kwargs)
context['version'] = get_version()
return context
2012-03-16 14:31:59 +01:00
2012-03-18 17:11:58 +01:00
def register_tab(request):
selected = True if request.path.startswith('/config/') else False
return Tab(
title=_('Configuration'),
url=reverse('config_general'),
permission=request.user.has_perm('config.can_manage_config'),
2012-03-18 17:11:58 +01:00
selected=selected,
)