2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2012-04-14 12:52:56 +02:00
|
|
|
openslides.config.views
|
2011-07-31 10:46:29 +02:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2012-04-14 12:52:56 +02:00
|
|
|
Views for the config app.
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-04-25 22:29:19 +02:00
|
|
|
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
2011-07-31 10:46:29 +02:00
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
2012-07-07 14:48:21 +02:00
|
|
|
from django.conf import settings
|
2011-07-31 10:46:29 +02:00
|
|
|
from django.contrib import messages
|
2012-07-07 14:48:21 +02:00
|
|
|
from django.core.urlresolvers import reverse
|
2012-04-18 09:33:09 +02:00
|
|
|
from django.utils.importlib import import_module
|
2012-07-20 11:31:28 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2012-02-15 12:04:11 +01:00
|
|
|
|
2012-04-15 10:36:37 +02:00
|
|
|
from openslides import get_version
|
|
|
|
|
2012-07-07 14:48:21 +02:00
|
|
|
from openslides.utils.template import Tab
|
|
|
|
from openslides.utils.views import FormView, TemplateView
|
2012-04-15 12:39:28 +02:00
|
|
|
|
2012-07-07 14:48:21 +02:00
|
|
|
from openslides.config.forms import GeneralConfigForm
|
|
|
|
from openslides.config.models import config
|
2012-11-23 09:35:41 +01:00
|
|
|
from openslides.participant.api import get_or_create_anonymous_group
|
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):
|
2012-07-07 14:48:21 +02:00
|
|
|
"""
|
|
|
|
Gereral config values.
|
|
|
|
"""
|
2012-04-14 12:52:56 +02:00
|
|
|
permission_required = 'config.can_manage_config'
|
2012-04-15 12:39:28 +02:00
|
|
|
form_class = GeneralConfigForm
|
2012-04-14 12:52:56 +02:00
|
|
|
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-11-17 22:14:49 +01:00
|
|
|
'welcome_title': config['welcome_title'],
|
|
|
|
'welcome_text': config['welcome_text'],
|
2012-04-15 12:39:28 +02:00
|
|
|
'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
|
|
|
|
2012-11-17 22:14:49 +01:00
|
|
|
# welcome widget
|
|
|
|
config['welcome_title'] = form.cleaned_data['welcome_title']
|
|
|
|
config['welcome_text'] = form.cleaned_data['welcome_text']
|
2012-04-15 13:26:01 +02:00
|
|
|
|
|
|
|
# system
|
2012-03-16 14:31:59 +01:00
|
|
|
if form.cleaned_data['system_enable_anonymous']:
|
|
|
|
config['system_enable_anonymous'] = True
|
2012-11-23 09:35:41 +01:00
|
|
|
anonymous = get_or_create_anonymous_group()
|
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
|
|
|
|
2012-07-07 14:48:21 +02:00
|
|
|
messages.success(self.request,
|
|
|
|
_('General settings successfully saved.'))
|
2012-04-15 12:39:28 +02:00
|
|
|
return super(GeneralConfig, self).form_valid(form)
|
|
|
|
|
|
|
|
|
|
|
|
class VersionConfig(TemplateView):
|
2012-07-07 14:48:21 +02:00
|
|
|
"""
|
|
|
|
Show version infos.
|
|
|
|
"""
|
2012-04-15 12:39:28 +02:00
|
|
|
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)
|
2012-04-18 09:33:09 +02:00
|
|
|
context['versions'] = [('OpenSlides', get_version())]
|
|
|
|
for plugin in settings.INSTALLED_PLUGINS:
|
|
|
|
try:
|
|
|
|
mod = import_module(plugin)
|
|
|
|
plugin_version = get_version(mod.VERSION)
|
|
|
|
except (ImportError, AttributeError, AssertionError):
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
plugin_name = mod.NAME
|
|
|
|
except AttributeError:
|
|
|
|
plugin_name = mod.__name__.split('.')[0]
|
|
|
|
|
|
|
|
context['versions'].append((plugin_name, plugin_version))
|
2012-04-15 12:39:28 +02:00
|
|
|
return context
|
2012-03-16 14:31:59 +01:00
|
|
|
|
|
|
|
|
2012-03-18 17:11:58 +01:00
|
|
|
def register_tab(request):
|
2012-07-07 14:48:21 +02:00
|
|
|
"""
|
|
|
|
Register the config tab.
|
|
|
|
"""
|
|
|
|
selected = request.path.startswith('/config/')
|
2012-03-18 17:11:58 +01:00
|
|
|
return Tab(
|
|
|
|
title=_('Configuration'),
|
|
|
|
url=reverse('config_general'),
|
2012-04-14 12:52:56 +02:00
|
|
|
permission=request.user.has_perm('config.can_manage_config'),
|
2012-03-18 17:11:58 +01:00
|
|
|
selected=selected,
|
|
|
|
)
|