2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.system.models
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Models for the system app.
|
|
|
|
|
|
|
|
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
2012-02-18 00:00:56 +01:00
|
|
|
from pickle import dumps, loads
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
from django.db import models
|
2011-10-05 21:18:28 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
DEFAULT_DATA = {
|
|
|
|
'event_name': 'OpenSlides',
|
|
|
|
'event_description': 'Presentation and voting system',
|
2011-11-09 21:16:02 +01:00
|
|
|
'agenda_countdown_time': 60,
|
2011-07-31 10:46:29 +02:00
|
|
|
'application_min_supporters': 4,
|
|
|
|
'application_preamble': 'Die Versammlung möge beschließen,',
|
2011-11-21 18:00:58 +01:00
|
|
|
'application_pdf_ballot_papers_selection': '1',
|
2011-10-05 21:18:28 +02:00
|
|
|
'application_pdf_title': _('Applications'),
|
2011-11-21 18:00:58 +01:00
|
|
|
'assignment_pdf_ballot_papers_selection': '1',
|
2011-10-05 21:18:28 +02:00
|
|
|
'assignment_pdf_title': _('Elections'),
|
|
|
|
'system_url': 'http://127.0.0.1:8000',
|
2011-11-14 23:12:52 +01:00
|
|
|
'system_welcometext': 'Welcome to OpenSlides!',
|
2011-07-31 10:46:29 +02:00
|
|
|
}
|
|
|
|
|
2012-02-15 12:04:11 +01:00
|
|
|
class ConfigStore(models.Model):
|
|
|
|
key = models.CharField(max_length=100, primary_key=True)
|
2011-07-31 10:46:29 +02:00
|
|
|
value = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-02-19 22:20:29 +01:00
|
|
|
return self.key
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
class Meta:
|
2012-02-15 12:04:11 +01:00
|
|
|
verbose_name = 'config'
|
2011-07-31 10:46:29 +02:00
|
|
|
permissions = (
|
2011-09-04 12:21:58 +02:00
|
|
|
('can_manage_system', "Can manage system configuration"),
|
2011-07-31 10:46:29 +02:00
|
|
|
)
|
2012-02-15 12:04:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Config(object):
|
2012-02-19 22:20:29 +01:00
|
|
|
def load_config(self):
|
|
|
|
self.config = {}
|
|
|
|
for key, value in ConfigStore.objects.all().values_list():
|
|
|
|
self.config[key] = loads(str(value))
|
|
|
|
|
2012-02-15 12:04:11 +01:00
|
|
|
def __getitem__(self, key):
|
|
|
|
try:
|
2012-02-19 22:20:29 +01:00
|
|
|
self.config
|
|
|
|
except AttributeError:
|
|
|
|
self.load_config()
|
|
|
|
try:
|
|
|
|
return self.config[key]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
return DEFAULT_DATA[key]
|
|
|
|
except KeyError:
|
|
|
|
return None
|
2012-02-15 12:04:11 +01:00
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
try:
|
2012-02-19 22:20:29 +01:00
|
|
|
c = self.config.get(pk=key)
|
2012-02-15 12:04:11 +01:00
|
|
|
except ConfigStore.DoesNotExist:
|
|
|
|
c = ConfigStore(pk=key)
|
2012-02-18 00:00:56 +01:00
|
|
|
c.value = dumps(value)
|
2012-02-15 12:04:11 +01:00
|
|
|
c.save()
|
2012-02-19 22:20:29 +01:00
|
|
|
self.config[key] = value
|
2012-02-15 12:04:11 +01:00
|
|
|
|
|
|
|
|
2012-02-18 00:00:56 +01:00
|
|
|
|