diff --git a/openslides/agenda/api.py b/openslides/agenda/api.py index e720b7164..0e68990b4 100644 --- a/openslides/agenda/api.py +++ b/openslides/agenda/api.py @@ -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 diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 6f8d28487..ee8ba87ea 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -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): """ diff --git a/openslides/agenda/slides.py b/openslides/agenda/slides.py index de62981fe..c1c24fdf0 100644 --- a/openslides/agenda/slides.py +++ b/openslides/agenda/slides.py @@ -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(): diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index bad944b70..0c4e55c13 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -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}) diff --git a/openslides/application/models.py b/openslides/application/models.py index c2b07c2c2..35e1f7d2c 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 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 diff --git a/openslides/application/views.py b/openslides/application/views.py index dd9a9a8bb..9f55aaaf8 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -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 %s?') % 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): diff --git a/openslides/default.settings.py b/openslides/default.settings.py index 56dd9a650..6fc5ef22f 100644 --- a/openslides/default.settings.py +++ b/openslides/default.settings.py @@ -11,7 +11,7 @@ """ # Django settings for openslides project. -from system.openslides_settings import * +from openslides_settings import * DEBUG = True TEMPLATE_DEBUG = DEBUG diff --git a/openslides/system/openslides_settings.py b/openslides/openslides_settings.py similarity index 98% rename from openslides/system/openslides_settings.py rename to openslides/openslides_settings.py index d0b8191a1..ed61544af 100644 --- a/openslides/system/openslides_settings.py +++ b/openslides/openslides_settings.py @@ -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 = ( diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index c9c099e46..a23e74e2d 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -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): diff --git a/openslides/participant/views.py b/openslides/participant/views.py index 3847101c2..9b3e81641 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -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') diff --git a/openslides/poll/models.py b/openslides/poll/models.py index ec63a30a3..89ccff15c 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -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) + diff --git a/openslides/projector/api.py b/openslides/projector/api.py index 84544188d..54c0e23e9 100644 --- a/openslides/projector/api.py +++ b/openslides/projector/api.py @@ -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 diff --git a/openslides/projector/models.py b/openslides/projector/models.py index 81e012f32..dae3d1440 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -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) diff --git a/openslides/projector/views.py b/openslides/projector/views.py index d67a5ae78..330071105 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -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')) diff --git a/openslides/system/__init__.py b/openslides/system/__init__.py index e69de29bb..27e2fc029 100644 --- a/openslides/system/__init__.py +++ b/openslides/system/__init__.py @@ -0,0 +1,3 @@ +from system.models import Config + +config = Config() diff --git a/openslides/system/admin.py b/openslides/system/admin.py index 607147d75..90ae727b1 100644 --- a/openslides/system/admin.py +++ b/openslides/system/admin.py @@ -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) diff --git a/openslides/system/api.py b/openslides/system/api.py index 25a5e7de5..e69de29bb 100644 --- a/openslides/system/api.py +++ b/openslides/system/api.py @@ -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() diff --git a/openslides/system/auth/AnonymousAuth.py b/openslides/system/auth/AnonymousAuth.py index 63b7575c6..c1e8b3b55 100644 --- a/openslides/system/auth/AnonymousAuth.py +++ b/openslides/system/auth/AnonymousAuth.py @@ -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']} diff --git a/openslides/system/forms.py b/openslides/system/forms.py index 89e919a46..a28eb26b6 100644 --- a/openslides/system/forms.py +++ b/openslides/system/forms.py @@ -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")) diff --git a/openslides/system/models.py b/openslides/system/models.py index 08ee5ea47..cd9ed3db1 100644 --- a/openslides/system/models.py +++ b/openslides/system/models.py @@ -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() + + diff --git a/openslides/system/templates/system/agenda.html b/openslides/system/templates/system/agenda.html index 08a079e9f..1479d2b15 100644 --- a/openslides/system/templates/system/agenda.html +++ b/openslides/system/templates/system/agenda.html @@ -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 %}