From 6c932aa77ac2dfc0d271ec8abc0b98707c4e934c Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 31 Mar 2017 13:48:41 +0200 Subject: [PATCH] Support logos --- CHANGELOG | 1 + openslides/core/config.py | 14 ++++++ openslides/core/config_variables.py | 18 ++++++++ .../migrations/0005_auto_20170412_1258.py | 25 +++++++++++ openslides/core/models.py | 3 +- openslides/core/static/js/core/base.js | 43 +++++++++++++++++++ openslides/core/static/js/core/projector.js | 8 +++- .../core/static/templates/projector.html | 3 +- openslides/core/views.py | 8 +++- .../mediafiles/static/js/mediafiles/list.js | 19 +++++++- .../static/js/mediafiles/resources.js | 12 +++++- .../templates/mediafiles/mediafile-list.html | 38 +++++++++++++++- openslides/users/signals.py | 2 + 13 files changed, 187 insertions(+), 7 deletions(-) create mode 100644 openslides/core/migrations/0005_auto_20170412_1258.py diff --git a/CHANGELOG b/CHANGELOG index 2321a83d6..d7ca4f950 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,7 @@ Motions: Core: - No reload on logoff. OpenSlides is now a full single page application [#3172]. +- Adding support for choosing image files as logos. Version 2.1.1 (2017-04-05) diff --git a/openslides/core/config.py b/openslides/core/config.py index b2546ec3e..ca4b9306e 100644 --- a/openslides/core/config.py +++ b/openslides/core/config.py @@ -15,6 +15,7 @@ INPUT_TYPE_MAPPING = { 'colorpicker': str, 'datetimepicker': int, 'majorityMethod': str, + 'logo': dict, } @@ -104,6 +105,19 @@ class ConfigHandler: if not isinstance(comment['public'], bool): raise ConfigError(_('public property has to be bool.')) + if config_variable.input_type == 'logo': + if not isinstance(value, dict): + raise ConfigError(_('logo has to be a dict.')) + whitelist = ( + 'path', + 'display_name', + ) + for required_entry in whitelist: + if required_entry not in value: + raise ConfigError(_('{} has to be given.'.format(required_entry))) + if not isinstance(value[required_entry], str): + raise ConfigError(_('{} has to be a string.'.format(required_entry))) + # Save the new value to the database. try: db_value = ConfigStore.objects.get(key=key) diff --git a/openslides/core/config_variables.py b/openslides/core/config_variables.py index f672f3004..4119f7ecb 100644 --- a/openslides/core/config_variables.py +++ b/openslides/core/config_variables.py @@ -209,3 +209,21 @@ def get_config_variables(): weight=201, group='Projector', hidden=True) + + # Logos. + yield ConfigVariable( + name='logos_available', + default_value=['logo_projector_main'], + weight=300, + group='Logo', + hidden=True) + + yield ConfigVariable( + name='logo_projector_main', + default_value={ + 'display_name': 'Main projector logo', + 'path': ''}, + input_type='logo', + weight=301, + group='Logo', + hidden=True) diff --git a/openslides/core/migrations/0005_auto_20170412_1258.py b/openslides/core/migrations/0005_auto_20170412_1258.py new file mode 100644 index 000000000..18e58bb0d --- /dev/null +++ b/openslides/core/migrations/0005_auto_20170412_1258.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-04-12 10:58 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0004_auto_20170215_1624'), + ] + + operations = [ + migrations.AlterModelOptions( + name='configstore', + options={ + 'default_permissions': (), + 'permissions': ( + ('can_manage_config', 'Can manage configuration'), + ('can_manage_logos', 'Can manage logos') + ) + }, + ), + ] diff --git a/openslides/core/models.py b/openslides/core/models.py index a26b4ece5..af019b182 100644 --- a/openslides/core/models.py +++ b/openslides/core/models.py @@ -257,7 +257,8 @@ class ConfigStore(RESTModelMixin, models.Model): class Meta: default_permissions = () permissions = ( - ('can_manage_config', 'Can manage configuration'),) + ('can_manage_config', 'Can manage configuration'), + ('can_manage_logos', 'Can manage logos')) @classmethod def get_collection_string(cls): diff --git a/openslides/core/static/js/core/base.js b/openslides/core/static/js/core/base.js index 824ff5f33..8b3a76d76 100644 --- a/openslides/core/static/js/core/base.js +++ b/openslides/core/static/js/core/base.js @@ -580,6 +580,49 @@ angular.module('OpenSlidesApp.core', [ } ]) +.factory('Logos', [ + 'Config', + 'gettext', + function (Config, gettext) { + return { + getKeys: function () { + return Config.get('logos_available').value; + }, + getAll: function () { + var self = this; + return _.map(this.getKeys(), function (key) { + return self.getFromKey(key); + }); + }, + getFromKey: function (key) { + var config = Config.get(key).value; + config.key = key; + return config; + }, + isMediafileUsedAsLogo: function (mediafile) { + return _.find(this.getAll(), function (logoPlaceholder) { + return logoPlaceholder.path === mediafile.mediafileUrl; + }); + }, + canMediafileBeUsedAsLogo: function (mediafile) { + return mediafile.is_image; + }, + setMediafile: function (key, mediafile) { + var config = Config.get(key); + if (!mediafile || mediafile.canBeUsedAsLogo()) { + config.value.path = mediafile ? mediafile.mediafileUrl : ''; + Config.save(key); + } + }, + getLogosForMediafile: function (mediafile) { + return _.filter(this.getAll(), function (logoPlaceholder) { + return logoPlaceholder.path === mediafile.mediafileUrl; + }); + }, + }; + } +]) + .factory('Tag', [ 'DS', function(DS) { diff --git a/openslides/core/static/js/core/projector.js b/openslides/core/static/js/core/projector.js index fd769560d..b70a05101 100644 --- a/openslides/core/static/js/core/projector.js +++ b/openslides/core/static/js/core/projector.js @@ -150,7 +150,8 @@ angular.module('OpenSlidesApp.core.projector', ['OpenSlidesApp.core']) 'slides', 'Config', 'ProjectorID', - function($scope, $location, $timeout, Projector, slides, Config, ProjectorID) { + 'Logos', + function($scope, $location, $timeout, Projector, slides, Config, ProjectorID, Logos) { var projectorId = ProjectorID(); $scope.broadcast = 0; @@ -243,6 +244,11 @@ angular.module('OpenSlidesApp.core.projector', ['OpenSlidesApp.core']) } }); + $scope.getLogo = function (key) { + var logo = Logos.getFromKey(key); + return logo ? logo.path : void 0; + }; + $scope.$on('$destroy', function() { if ($scope.broadcastDeregister) { $scope.broadcastDeregister(); diff --git a/openslides/core/static/templates/projector.html b/openslides/core/static/templates/projector.html index 024914823..ea574438f 100644 --- a/openslides/core/static/templates/projector.html +++ b/openslides/core/static/templates/projector.html @@ -33,7 +33,8 @@