diff --git a/openslides/__init__.py b/openslides/__init__.py index 6f3afd118..1d73bd338 100644 --- a/openslides/__init__.py +++ b/openslides/__init__.py @@ -29,6 +29,7 @@ def get_version(version=None): return main + sub + def hg_version(): import socket import os @@ -69,6 +70,7 @@ def hg_version(): return version + import os, site SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 424eeb773..dac9b92d8 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -25,7 +25,7 @@ from projector.projector import SlideMixin from projector.api import register_slidemodel from agenda.api import is_summary -from utils.translation_ext import xugettext as _ +from utils.translation_ext import ugettext as _ class Item(MPTTModel, SlideMixin): diff --git a/openslides/application/models.py b/openslides/application/models.py index 2b09b368a..619bd4156 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -23,7 +23,7 @@ from projector.models import SlideMixin from participant.models import Profile from config.models import config from utils.utils import _propper_unicode -from utils.translation_ext import xugettext as _ +from utils.translation_ext import ugettext as _ from poll.models import BaseOption, BasePoll, CountVotesCast, CountInvalid, Vote diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 2d98a4a5e..6f6049faf 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -17,7 +17,7 @@ from participant.models import Profile from projector.projector import SlideMixin from projector.api import register_slidemodel from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption, PublishPollMixin -from utils.translation_ext import xugettext as _ +from utils.translation_ext import ugettext as _ class Assignment(models.Model, SlideMixin): prefix = 'assignment' diff --git a/openslides/config/models.py b/openslides/config/models.py index 4cee5caf6..e05fe94b5 100644 --- a/openslides/config/models.py +++ b/openslides/config/models.py @@ -15,7 +15,7 @@ import base64 from django.db import models from django.dispatch import receiver -from utils.translation_ext import xugettext as _ +from utils.translation_ext import ugettext as _ from openslides.config.signals import default_config_value diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index 515f1d5a9..0858ca777 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -19,19 +19,8 @@ from utils.forms import CssClassMixin from utils.translation_ext import LocalizedModelMultipleChoiceField # required for USER_VISIBLE_PERMISSIONS -from agenda.models import Item -from application.models import Application -from assignment.models import Assignment from participant.models import Profile -from config.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 ConfigStore._meta.permissions] -]) USER_APPLICATION_IMPORT_OPTIONS = [ @@ -63,27 +52,26 @@ class UsernameForm(ModelForm, CssClassMixin): model = User exclude = ('first_name', 'last_name', 'email', 'is_active','is_superuser', 'groups', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions') + class ProfileForm(ModelForm, CssClassMixin): class Meta: model = Profile -class GroupForm(ModelForm, CssClassMixin): - permissions = LocalizedModelMultipleChoiceField(queryset=Permission.objects.filter(codename__in=USER_VISIBLE_PERMISSIONS)) - def __init__(self, *args, **kwargs): - super(GroupForm, self).__init__(*args, **kwargs) - if kwargs.get('instance', None) is not None: - self.fields['permissions'].initial = [p.pk for p in kwargs['instance'].permissions.all()] +class GroupForm(ModelForm, CssClassMixin): + permissions = LocalizedModelMultipleChoiceField(queryset=Permission.objects.all()) class Meta: model = Group exclude = ('permissions',) + class UsersettingsForm(UserEditForm, CssClassMixin): class Meta: model = User fields = ('username', 'first_name', 'last_name', 'email') + class UserImportForm(Form, CssClassMixin): csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File")) application_handling = ChoiceField(required=True, choices=USER_APPLICATION_IMPORT_OPTIONS, label=_("For existing applications")) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index b1abe2ff8..598957af0 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -14,7 +14,7 @@ from django.db import models from django.db.models import Q from django.contrib.auth.models import User -from utils.translation_ext import xugettext as _ +from utils.translation_ext import ugettext as _ from participant.api import gen_password class Profile(models.Model): diff --git a/openslides/poll/models.py b/openslides/poll/models.py index d07c95f5f..7d86424d3 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -14,7 +14,7 @@ from django.db import models from projector.api import register_slidemodel from projector.models import SlideMixin -from utils.translation_ext import xugettext as _ +from utils.translation_ext import ugettext as _ class BaseOption(models.Model): poll = models.ForeignKey('BasePoll') diff --git a/openslides/projector/models.py b/openslides/projector/models.py index 3ba440ba0..885898ec6 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -4,7 +4,7 @@ from api import register_slidemodel from projector import SlideMixin from config.models import config -from utils.translation_ext import xugettext as _ +from utils.translation_ext import ugettext as _ class ProjectorSlide(models.Model, SlideMixin): diff --git a/openslides/utils/translation_ext.py b/openslides/utils/translation_ext.py index 887274363..7e86cd2d0 100644 --- a/openslides/utils/translation_ext.py +++ b/openslides/utils/translation_ext.py @@ -10,44 +10,47 @@ :license: GNU GPL, see LICENSE for more details. """ -from django.utils.translation import ugettext +from django.utils.translation import ugettext as _ugettext from django.forms import ChoiceField, ModelChoiceField, ModelMultipleChoiceField + class LocalizedModelChoiceField(ModelChoiceField): - def __init__(self, *args, **kwargs): - super(LocalizedModelChoiceField, self).__init__(*args, **kwargs) + def __init__(self, *args, **kwargs): + super(LocalizedModelChoiceField, self).__init__(*args, **kwargs) - def _localized_get_choices(self): - if hasattr(self, '_choices'): - return self._choices + def _localized_get_choices(self): + if hasattr(self, '_choices'): + return self._choices - c = [] - for (id, text) in super(LocalizedModelMultipleChoiceField, self)._get_choices(): - text = text.split(' | ')[-1] - c.append((id, ugettext(text))) - return c + c = [] + for (id, text) in super(LocalizedModelMultipleChoiceField, self)._get_choices(): + text = text.split(' | ')[-1] + c.append((id, ugettext(text))) + return c + + choices = property(_localized_get_choices, ChoiceField._set_choices) - choices = property(_localized_get_choices, ChoiceField._set_choices) class LocalizedModelMultipleChoiceField(ModelMultipleChoiceField): - def __init__(self, *args, **kwargs): - self.to_field_name = kwargs.get('to_field_name', None) - super(LocalizedModelMultipleChoiceField, self).__init__(*args, **kwargs) + def __init__(self, *args, **kwargs): + self.to_field_name = kwargs.get('to_field_name', None) + super(LocalizedModelMultipleChoiceField, self).__init__(*args, **kwargs) - def _localized_get_choices(self): - if hasattr(self, '_choices'): - return self._choices + def _localized_get_choices(self): + if hasattr(self, '_choices'): + return self._choices - c = [] - for (id, text) in super(LocalizedModelMultipleChoiceField, self)._get_choices(): - text = text.split(' | ')[-1] - c.append((id, ugettext(text))) - return c + c = [] + for (id, text) in super(LocalizedModelMultipleChoiceField, self)._get_choices(): + text = text.split(' | ')[-1] + c.append((id, ugettext(text))) + return c - choices = property(_localized_get_choices, ChoiceField._set_choices) + choices = property(_localized_get_choices, ChoiceField._set_choices) -def xugettext(msg, fixstr=False): + +def ugettext(msg, fixstr=False): if fixstr: return msg else: - return ugettext(msg) + return _ugettext(msg) diff --git a/openslides/utils/utils.py b/openslides/utils/utils.py index f679c1a20..f356229c1 100644 --- a/openslides/utils/utils.py +++ b/openslides/utils/utils.py @@ -24,6 +24,7 @@ from django.core.context_processors import csrf from django.contrib import messages from django.contrib.auth.models import Permission from django.utils.translation import ugettext as _ +from django.db.models import signals from openslides.utils.signals import template_manipulation @@ -88,7 +89,7 @@ def render_to_forbitten(request, error=_("Sorry, you have no rights to see this return HttpResponseForbidden(render_to_string('403.html', {'error': error}, context_instance=RequestContext(request))) -def delete_default_permissions(): +def delete_default_permissions(**kwargs): for p in Permission.objects.all(): if p.codename.startswith('add') or p.codename.startswith('delete') or p.codename.startswith('change'): p.delete() @@ -123,3 +124,7 @@ def encodedict(dict): for key in dict: newdict[key] = [unicode(dict[key][0].decode('utf-8'))] return newdict + + +signals.post_syncdb.connect(delete_default_permissions, + dispatch_uid = "openslides.utils.utils.delete_default_permissions")