rewrote the config api

This commit is contained in:
Oskar Hahn 2012-02-15 12:04:11 +01:00
parent 77b11d8edf
commit bc05b78648
32 changed files with 203 additions and 245 deletions

View File

@ -14,7 +14,7 @@ from django.utils.translation import ugettext as _
from django.contrib import messages
from django.core.context_processors import csrf
from openslides.system.api import config_get
from system import config
from projector.api import get_active_slide
@ -22,7 +22,7 @@ def is_summary():
"""
True, if a summery shall be displayed
"""
if config_get('agenda_summary', False):
if config['agenda_summary']:
return True
return False

View File

@ -18,9 +18,11 @@ except ImportError:
from django.db import models
from django.utils.translation import ugettext as _
from system import config
from projector.models import Slide
from projector.api import register_slidemodel
from system.api import config_set
from agenda.api import is_summary
@ -59,9 +61,9 @@ class Item(models.Model, Slide):
"""
Slide.set_active(self)
if summary:
config_set("agenda_summary", True)
config["agenda_summary"] = True
else:
config_set("agenda_summary", '')
config["agenda_summary"] = False
def set_closed(self, closed=True):
"""

View File

@ -1,6 +1,5 @@
from django.utils.translation import ugettext as _
from projector.api import register_slidefunc
from agenda.models import Item
def agenda_show():

View File

@ -14,6 +14,8 @@ from django.core.urlresolvers import reverse
from django.contrib import messages
from django.utils.translation import ugettext as _
from system import config
from projector.api import get_active_slide, set_active_slide
from agenda.models import Item
@ -21,8 +23,6 @@ from agenda.api import is_summary, children_list, \
del_confirm_form_for_items
from agenda.forms import ItemOrderForm, ItemFormText
from system.api import config_set, config_get
from utils.utils import template, permission_required, \
del_confirm_form, ajax_request
from utils.pdf import print_agenda
@ -69,8 +69,8 @@ def overview(request):
'items': items,
'overview': overview,
'summary': is_summary(),
'countdown_visible': config_get('countdown_visible'),
'countdown_time': config_get('agenda_countdown_time'),
'countdown_visible': config['countdown_visible'],
'countdown_time': config['agenda_countdown_time'],
}
@ -87,8 +87,8 @@ def set_active(request, item_id, summary=False):
item.set_active(summary)
except Item.DoesNotExist:
messages.error(request, _('Item ID %d does not exist.') % int(item_id))
config_set("bigger", 100)
config_set("up", 0)
config["bigger"] = 100
config["up"] = 0
if request.is_ajax():
return ajax_request({'active': item_id, 'summary': summary})

View File

@ -21,7 +21,7 @@ from projector.api import register_slidemodel
from projector.models import Slide
from participant.models import Profile
from system.api import config_get
from system import config
from utils.utils import _propper_unicode
from poll import ChoicePoll
from poll.models import BaseOption, BasePoll
@ -148,7 +148,7 @@ class Application(models.Model, Slide):
"""
Return True, if the application has enough supporters
"""
min_supporters = int(config_get('application_min_supporters'))
min_supporters = int(config['application_min_supporters'])
if self.status == "pub":
return self.supporter.count() >= min_supporters
else:
@ -159,7 +159,7 @@ class Application(models.Model, Slide):
"""
Return number of missing supporters
"""
min_supporters = int(config_get('application_min_supporters'))
min_supporters = int(config['application_min_supporters'])
delta = min_supporters - self.supporter.count()
if delta > 0:
return delta

View File

