diff --git a/openslides/agenda/api.py b/openslides/agenda/api.py index 757ea2db6..dc356ca09 100644 --- a/openslides/agenda/api.py +++ b/openslides/agenda/api.py @@ -10,7 +10,7 @@ :license: GNU GPL, see LICENSE for more details. """ -from system import config +from config.models import config def is_summary(): diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 482ad54e8..424eeb773 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -19,7 +19,7 @@ from django.db import models from mptt.models import MPTTModel, TreeForeignKey -from system import config +from config.models import config from projector.projector import SlideMixin from projector.api import register_slidemodel @@ -27,6 +27,7 @@ from projector.api import register_slidemodel from agenda.api import is_summary from utils.translation_ext import xugettext as _ + class Item(MPTTModel, SlideMixin): """ An Agenda Item @@ -131,11 +132,23 @@ class Item(MPTTModel, SlideMixin): order_insertion_by = ['weight', 'title'] -register_slidemodel(Item, category=_('Agenda'), model_name=_('Agenda Item')) +register_slidemodel(Item, model_name=_('Agenda Item')) # TODO: put this in another file from projector.api import register_slidefunc from agenda.slides import agenda_show -register_slidefunc(_('Agenda'), agenda_show, category=_('Agenda')) +register_slidefunc(_('Agenda'), agenda_show) + + +from django.dispatch import receiver +from openslides.config.signals import default_config_value + + +@receiver(default_config_value, dispatch_uid="agenda_default_config") +def default_config(sender, key, **kwargs): + return { + 'agenda_countdown_time': 60, + }.get(key) + diff --git a/openslides/agenda/templates/agenda/config.html b/openslides/agenda/templates/agenda/config.html index a02d26e3e..4e738721d 100644 --- a/openslides/agenda/templates/agenda/config.html +++ b/openslides/agenda/templates/agenda/config.html @@ -1,4 +1,4 @@ -{% extends "system/base_system.html" %} +{% extends "config/base_config.html" %} {% load i18n %} diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index e32495e40..c74667829 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -21,7 +21,7 @@ from utils.pdf import stylesheet from utils.views import TemplateView, RedirectView, UpdateView, CreateView, DeleteView, PDFView, FormView from utils.template import Tab -from system import config +from config.models import config from projector.api import get_active_slide, set_active_slide @@ -201,7 +201,7 @@ class AgendaPDF(PDFView): class Config(FormView): - permission_required = 'system.can_manage_system' + permission_required = 'config.can_manage_config' form_class = ConfigForm template_name = 'agenda/config.html' diff --git a/openslides/application/models.py b/openslides/application/models.py index 52bfa410b..2b09b368a 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -21,7 +21,7 @@ from projector.api import register_slidemodel from projector.models import SlideMixin from participant.models import Profile -from system import config +from config.models import config from utils.utils import _propper_unicode from utils.translation_ext import xugettext as _ from poll.models import BaseOption, BasePoll, CountVotesCast, CountInvalid, Vote @@ -494,7 +494,7 @@ class AVersion(models.Model): .filter(id__lte=self.id).count() return self._aid -register_slidemodel(Application, category=_('Applications')) +register_slidemodel(Application) class ApplicationOption(BaseOption): @@ -527,3 +527,17 @@ class ApplicationPoll(BasePoll, CountInvalid, CountVotesCast): def get_absolute_url(self): return reverse('application_poll_view', args=[self.id]) + + +from django.dispatch import receiver +from openslides.config.signals import default_config_value + + +@receiver(default_config_value, dispatch_uid="application_default_config") +def default_config(sender, key, **kwargs): + return { + 'application_min_supporters': 4, + 'application_preamble': 'Die Versammlung möge beschließen,', + 'application_pdf_ballot_papers_selection': '1', + 'application_pdf_title': _('Applications'), + }.get(key) diff --git a/openslides/application/templates/application/config.html b/openslides/application/templates/application/config.html index 13680a297..2fc58d7b2 100644 --- a/openslides/application/templates/application/config.html +++ b/openslides/application/templates/application/config.html @@ -1,4 +1,4 @@ -{% extends "system/base_system.html" %} +{% extends "config/base_config.html" %} {% load i18n %} diff --git a/openslides/application/views.py b/openslides/application/views.py index a830d01de..0a6df40f9 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -29,7 +29,7 @@ from reportlab.lib import colors from reportlab.lib.units import cm from reportlab.platypus import PageBreak, Paragraph, Spacer, Table, TableStyle -from system import config +from config.models import config from settings import SITE_ROOT from utils.pdf import stylesheet from utils.views import PDFView @@ -506,7 +506,7 @@ def application_import(request): # check for valid encoding (will raise UnicodeDecodeError if not) request.FILES['csvfile'].read().decode('utf-8') request.FILES['csvfile'].seek(0) - + users_generated = 0 applications_generated = 0 applications_modified = 0 @@ -777,7 +777,7 @@ class ApplicationPollPDF(PDFView): class Config(FormView): - permission_required = 'system.can_manage_system' + permission_required = 'config.can_manage_config' form_class = ConfigForm template_name = 'application/config.html' diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 7d1d0b1e8..05f209528 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -121,7 +121,7 @@ class Assignment(models.Model, SlideMixin): ('can_manage_assignment', _("Can manage assignment", fixstr=True)), ) -register_slidemodel(Assignment, category=_('Elections')) +register_slidemodel(Assignment) class AssignmentOption(BaseOption): @@ -150,5 +150,14 @@ class AssignmentPoll(BasePoll, CountInvalid, CountVotesCast, PublishPollMixin): if link == 'delete': return ('assignment_poll_delete', [str(self.id)]) -#register_slidemodel(AssignmentPoll, category=_('Elections')) +from django.dispatch import receiver +from openslides.config.signals import default_config_value + + +@receiver(default_config_value, dispatch_uid="assignment_default_config") +def default_config(sender, key, **kwargs): + return { + 'assignment_pdf_ballot_papers_selection': '1', + 'assignment_pdf_title': _('Elections'), + }.get(key) diff --git a/openslides/assignment/templates/assignment/config.html b/openslides/assignment/templates/assignment/config.html index 33bdc11c0..edb32fd6b 100644 --- a/openslides/assignment/templates/assignment/config.html +++ b/openslides/assignment/templates/assignment/config.html @@ -1,4 +1,4 @@ -{% extends "system/base_system.html" %} +{% extends "config/base_config.html" %} {% load i18n %} diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index c08974906..bd22261d7 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -20,7 +20,7 @@ from reportlab.lib import colors from reportlab.lib.units import cm from reportlab.platypus import PageBreak, Paragraph, Spacer, Table, TableStyle -from system import config +from config.models import config from utils.utils import template, permission_required, gen_confirm_form, del_confirm_form, ajax_request from utils.pdf import print_assignment_poll @@ -439,7 +439,7 @@ class AssignmentPDF(PDFView): class Config(FormView): - permission_required = 'system.can_manage_system' + permission_required = 'config.can_manage_config' form_class = ConfigForm template_name = 'assignment/config.html' diff --git a/openslides/config/__init__.py b/openslides/config/__init__.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/openslides/config/__init__.py @@ -0,0 +1 @@ + diff --git a/openslides/system/forms.py b/openslides/config/forms.py similarity index 94% rename from openslides/system/forms.py rename to openslides/config/forms.py index 35bc15ad5..b17f54558 100644 --- a/openslides/system/forms.py +++ b/openslides/config/forms.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ - openslides.system.forms + openslides.config.forms ~~~~~~~~~~~~~~~~~~~~~~~ - Forms for the system app. + Forms for the config app. :copyright: 2011 by the OpenSlides team, see AUTHORS. :license: GNU GPL, see LICENSE for more details. @@ -14,7 +14,7 @@ from django.forms import Form, CharField, TextInput, BooleanField, IntegerField, from django.utils.translation import ugettext as _ from utils.forms import CssClassMixin -from system import config +from models import config class SystemConfigForm(Form, CssClassMixin): diff --git a/openslides/system/models.py b/openslides/config/models.py similarity index 75% rename from openslides/system/models.py rename to openslides/config/models.py index 346a72c64..4cee5caf6 100644 --- a/openslides/system/models.py +++ b/openslides/config/models.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ - openslides.system.models + openslides.config.models ~~~~~~~~~~~~~~~~~~~~~~~~ - Models for the system app. + Models for the config app. :copyright: 2011 by the OpenSlides team, see AUTHORS. :license: GNU GPL, see LICENSE for more details. @@ -13,21 +13,12 @@ from pickle import dumps, loads import base64 from django.db import models +from django.dispatch import receiver + from utils.translation_ext import xugettext as _ -DEFAULT_DATA = { - 'event_name': 'OpenSlides', - 'event_description': 'Presentation and voting system', - 'agenda_countdown_time': 60, - 'application_min_supporters': 4, - 'application_preamble': 'Die Versammlung möge beschließen,', - 'application_pdf_ballot_papers_selection': '1', - 'application_pdf_title': _('Applications'), - 'assignment_pdf_ballot_papers_selection': '1', - 'assignment_pdf_title': _('Elections'), - 'system_url': 'http://127.0.0.1:8000', - 'system_welcometext': 'Welcome to OpenSlides!', -} +from openslides.config.signals import default_config_value + class ConfigStore(models.Model): key = models.CharField(max_length=100, primary_key=True) @@ -39,9 +30,10 @@ class ConfigStore(models.Model): class Meta: verbose_name = 'config' permissions = ( - ('can_manage_system', _("Can manage system configuration", fixstr=True)), + ('can_manage_config', _("Can manage config configuration", fixstr=True)), ) + # TODO: # I used base64 to save pickled Data, there has to be another way see: # http://stackoverflow.com/questions/2524970/djangounicodedecodeerror-while-storing-pickled-data @@ -57,14 +49,16 @@ class Config(object): self.config except AttributeError: self.load_config() + try: return self.config[key] except KeyError: pass - try: - return DEFAULT_DATA[key] - except KeyError: - return None + + for receiver, value in default_config_value.send(sender='config', key=key): + if value is not None: + return value + return None def __setitem__(self, key, value): try: @@ -79,6 +73,21 @@ class Config(object): self.load_config() self.config[key] = value +config = Config() + + +@receiver(default_config_value, dispatch_uid="config_default_config") +def default_config(sender, key, **kwargs): + return { + 'event_name': 'OpenSlides', + 'event_description': 'Presentation and voting system', + 'system_url': 'http://127.0.0.1:8000', + 'system_welcometext': 'Welcome to OpenSlides!', + }.get(key) + + + + from django.dispatch import receiver from django.core.urlresolvers import reverse from django.utils.importlib import import_module @@ -88,7 +97,7 @@ from openslides.utils.signals import template_manipulation -@receiver(template_manipulation, dispatch_uid="system_base_system") +@receiver(template_manipulation, dispatch_uid="config_submenu") def set_submenu(sender, request, context, **kwargs): if not request.path.startswith('/config/'): return None diff --git a/openslides/config/signals.py b/openslides/config/signals.py new file mode 100644 index 000000000..4e0880e40 --- /dev/null +++ b/openslides/config/signals.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + openslides.config.signals + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Defines Signals for the config. + + :copyright: 2011 by the OpenSlides team, see AUTHORS. + :license: GNU GPL, see LICENSE for more details. +""" + +from django.dispatch import Signal + +default_config_value = Signal(providing_args=['key']) diff --git a/openslides/system/templates/system/base_system.html b/openslides/config/templates/config/base_config.html similarity index 100% rename from openslides/system/templates/system/base_system.html rename to openslides/config/templates/config/base_config.html diff --git a/openslides/system/templates/system/system.html b/openslides/config/templates/config/config.html similarity index 83% rename from openslides/system/templates/system/system.html rename to openslides/config/templates/config/config.html index 04f724212..f5fd185e8 100644 --- a/openslides/system/templates/system/system.html +++ b/openslides/config/templates/config/config.html @@ -1,4 +1,4 @@ -{% extends "system/base_system.html" %} +{% extends "config/base_config.html" %} {% load i18n %} @@ -13,8 +13,8 @@ - - diff --git a/openslides/system/templates/system/general.html b/openslides/config/templates/config/general.html similarity index 93% rename from openslides/system/templates/system/general.html rename to openslides/config/templates/config/general.html index f29cb7457..1a7e7a502 100644 --- a/openslides/system/templates/system/general.html +++ b/openslides/config/templates/config/general.html @@ -1,4 +1,4 @@ -{% extends "system/base_system.html" %} +{% extends "config/base_config.html" %} {% load i18n %} diff --git a/openslides/system/urls.py b/openslides/config/urls.py similarity index 89% rename from openslides/system/urls.py rename to openslides/config/urls.py index b4791ba4b..ba16952d8 100644 --- a/openslides/system/urls.py +++ b/openslides/config/urls.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ - openslides.system.urls + openslides.config.urls ~~~~~~~~~~~~~~~~~~~~~~ - URL list for the system app. + URL list for the config app. :copyright: 2011 by the OpenSlides team, see AUTHORS. :license: GNU GPL, see LICENSE for more details. @@ -17,7 +17,7 @@ import settings from views import GeneralConfig -urlpatterns = patterns('system.views', +urlpatterns = patterns('config.views', url(r'^general/$', GeneralConfig.as_view(), name='config_general', diff --git a/openslides/system/views.py b/openslides/config/views.py similarity index 89% rename from openslides/system/views.py rename to openslides/config/views.py index 37a3763f6..f7ff7f1ee 100644 --- a/openslides/system/views.py +++ b/openslides/config/views.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ - openslides.system.views + openslides.config.views ~~~~~~~~~~~~~~~~~~~~~~~ - Views for the system app. + Views for the config app. :copyright: 2011 by the OpenSlides team, see AUTHORS. :license: GNU GPL, see LICENSE for more details. @@ -21,15 +21,15 @@ from utils.utils import template, permission_required from utils.views import FormView from utils.template import Tab -from system.forms import SystemConfigForm, EventConfigForm +from forms import SystemConfigForm, EventConfigForm -from system import config +from models import config class GeneralConfig(FormView): - permission_required = 'system.can_manage_system' + permission_required = 'config.can_manage_config' form_class = EventConfigForm - template_name = 'system/general.html' + template_name = 'config/general.html' def get_initial(self): return { @@ -55,9 +55,9 @@ class GeneralConfig(FormView): class Config(FormView): - permission_required = 'system.can_manage_system' + permission_required = 'config.can_manage_config' form_class = SystemConfigForm - template_name = 'system/system.html' + template_name = 'config/config.html' def get_initial(self): return { @@ -93,6 +93,6 @@ def register_tab(request): return Tab( title=_('Configuration'), url=reverse('config_general'), - permission=request.user.has_perm('system.can_manage_system'), + permission=request.user.has_perm('config.can_manage_config'), selected=selected, ) diff --git a/openslides/openslides_settings.py b/openslides/openslides_settings.py index ad3092d40..7d35ad551 100644 --- a/openslides/openslides_settings.py +++ b/openslides/openslides_settings.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ - openslides.system.opennslides_settings + openslides.opennslides_settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~ OpenSlides default settings. @@ -103,7 +103,7 @@ INSTALLED_APPS = ( 'application', 'assignment', 'participant', - 'system', + 'config', ) TEMPLATE_CONTEXT_PROCESSORS = ( diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index 0f321281d..515f1d5a9 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -23,7 +23,7 @@ from agenda.models import Item from application.models import Application from assignment.models import Assignment from participant.models import Profile -from system.models import ConfigStore +from config.models import ConfigStore USER_VISIBLE_PERMISSIONS = reduce(list.__add__, [ [p[0] for p in Item._meta.permissions], diff --git a/openslides/participant/views.py b/openslides/participant/views.py index 7532b6d56..d9323173a 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -42,7 +42,7 @@ from utils.utils import (template, permission_required, gen_confirm_form, ajax_request, decodedict, encodedict) from utils.pdf import print_userlist, print_passwords from utils.template import Tab -from system import config +from config.models import config from django.db.models import Avg, Max, Min, Count diff --git a/openslides/projector/api.py b/openslides/projector/api.py index b21cdb09b..7a8a12d68 100644 --- a/openslides/projector/api.py +++ b/openslides/projector/api.py @@ -1,4 +1,4 @@ -from system import config +from config.models import config from projector import SLIDE, Slide @@ -35,10 +35,12 @@ def set_active_slide(sid): config["presentation"] = sid -def register_slidemodel(model, category=None, model_name=None): +def register_slidemodel(model, model_name=None): #TODO: Warn if there already is a slide with this prefix if model_name is None: model_name = model.prefix + + category = model.__module__.split('.')[0] SLIDE[model.prefix] = Slide( model_slide=True, model=model, @@ -48,8 +50,9 @@ def register_slidemodel(model, category=None, model_name=None): ) -def register_slidefunc(key, func, category=None): +def register_slidefunc(key, func): #TODO: Warn if there already is a slide with this prefix + category = func.__module__.split('.')[0] SLIDE[key] = Slide( model_slide=False, func=func, diff --git a/openslides/projector/models.py b/openslides/projector/models.py index 150d3f3ba..3ba440ba0 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -3,9 +3,10 @@ from django.db import models from api import register_slidemodel from projector import SlideMixin -from system import config +from config.models import config from utils.translation_ext import xugettext as _ + class ProjectorSlide(models.Model, SlideMixin): prefix = 'ProjectorSlide' @@ -13,6 +14,14 @@ class ProjectorSlide(models.Model, SlideMixin): text = models.TextField(null=True, blank=True, verbose_name=_("Text")) weight = models.IntegerField(default=0, verbose_name=_("Weight")) + def slide(self): + return { + 'slide': self, + 'title': self.title, + 'template': 'projector/ProjectorSlide.html', + } + + def __unicode__(self): return self.title @@ -31,5 +40,5 @@ class ProjectorMessage(models.Model): return self.def_name -register_slidemodel(ProjectorSlide, category=_('Projector'), model_name=_('Projector Slide')) +register_slidemodel(ProjectorSlide, model_name=_('Projector Slide')) diff --git a/openslides/projector/projector.py b/openslides/projector/projector.py index 2d7d9b3b8..aeb6e0b85 100644 --- a/openslides/projector/projector.py +++ b/openslides/projector/projector.py @@ -3,7 +3,7 @@ from time import time from django.dispatch import receiver from django.utils.translation import ugettext as _ -from system import config +from config.models import config from openslides.projector.signals import projector_messages diff --git a/openslides/projector/templates/projector/ProjectorSlide.html b/openslides/projector/templates/projector/ProjectorSlide.html new file mode 100644 index 000000000..eb25adcc1 --- /dev/null +++ b/openslides/projector/templates/projector/ProjectorSlide.html @@ -0,0 +1,14 @@ +{% extends "base-projector.html" %} + +{% load i18n %} + +{% block title %}{{ block.super }} - {{ slide.title }}{% endblock %} + +{% block content %} + {% if slide.text %} +

{{ slide.title }}

+ {{ slide.text|safe|linebreaks }} + {% else %} +
{{ slide.title }}
+ {% endif %} +{% endblock %} diff --git a/openslides/projector/templates/projector/control.html b/openslides/projector/templates/projector/control.html index 612cbe015..1eebe4de2 100644 --- a/openslides/projector/templates/projector/control.html +++ b/openslides/projector/templates/projector/control.html @@ -77,14 +77,14 @@ {% for slide in slides %} {% if slide.model_slide %}