Merge pull request #1901 from emanuelschuetze/fix1895

Translate permission strings. (Fixes #1895)
This commit is contained in:
Norman Jäckel 2016-01-27 20:42:07 +01:00
commit 352e32334e
11 changed files with 88 additions and 43 deletions

View File

@ -7,7 +7,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models, transaction
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy, ugettext_noop
from django.utils.translation import ugettext_lazy
from openslides.core.config import config
from openslides.core.projector import Countdown
@ -266,9 +266,9 @@ class Item(RESTModelMixin, models.Model):
class Meta:
default_permissions = ()
permissions = (
('can_see', ugettext_noop("Can see agenda")),
('can_manage', ugettext_noop("Can manage agenda")),
('can_see_hidden_items', ugettext_noop("Can see hidden items and time scheduling of agenda")))
('can_see', 'Can see agenda'),
('can_manage', 'Can manage agenda'),
('can_see_hidden_items', 'Can see hidden items and time scheduling of agenda'))
unique_together = ('content_type', 'object_id')
def __str__(self):
@ -392,7 +392,7 @@ class Speaker(RESTModelMixin, models.Model):
class Meta:
default_permissions = ()
permissions = (
('can_be_speaker', ugettext_noop('Can put oneself on the list of speakers')),
('can_be_speaker', 'Can put oneself on the list of speakers'),
)
def __str__(self):

View File

@ -109,10 +109,10 @@ class Assignment(RESTModelMixin, models.Model):
class Meta:
default_permissions = ()
permissions = (
('can_see', ugettext_noop('Can see elections')),
('can_nominate_other', ugettext_noop('Can nominate another participant')),
('can_nominate_self', ugettext_noop('Can nominate oneself')),
('can_manage', ugettext_noop('Can manage elections')),
('can_see', 'Can see elections'),
('can_nominate_other', 'Can nominate another participant'),
('can_nominate_self', 'Can nominate oneself'),
('can_manage', 'Can manage elections'),
)
ordering = ('title', )
verbose_name = ugettext_noop('Election')

View File