@ -23,21 +23,25 @@ from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from django.db import transaction
from system import config
from agenda.models import Item
from application.models import Application, AVersion, ApplicationPoll
from application.forms import ApplicationForm, \
ApplicationManagerForm, \
ApplicationImportForm
from openslides.participant.models import Profile
from participant.models import Profile
from poll.views import PollFormView
from openslides.utils.utils import template, permission_required, \
from utils.utils import template, permission_required, \
render_to_forbitten, del_confirm_form, gen_confirm_form
from openslides.utils.pdf import print_application, print_application_poll
from openslides.system.api import config_get
from openslides.participant.api import gen_username, gen_password
from utils.pdf import print_application, print_application_poll
from participant.api import gen_username, gen_password
@permission_required('application.can_see_application')
@template('application/overview.html')
@ -69,7 +73,7 @@ def overview(request):
applications = query.all()
return {
'applications': applications,
'min_supporters': int(config_get('application_min_supporters')),
'min_supporters': int(config['application_min_supporters']),
}
@ -91,7 +95,7 @@ def view(request, application_id, newest=False):
'application': application,
'revisions': revisions,
'actions': actions,
'min_supporters': int(config_get('application_min_supporters')),
'min_supporters': int(config['application_min_supporters']),
'version': version,
#'results': application.results
}
@ -182,7 +186,7 @@ def edit(request, application_id=None):
messages.error(request, _('Please check the form for errors.'))
else:
if application_id is None:
initial = {'text': config_get('application_preamble')}
initial = {'text': config['application_preamble']}
else:
if application.status == "pub" and application.supporter.count() > 0:
if request.user.has_perm('application.can_manage_application'):
@ -455,6 +459,7 @@ def reject_version(request, aversion_id):
gen_confirm_form(request, _('Do you really want to reject version <b>%s</b>?') % aversion.aid, reverse('application_version_reject', args=[aversion.id]))
return redirect(reverse('application_view', args=[application.id]))
@permission_required('application.can_manage_applications')
@template('application/import.html')
def application_import(request):

View File

@ -11,7 +11,7 @@
"""
# Django settings for openslides project.
from system.openslides_settings import *
from openslides_settings import *
DEBUG = True
TEMPLATE_DEBUG = DEBUG

View File

@ -13,7 +13,7 @@ import os
from django.conf.global_settings import *
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
SITE_ROOT = os.path.join(SITE_ROOT, '..')
#SITE_ROOT = os.path.join(SITE_ROOT, '..')
AUTH_PROFILE_MODULE = 'participant.Profile'
@ -100,14 +100,14 @@ INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.admin',
'agenda',
'system',
'participant',
'application',
'poll',
'assignment',
'utils',
'projector',
'poll',
'agenda',
'participant',
'application',
'assignment',
)
TEMPLATE_CONTEXT_PROCESSORS = (

View File

@ -20,14 +20,14 @@ from agenda.models import Item
from application.models import Application
from assignment.models import Assignment
from participant.models import Profile
from system.models import Config
from system.models import ConfigStore
USER_VISIBLE_PERMISSIONS = reduce(list.__add__, [
[p[0] for p in Item._meta.permissions],
[p[0] for p in Application._meta.permissions],
[p[0] for p in Assignment._meta.permissions],
[p[0] for p in Profile._meta.permissions],
[p[0] for p in Config._meta.permissions]
[p[0] for p in ConfigStore._meta.permissions]
])
class UserNewForm(ModelForm):

View File

@ -36,7 +36,7 @@ from participant.api import gen_username, gen_password
from participant.forms import UserNewForm, UserEditForm, ProfileForm, UsersettingsForm, UserImportForm, GroupForm, AdminPasswordChangeForm
from utils.utils import template, permission_required, gen_confirm_form
from utils.pdf import print_userlist, print_passwords
from system.api import config_get
from system import config
from django.db.models import Avg, Max, Min, Count
@ -203,7 +203,7 @@ def user_set_active(request, user_id):
@permission_required('participant.can_manage_participant')
@template('participant/group_overview.html')
def get_group_overview(request):
if config_get('system_enable_anonymous', False):
if config['system_enable_anonymous']:
groups = Group.objects.all()
else:
groups = Group.objects.exclude(name='Anonymous')

View File

@ -13,6 +13,9 @@
from django.db import models
from django.utils.translation import ugettext as _
#from projector.api import register_slidemodel
#from projector.models import Slide
class BaseOption(models.Model):
poll = models.ForeignKey('BasePoll')
@ -39,7 +42,9 @@ class Vote(models.Model):
value = models.CharField(max_length=255, null=True)
class BasePoll(models.Model):
class BasePoll(models.Model): #, Slide):
prefix = 'BasePoll'
description = models.TextField(null=True, blank=True, verbose_name = _("Description"))
votescast = models.IntegerField(null=True, blank=True, verbose_name = _("Votes cast"))
votesinvalid = models.IntegerField(null=True, blank=True, verbose_name = _("Votes invalid"))
@ -96,3 +101,5 @@ class BasePoll(models.Model):
return forms
#register_slidemodel(BasePoll)

View File

@ -1,4 +1,4 @@
from system.api import config_set, config_get
from system import config
from projector.models import SLIDE
@ -24,7 +24,7 @@ def get_active_slide(only_sid=False):
if only_sid is True, returns only the id of this item. Returns None if not Item
is active. Does not Raise Item.DoesNotExist
"""
sid = config_get("presentation", None)
sid = config["presentation"]
if only_sid:
return sid
@ -32,7 +32,7 @@ def get_active_slide(only_sid=False):
def set_active_slide(sid):
config_set("presentation", sid)
config["presentation"] = sid
def register_slidemodel(model):
@ -43,39 +43,3 @@ def register_slidefunc(name, func):
if ' ' in name:
raise NameError('There can be no space in name')
SLIDE[name] = func
## def assignment_votes(item):
## votes = []
## if item.type == "ItemAssignment":
## assignment = item.cast().assignment
## publish_winner_results_only = config_get("assignment_publish_winner_results_only")
## # list of votes
## votes = []
## for candidate in assignment.candidates:
## tmplist = [[candidate, assignment.is_elected(candidate)], []]
## for poll in assignment.poll_set.all():
## if poll.published:
## if candidate in poll.options_values:
## # check config option 'publish_winner_results_only'
## if not publish_winner_results_only \
## or publish_winner_results_only and assignment.is_elected(candidate):
## option = Option.objects.filter(poll=poll).filter(user=candidate)[0]
## if poll.optiondecision:
## tmplist[1].append([option.yes, option.no, option.undesided])
## else:
## tmplist[1].append(option.yes)
## else:
## tmplist[1].append("")
## else:
## tmplist[1].append("-")
## votes.append(tmplist)
## return votes
##
##
## def assignment_polls(item):
## polls = []
## if item.type == "ItemAssignment":
## for poll in item.cast().assignment.poll_set.filter(assignment=item.cast().assignment):
## polls.append(poll)
## return polls

View File

@ -1,6 +1,6 @@
from django.db import models
from system.api import config_set, config_get
from system import config
SLIDE = {}
@ -37,4 +37,4 @@ class Slide(object):
"""
Appoint this item as the active one.
"""
config_set("presentation", "%s %d" % (self.prefix, self.id))
config["presentation"] = "%s %d" % (self.prefix, self.id)

View File