@ -73,8 +73,7 @@ angular.module('OpenSlidesApp.assignments', [])
'AssignmentPoll',
'jsDataModel',
'gettext',
'gettextCatalog',
function ($http, DS, AssignmentRelatedUser, AssignmentPoll, jsDataModel, gettext, gettextCatalog) {
function ($http, DS, AssignmentRelatedUser, AssignmentPoll, jsDataModel, gettext) {
var name = 'assignments/assignment';
var phases;
return DS.defineResource({

View File

@ -2,7 +2,6 @@ from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import ugettext_noop
from jsonfield import JSONField
from openslides.mediafiles.models import Mediafile
@ -64,9 +63,9 @@ class Projector(RESTModelMixin, models.Model):
"""
default_permissions = ()
permissions = (
('can_see_projector', ugettext_noop('Can see the projector')),
('can_manage_projector', ugettext_noop('Can manage the projector')),
('can_see_frontpage', ugettext_noop('Can see the front page')))
('can_see_projector', 'Can see the projector'),
('can_manage_projector', 'Can manage the projector'),
('can_see_frontpage', 'Can see the front page'),)
@property
def elements(self):
@ -184,7 +183,7 @@ class Tag(RESTModelMixin, models.Model):
ordering = ('name',)
default_permissions = ()
permissions = (
('can_manage_tags', ugettext_noop('Can manage tags')),)
('can_manage_tags', 'Can manage tags'),)
def __str__(self):
return self.name
@ -204,7 +203,7 @@ class ConfigStore(models.Model):
class Meta:
default_permissions = ()
permissions = (
('can_manage_config', ugettext_noop('Can manage configuration')),)
('can_manage_config', 'Can manage configuration'),)
def get_root_rest_url(self):
"""
@ -230,7 +229,7 @@ class ChatMessage(RESTModelMixin, models.Model):
class Meta:
default_permissions = ()
permissions = (
('can_use_chat', ugettext_noop('Can use the chat')),)
('can_use_chat', 'Can use the chat'),)
def __str__(self):
return 'Message {}'.format(self.timestamp)

View File

@ -1,7 +1,6 @@
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_noop
from openslides.utils.search import user_name_helper
@ -38,9 +37,9 @@ class Mediafile(RESTModelMixin, models.Model):
ordering = ['title']
default_permissions = ()
permissions = (
('can_see', ugettext_noop('Can see the list of files')),
('can_upload', ugettext_noop('Can upload files')),
('can_manage', ugettext_noop('Can manage files')),)
('can_see', 'Can see the list of files'),
('can_upload', 'Can upload files'),
('can_manage', 'Can manage files'))
def __str__(self):
"""

View File

@ -115,10 +115,10 @@ class Motion(RESTModelMixin, models.Model):
class Meta:
default_permissions = ()
permissions = (
('can_see', ugettext_noop('Can see motions')),
('can_create', ugettext_noop('Can create motions')),
('can_support', ugettext_noop('Can support motions')),
('can_manage', ugettext_noop('Can manage motions')),
('can_see', 'Can see motions'),
('can_create', 'Can create motions'),
('can_support', 'Can support motions'),
('can_manage', 'Can manage motions'),
)
ordering = ('identifier', )
verbose_name = ugettext_noop('Motion')

View File

@ -161,10 +161,9 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
'MotionPoll',
'jsDataModel',
'gettext',
'gettextCatalog',
'operator',
'Config',
function(DS, MotionPoll, jsDataModel, gettext, gettextCatalog, operator, Config) {
function(DS, MotionPoll, jsDataModel, gettext, operator, Config) {
var name = 'motions/motion';
return DS.defineResource({
name: name,

View File

@ -8,7 +8,6 @@ from django.contrib.auth.models import (
PermissionsMixin,
)
from django.db import models
from django.utils.translation import ugettext_noop
from openslides.utils.search import user_name_helper
@ -146,9 +145,9 @@ class User(RESTModelMixin, PermissionsMixin, AbstractBaseUser):
class Meta:
default_permissions = ()
permissions = (
('can_see_name', ugettext_noop('Can see names of users')),
('can_see_extra_data', ugettext_noop('Can see extra data of users')),
('can_manage', ugettext_noop('Can manage users')),
('can_see_name', 'Can see names of users'),
('can_see_extra_data', 'Can see extra data of users'),
('can_manage', 'Can manage users'),
)
ordering = ('last_name', 'first_name', 'username', )

View File

@ -148,10 +148,22 @@ angular.module('OpenSlidesApp.users', [])
])
.factory('Group', [
'$http',
'DS',
function(DS) {
function($http, DS) {
var permissions;
return DS.defineResource({
name: 'users/group',
permissions: permissions,
getPermissions: function() {
if (!this.permissions) {
this.permissions = $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' })
.then(function(result) {
return result.data.actions.POST.permissions.choices;
});
}
return this.permissions;
}
});
}
])

View File

@ -96,8 +96,8 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
})
.state('users.group.create', {
resolve: {
permissions: function($http) {
return $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' });
permissions: function(Group) {
return Group.getPermissions();
}
}
})
@ -113,8 +113,8 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'@users.group': {}
},
resolve: {
permissions: function($http) {
return $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' });
permissions: function(Group) {
return Group.getPermissions();
}
}
})
@ -762,7 +762,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'permissions',
function($scope, $state, Group, permissions) {
// get all permissions
$scope.permissions = permissions.data.actions.POST.permissions.choices;
$scope.permissions = permissions;
$scope.group = {};
$scope.save = function (group) {
Group.create(group).then(
@ -782,7 +782,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'group',
function($scope, $state, Group, permissions, group) {
// get all permissions
$scope.permissions = permissions.data.actions.POST.permissions.choices;
$scope.permissions = permissions;
$scope.group = group; // autoupdate is not activated
$scope.save = function (group) {
Group.save(group).then(
@ -827,8 +827,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'$http',
'$stateParams',
'operator',
'gettextCatalog',
function ($rootScope, $scope, $http, $stateParams, operator, gettextCatalog) {
function ($rootScope, $scope, $http, $stateParams, operator ) {
$scope.alerts = [];
// get login info-text from server
@ -872,8 +871,47 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
$scope.closeThisDialog();
};
}
])
// Mark all permission strings for translation in JavaScript.
// (see models.py of each Django app)
.config([
'gettext',
function (gettext) {
// agenda
gettext('Can see agenda')
gettext('Can manage agenda')
gettext('Can see hidden items and time scheduling of agenda')
gettext('Can put oneself on the list of speakers')
// assignments
gettext('Can see elections')
gettext('Can nominate another participant')
gettext('Can nominate oneself')
gettext('Can manage elections')
// core
gettext('Can see the projector')
gettext('Can manage the projector')
gettext('Can see the dashboard')
gettext('Can manage tags')
gettext('Can manage configuration')
gettext('Can use the chat')
// mediafiles
gettext('Can see the list of files')
gettext('Can upload files')
gettext('Can manage files')
// motions
gettext('Can see motions')
gettext('Can create motions')
gettext('Can support motions')
gettext('Can manage motions')
// users
gettext('Can see names of users')
gettext('Can see extra data of users')
gettext('Can manage users')
}
]);
// this is code from angular.js. Find a way to call this function from this file
function getBlockNodes(nodes) {
// TODO(perf): just check if all items in `nodes` are siblings and if they are return the original

View File

@ -19,8 +19,8 @@
</div>
<div class="form-group">
<label for="selectPermissions" translate>Permissions</label>
<select multiple size="15" ng-options="permission.value as permission.display_name for permission in permissions"
ng-model="group.permissions" class="form-control" name="selectPermissions" required>
<select multiple size="15" ng-model="group.permissions" class="form-control" id="selectPermissions" required>
<option value="{{ permission.value }}" ng-repeat="permission in permissions">{{ permission.display_name | translate }}</option>
</select>
</div>