@ -22,7 +22,7 @@ from utils.utils import template, permission_required, \
del_confirm_form, ajax_request
from utils.template import render_block_to_string
from system.api import config_set, config_get
from system import config
from agenda.api import is_summary, children_list, \
del_confirm_form_for_items
@ -40,7 +40,7 @@ def active_slide(request):
data = get_active_slide()
except AttributeError: #TODO: It has to be an Slide.DoesNotExist
data = {
'title': config_get('event_name'),
'title': config['event_name'],
'template': 'projector/default.html',
}
@ -52,11 +52,11 @@ def active_slide(request):
'content': content,
'title': data['title'],
'time': datetime.now().strftime('%H:%M'),
'bigger': config_get('bigger'),
'up': config_get('up'),
'countdown_visible': config_get('countdown_visible'),
'countdown_time': config_get('agenda_countdown_time'),
'countdown_control': config_get('countdown_control'),
'bigger': config['bigger'],
'up': config['up'],
'countdown_visible': config['countdown_visible'],
'countdown_time': config['agenda_countdown_time'],
'countdown_control': config['countdown_control'],
}
return ajax_request(jsondata)
else:
@ -70,16 +70,16 @@ def active_slide(request):
@permission_required('agenda.can_manage_agenda')
def projector_edit(request, direction):
if direction == 'bigger':
config_set('bigger', int(config_get('bigger', 100)) + 10)
config['bigger'] = int(config['bigger']) + 10
elif direction == 'smaller':
config_set('bigger', int(config_get('bigger', 100)) - 10)
config['bigger'] = int(config['bigger']) - 10
elif direction == 'up':
config_set('up', int(config_get('up', 0)) - 10)
config['up'] = int(config['up']) - 10
elif direction == 'down':
config_set('up', int(config_get('up', 0)) + 10)
config['up'] = int(config['up']) + 10
elif direction == 'clean':
config_set('up', 0)
config_set('bigger', 100)
config['up'] = 0
config['bigger'] = 100
if request.is_ajax():
return ajax_request({})
@ -89,21 +89,21 @@ def projector_edit(request, direction):
@permission_required('agenda.can_manage_agenda')
def projector_countdown(request, command, time=60):
if command == 'show':
config_set('countdown_visible', True)
config['countdown_visible'] = True
elif command == 'hide':
config_set('countdown_visible', False)
config['countdown_visible'] = False
elif command == 'reset':
config_set('countdown_control', 'reset')
config['countdown_control'] = 'reset'
elif command == 'start':
config_set('countdown_control', 'start')
config['countdown_control'] = 'start'
elif command == 'stop':
config_set('countdown_control', 'stop')
config['countdown_control'] = 'stop'
if request.is_ajax():
if command == "show":
link = reverse('countdown_close')
else:
link = reverse('countdown_open')
return ajax_request({'countdown_visible': config_get('countdown_visible'),
return ajax_request({'countdown_visible': config['countdown_visible'],
'link': link})
return redirect(reverse('item_overview'))

View File

@ -0,0 +1,3 @@
from system.models import Config
config = Config()

View File

@ -11,6 +11,6 @@
"""
from django.contrib import admin
from system.models import Config
from system.models import ConfigStore
admin.site.register(Config)
admin.site.register(ConfigStore)

View File

@ -1,45 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.system.api
~~~~~~~~~~~~~~~~~~~~~
Useful functions for the system app.
:copyright: 2011 by the OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from system.models import Config, DEFAULT_DATA
def config_get(key, default=None):
"""
return the Value to the given Key
Else, return the given default value
Else, return the default value from config.models
Else, return none
"""
try:
value = Config.objects.values_list('value').get(pk=key)[0]
return value
except Config.DoesNotExist:
if default is None:
try:
default = DEFAULT_DATA[key]
except KeyError:
pass
return default
def config_set(key, value):
"""
Save key, value in DB. If it allready exist, it will be updated
"""
try:
c = Config.objects.get(id=key)
except Config.DoesNotExist:
c = Config()
c.id = str(key)
c.value = unicode(value)
c.save()

View File

@ -1,5 +1,5 @@
from django.contrib.auth.models import Permission
from openslides.system.api import config_get
from system import config
class AnonymousAuth(object):
"""
@ -25,7 +25,7 @@ class AnonymousAuth(object):
- try to return the permissions for the 'Anonymous' group
"""
if not user_obj.is_anonymous() or obj is not None or \
not config_get('system_enable_anonymous', False):
not config['system_enable_anonymous']:
return set()
perms = Permission.objects.filter(group__name='Anonymous')
@ -47,7 +47,7 @@ class AnonymousAuth(object):
Check if the user as a specific permission
"""
if not user_obj.is_anonymous() or obj is not None or \
not config_get('system_enable_anonymous', False):
not config['system_enable_anonymous']:
return False
return (perm in self.get_all_permissions(user_obj))
@ -57,7 +57,7 @@ class AnonymousAuth(object):
Check if the user has permissions on the module app_label
"""
if not user_obj.is_anonymous() or \
not config_get('system_enable_anonymous', False):
not config['system_enable_anonymous']:
return False
for perm in self.get_all_permissions(user_obj):
@ -78,5 +78,5 @@ def anonymous_context_additions(RequestContext):
Add a variable to the request context that will indicate
if anonymous login is possible at all.
"""
return { 'os_enable_anonymous_login' : config_get('system_enable_anonymous', False) }
return { 'os_enable_anonymous_login' : config['system_enable_anonymous']}

View File

@ -12,21 +12,21 @@
from django.forms import Form, CharField, TextInput, BooleanField, IntegerField, ChoiceField, Textarea, Select
from django.utils.translation import ugettext as _
from system.api import config_get
from system import config
class SystemConfigForm(Form):
error_css_class = 'error'
required_css_class = 'required'
#user_registration = BooleanField(label=_("User registration"), required=False)
system_url = CharField(widget=TextInput(), required=False, label=_("System URL"))
system_welcometext = CharField(widget=Textarea(), required=False, label=_("Welcome text (for password PDF)"))
system_enable_anonymous = BooleanField(required=False, label=_("Access for anonymous / guest users"), help_text=_("Allow access for guest users"))
class EventConfigForm(Form):
error_css_class = 'error'
required_css_class = 'required'
event_name = CharField(widget=TextInput(),label=_("Event name"), max_length=30)
event_description = CharField(widget=TextInput(),label=_("Short description of event"), max_length=100, required=False)
event_date = CharField(widget=TextInput(), required=False, label=_("Event date"))

View File

@ -27,14 +27,36 @@ DEFAULT_DATA = {
'system_welcometext': 'Welcome to OpenSlides!',
}
class Config(models.Model):
id = models.CharField(max_length=100, primary_key=True)
class ConfigStore(models.Model):
key = models.CharField(max_length=100, primary_key=True)
value = models.CharField(max_length=100)
def __unicode__(self):
return self.id
class Meta:
verbose_name = 'config'
permissions = (
('can_manage_system', "Can manage system configuration"),
)
class Config(object):
def __getitem__(self, key):
try:
return ConfigStore.objects.get(pk=key).value
except ConfigStore.DoesNotExist:
try:
return DEFAULT_DATA[key]
except KeyError:
return None
def __setitem__(self, key, value):
try:
c = ConfigStore.objects.get(pk=key)
except ConfigStore.DoesNotExist:
c = ConfigStore(pk=key)
c.value = value
c.save()

View File

@ -1,5 +1,8 @@
{% extends "system/base_system.html" %}
{% block title %}{{ block.super }} - {%trans "Configuration" %}{% endblock %}
{% load i18n %}
{% block title %}{{ block.super }} - {% trans "Configuration" %}{% endblock %}
{% block content %}
<h1>{%trans "Agenda settings" %}</h1>

View File

@ -1,5 +1,8 @@
{% extends "system/base_system.html" %}
{% block title %}{{ block.super }} - {%trans "Configuration" %}{% endblock %}
{% load i18n %}
{% block title %}{{ block.super }} - {% trans "Configuration" %}{% endblock %}
{% block content %}
<h1>{%trans "Application settings" %}</h1>

View File

@ -1,5 +1,8 @@
{% extends "system/base_system.html" %}
{% block title %}{{ block.super }} - {%trans "Configuration" %}{% endblock %}
{% load i18n %}
{% block title %}{{ block.super }} - {% trans "Configuration" %}{% endblock %}
{% block content %}
<h1>{%trans "Election settings" %}</h1>

View File

@ -1,5 +1,7 @@
{% extends "base.html" %}
{% load tags %}
{% load i18n %}
{% block submenu %}
{% url config_general as url_config_general %}

View File

@ -1,5 +1,8 @@
{% extends "system/base_system.html" %}
{% block title %}{{ block.super }} - {%trans "Configuration" %}{% endblock %}
{% load i18n %}
{% block title %}{{ block.super }} - {% trans "Configuration" %}{% endblock %}
{% block content %}
<h1>{%trans "General settings" %}</h1>

View File

@ -1,11 +1,14 @@
{% extends "system/base_system.html" %}
{% block title %}{{ block.super }} - {%trans "Configuration" %}{% endblock %}
{% load i18n %}
{% block title %}{{ block.super }} - {% trans "Configuration" %}{% endblock %}
{% block content %}
<h1>{%trans "System settings" %}</h1>
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<p>
<button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span>

View File

@ -1,28 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.system.tests
~~~~~~~~~~~~~~~~~~~~~~~
Unit tests for the system app.
:copyright: 2011 by the OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

View File

@ -13,9 +13,18 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('system.views',
url(r'^config/general$', 'get_general_config', name='config_general'),
url(r'^config/agenda$', 'get_agenda_config', name='config_agenda'),
url(r'^config/application$', 'get_application_config', name='config_application'),
url(r'^config/assignment$', 'get_assignment_config', name='config_assignment'),
url(r'^config/system$', 'get_system_config', name='config_system'),
url(r'^config/general$', 'get_general_config',
name='config_general'),
url(r'^config/agenda$', 'get_agenda_config',
name='config_agenda'),
url(r'^config/application$', 'get_application_config',
name='config_application'),
url(r'^config/assignment$', 'get_assignment_config',
name='config_assignment'),
url(r'^config/system$', 'get_system_config',
name='config_system'),
)

View File

@ -15,10 +15,13 @@ from django.core.urlresolvers import reverse
from django.contrib import messages
from django.contrib.auth.models import Group, Permission
from django.utils.translation import ugettext as _
from utils.utils import template
from utils.utils import template, permission_required
from system.forms import SystemConfigForm, EventConfigForm, AgendaConfigForm, ApplicationConfigForm, AssignmentConfigForm
from system.api import config_get, config_set
from system import config
@permission_required('system.can_manage_system')
@template('system/general.html')
@ -27,21 +30,21 @@ def get_general_config(request):
form_event = EventConfigForm(request.POST, prefix='event')
if form_event.is_valid():
# event form
config_set('event_name', form_event.cleaned_data['event_name'])
config_set('event_description', form_event.cleaned_data['event_description'])
config_set('event_date', form_event.cleaned_data['event_date'])
config_set('event_location', form_event.cleaned_data['event_location'])
config_set('event_organizer', form_event.cleaned_data['event_organizer'])
config['event_name'] = form_event.cleaned_data['event_name']
config['event_description'] = form_event.cleaned_data['event_description']
config['event_date'] = form_event.cleaned_data['event_date']
config['event_location'] = form_event.cleaned_data['event_location']
config['event_organizer'] = form_event.cleaned_data['event_organizer']
messages.success(request, _('General settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form_event = EventConfigForm(initial={
'event_name': config_get('event_name'),
'event_description': config_get('event_description'),
'event_date': config_get('event_date'),
'event_location': config_get('event_location'),
'event_organizer': config_get('event_organizer'),
'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'],
}, prefix='event')
return {
'form_event': form_event,
@ -53,13 +56,13 @@ def get_agenda_config(request):
if request.method == 'POST':
form_agenda = AgendaConfigForm(request.POST, prefix='agenda')
if form_agenda.is_valid():
config_set('agenda_countdown_time', form_agenda.cleaned_data['agenda_countdown_time'])
config['agenda_countdown_time'] = form_agenda.cleaned_data['agenda_countdown_time']
messages.success(request, _('Agenda settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form_agenda = AgendaConfigForm(initial={
'agenda_countdown_time': config_get('agenda_countdown_time'),
'agenda_countdown_time': config['agenda_countdown_time'],
}, prefix='agenda')
return {
'form_agenda': form_agenda,
@ -72,23 +75,23 @@ def get_application_config(request):
form_application = ApplicationConfigForm(request.POST, prefix='application')
form_assignment = AssignmentConfigForm(request.POST, prefix='assignment')
if form_application.is_valid():
config_set('application_min_supporters', form_application.cleaned_data['application_min_supporters'])
config_set('application_preamble', form_application.cleaned_data['application_preamble'])
config_set('application_pdf_ballot_papers_selection', form_application.cleaned_data['application_pdf_ballot_papers_selection'])
config_set('application_pdf_ballot_papers_number', form_application.cleaned_data['application_pdf_ballot_papers_number'])
config_set('application_pdf_title', form_application.cleaned_data['application_pdf_title'])
config_set('application_pdf_preamble', form_application.cleaned_data['application_pdf_preamble'])
config['application_min_supporters'] = form_application.cleaned_data['application_min_supporters']
config['application_preamble'] = form_application.cleaned_data['application_preamble']
config['application_pdf_ballot_papers_selection'] = form_application.cleaned_data['application_pdf_ballot_papers_selection']
config['application_pdf_ballot_papers_number'] = form_application.cleaned_data['application_pdf_ballot_papers_number']
config['application_pdf_title'] = form_application.cleaned_data['application_pdf_title']
config['application_pdf_preamble'] = form_application.cleaned_data['application_pdf_preamble']
messages.success(request, _('Application settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form_application = ApplicationConfigForm(initial={
'application_min_supporters': config_get('application_min_supporters'),
'application_preamble': config_get('application_preamble'),
'application_pdf_ballot_papers_selection': config_get('application_pdf_ballot_papers_selection'),
'application_pdf_ballot_papers_number': config_get('application_pdf_ballot_papers_number'),
'application_pdf_title': config_get('application_pdf_title'),
'application_pdf_preamble': config_get('application_pdf_preamble'),
'application_min_supporters': config['application_min_supporters'],
'application_preamble': config['application_preamble'],
'application_pdf_ballot_papers_selection': config['application_pdf_ballot_papers_selection'],
'application_pdf_ballot_papers_number': config['application_pdf_ballot_papers_number'],
'application_pdf_title': config['application_pdf_title'],
'application_pdf_preamble': config['application_pdf_preamble'],
}, prefix='application')
return {
'form_application': form_application,
@ -101,23 +104,23 @@ def get_assignment_config(request):
form_assignment = AssignmentConfigForm(request.POST, prefix='assignment')
if form_assignment.is_valid():
if form_assignment.cleaned_data['assignment_publish_winner_results_only']:
config_set('assignment_publish_winner_results_only', True)
config['assignment_publish_winner_results_only'] = True
else:
config_set('assignment_publish_winner_results_only', '')
config_set('assignment_pdf_ballot_papers_selection', form_assignment.cleaned_data['assignment_pdf_ballot_papers_selection'])
config_set('assignment_pdf_ballot_papers_number', form_assignment.cleaned_data['assignment_pdf_ballot_papers_number'])
config_set('assignment_pdf_title', form_assignment.cleaned_data['assignment_pdf_title'])
config_set('assignment_pdf_preamble', form_assignment.cleaned_data['assignment_pdf_preamble'])
config['assignment_publish_winner_results_only'] = ''
config['assignment_pdf_ballot_papers_selection'] = form_assignment.cleaned_data['assignment_pdf_ballot_papers_selection']
config['assignment_pdf_ballot_papers_number'] = form_assignment.cleaned_data['assignment_pdf_ballot_papers_number']
config['assignment_pdf_title'] = form_assignment.cleaned_data['assignment_pdf_title']
config['assignment_pdf_preamble'] = form_assignment.cleaned_data['assignment_pdf_preamble']
messages.success(request, _('Election settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form_assignment = AssignmentConfigForm(initial={
'assignment_publish_winner_results_only': config_get('assignment_publish_winner_results_only'),
'assignment_pdf_ballot_papers_selection': config_get('assignment_pdf_ballot_papers_selection'),
'assignment_pdf_ballot_papers_number': config_get('assignment_pdf_ballot_papers_number'),
'assignment_pdf_title': config_get('assignment_pdf_title'),
'assignment_pdf_preamble': config_get('assignment_pdf_preamble'),
'assignment_publish_winner_results_only': config['assignment_publish_winner_results_only'],
'assignment_pdf_ballot_papers_selection': config['assignment_pdf_ballot_papers_selection'],
'assignment_pdf_ballot_papers_number': config['assignment_pdf_ballot_papers_number'],
'assignment_pdf_title': config['assignment_pdf_title'],
'assignment_pdf_preamble': config['assignment_pdf_preamble'],
}, prefix='assignment')
return {
'form_assignment': form_assignment,
@ -129,10 +132,10 @@ def get_system_config(request):
if request.method == 'POST':
form = SystemConfigForm(request.POST)
if form.is_valid():
config_set('system_url', form.cleaned_data['system_url'])
config_set('system_welcometext', form.cleaned_data['system_welcometext'])
config['system_url'] = form.cleaned_data['system_url']
config['system_welcometext'] = form.cleaned_data['system_welcometext']
if form.cleaned_data['system_enable_anonymous']:
config_set('system_enable_anonymous', True)
config['system_enable_anonymous'] = True
# check for Anonymous group and (re)create it as needed
try:
anonymous = Group.objects.get(name='Anonymous')
@ -146,15 +149,15 @@ def get_system_config(request):
messages.success(request, _('Anonymous access enabled. Please modify the "Anonymous" group to fit your required permissions.'))
else:
# use '' - False will evaluate to uniced(False) => True..
config_set('system_enable_anonymous', '')
config['system_enable_anonymous'] = ''
messages.success(request, _('System settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form = SystemConfigForm(initial={
'system_url': config_get('system_url'),
'system_welcometext': config_get('system_welcometext'),
'system_enable_anonymous': config_get('system_enable_anonymous'),
'system_url': config['system_url'],
'system_welcometext': config['system_welcometext'],
'system_enable_anonymous': config['system_enable_anonymous'],
})
return {
'form': form,

View File

@ -20,7 +20,7 @@ handler500 = 'openslides.utils.views.server_error'
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^$', 'agenda.views.overview'),
(r'agenda', include('agenda.urls')),
(r'^agenda', include('agenda.urls')),
(r'', include('application.urls')),
(r'', include('participant.urls')),
(r'', include('assignment.urls')),

View File

@ -38,7 +38,7 @@ from openslides.application.models import Application
from openslides.assignment.models import Assignment
#from openslides.poll.models import Poll, Option
from openslides.participant.models import Profile
from openslides.system.api import config_get
from system import config
from openslides.settings import SITE_ROOT
from openslides.utils.utils import permission_required
@ -178,11 +178,11 @@ stylesheet.add(ParagraphStyle(name = 'Ballot_option_group_right',
)
# set event information
event_name = config_get("event_name")
event_description = config_get("event_description")
event_date = config_get("event_date")
event_location = config_get("event_location")
event_organizer = config_get("event_organizer")
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"]
# set print time
time = datetime.now().strftime(str(_("%Y-%m-%d %H:%Mh")))

View File

@ -2,17 +2,17 @@
# -*- coding: utf-8 -*-
from django import template
from system.api import config_get
from system import config
register = template.Library()
@register.simple_tag
def get_min_supporters():
return config_get('application_min_supporters')
return config['application_min_supporters']
@register.simple_tag
def get_config(key):
return config_get(key)
return config[key]
@register.simple_tag
def active(request, pattern):