From f9f3af245e7bf60cbe535c193ef35958490251fc Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Sun, 10 Jan 2016 10:52:44 +0100 Subject: [PATCH] Template fixes. - Use PATCH request for user profile update. --- openslides/mediafiles/serializers.py | 6 +++ .../mediafiles/static/js/mediafiles/base.js | 52 ++++++++++++------- .../mediafiles/static/js/mediafiles/site.js | 37 +++++++++---- .../templates/mediafiles/mediafile-list.html | 4 +- openslides/motions/static/js/motions/base.js | 2 +- .../templates/motions/motion-detail.html | 26 +++++----- openslides/users/static/js/users/site.js | 2 +- openslides/users/views.py | 15 +++--- 8 files changed, 92 insertions(+), 52 deletions(-) diff --git a/openslides/mediafiles/serializers.py b/openslides/mediafiles/serializers.py index 58b2de0ba..4f4b0e360 100644 --- a/openslides/mediafiles/serializers.py +++ b/openslides/mediafiles/serializers.py @@ -1,5 +1,6 @@ import mimetypes +from django.conf import settings from django.db import models as dbmodels from ..utils.rest_api import FileField, ModelSerializer, SerializerMethodField @@ -26,6 +27,7 @@ class MediafileSerializer(ModelSerializer): """ Serializer for mediafile.models.Mediafile objects. """ + media_url_prefix = SerializerMethodField() filesize = SerializerMethodField() def __init__(self, *args, **kwargs): @@ -42,9 +44,13 @@ class MediafileSerializer(ModelSerializer): 'id', 'title', 'mediafile', + 'media_url_prefix', 'uploader', 'filesize', 'timestamp',) def get_filesize(self, mediafile): return mediafile.get_filesize() + + def get_media_url_prefix(self, mediafile): + return settings.MEDIA_URL diff --git a/openslides/mediafiles/static/js/mediafiles/base.js b/openslides/mediafiles/static/js/mediafiles/base.js index e876de418..8a645f877 100644 --- a/openslides/mediafiles/static/js/mediafiles/base.js +++ b/openslides/mediafiles/static/js/mediafiles/base.js @@ -4,24 +4,40 @@ angular.module('OpenSlidesApp.mediafiles', []) -.factory('Mediafile', ['DS', function(DS) { - return DS.defineResource({ - name: 'mediafiles/mediafile', - computed: { - is_presentable: ['filetype', function (filetype) { - var PRESENTABLE_FILE_TYPES = ['application/pdf']; - return _.contains(PRESENTABLE_FILE_TYPES, filetype); - }], - filename: [function () { - var filename = this.mediafile.name; - return /\/(.+?)$/.exec(filename)[1]; - }], - title_or_filename: ['title', 'mediafile', function (title) { - return title || this.filename; - }] - } - }); -}]) +.factory('Mediafile', [ + 'DS', + 'jsDataModel', + function(DS, jsDataModel) { + var name = 'mediafiles/mediafile'; + return DS.defineResource({ + name: name, + computed: { + is_presentable: ['filetype', function (filetype) { + var PRESENTABLE_FILE_TYPES = ['application/pdf']; + return _.contains(PRESENTABLE_FILE_TYPES, filetype); + }], + mediafileUrl: [function () { + return this.media_url_prefix + this.mediafile.name; + }], + filename: [function () { + var filename = this.mediafile.name; + return /\/(.+?)$/.exec(filename)[1]; + }], + title_or_filename: ['title', 'mediafile', function (title) { + return title || this.filename; + }] + }, + relations: { + belongsTo: { + 'users/user': { + localField: 'uploader', + localKey: 'uploader_id', + } + } + } + }); + } +]) .run(['Mediafile', function(Mediafile) {}]); diff --git a/openslides/mediafiles/static/js/mediafiles/site.js b/openslides/mediafiles/static/js/mediafiles/site.js index 0a62c9998..85bc732ec 100644 --- a/openslides/mediafiles/static/js/mediafiles/site.js +++ b/openslides/mediafiles/static/js/mediafiles/site.js @@ -82,22 +82,39 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp. }; }) -.controller('MediafileCreateCtrl', function($scope, $state, $timeout, Upload) { - $scope.mediafile = {}; - $scope.save = uploadFile($timeout, $scope, $state, Upload); -}) +.controller('MediafileCreateCtrl', [ + '$scope', + '$state', + '$timeout', + 'operator', + 'Upload', + function($scope, $state, $timeout, operator, Upload) { + $scope.mediafile = {}; + $scope.save = uploadFile($timeout, $scope, $state, operator, Upload); + } +]) -.controller('MediafileUpdateCtrl', function($scope, $state, $timeout, Upload, Mediafile, mediafile) { - $scope.mediafile = mediafile; - $scope.save = uploadFile($timeout, $scope, $state, Upload, mediafile); -}); +.controller('MediafileUpdateCtrl', [ + '$scope', + '$state', + '$timeout', + 'operator', + 'Upload', + 'Mediafile', + 'mediafile', + function($scope, $state, $timeout, operator, Upload, Mediafile, mediafile) { + $scope.mediafile = mediafile; + $scope.save = uploadFile($timeout, $scope, $state, operator, Upload, mediafile); + } +]); -function uploadFile($timeout, $scope, $state, Upload, mediafile) { +function uploadFile($timeout, $scope, $state, operator, Upload, mediafile) { + console.log(operator.user); return function(file) { file.upload = Upload.upload({ url: '/rest/mediafiles/mediafile/' + (mediafile ? mediafile.id : ''), method: mediafile ? 'PUT' : 'POST', - data: {mediafile: file.newFile, title: file.title} + data: {mediafile: file.newFile, title: file.title, uploader_id: operator.user.id} }); file.upload.then(function (response) { diff --git a/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html b/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html index df631deb5..64cf01155 100644 --- a/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html +++ b/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html @@ -53,11 +53,11 @@ - {{ mediafile.title_or_filename }} + {{ mediafile.title_or_filename }} {{ mediafile.mediafile.type }} {{ mediafile.filesize }} {{ mediafile.timestamp }} - {{ mediafile.uploader }} + {{ mediafile.uploader.get_full_name() }}
-

Category

- {{ motion.category.name }}
+

Category

+ {{ motion.category.name }} -

Tags

+

Tags

{{ tag.name }}{{$last ? '' : ', '}} @@ -100,11 +100,11 @@
-

Voting result

+

Voting result

  1. Vote - @@ -163,7 +163,7 @@
-
+
@@ -240,16 +240,16 @@
- + +

Attachments

+
diff --git a/openslides/users/static/js/users/site.js b/openslides/users/static/js/users/site.js index ade115706..8b367038e 100644 --- a/openslides/users/static/js/users/site.js +++ b/openslides/users/static/js/users/site.js @@ -546,7 +546,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) function($scope, $state, User, user) { $scope.user = user; // autoupdate is not activated $scope.save = function (user) { - User.save(user).then( + User.save(user, { method: 'PATCH' }).then( function(success) { $state.go('users.user.list'); }, diff --git a/openslides/users/views.py b/openslides/users/views.py index 33936246a..a27806c99 100644 --- a/openslides/users/views.py +++ b/openslides/users/views.py @@ -37,9 +37,9 @@ class UserViewSet(ModelViewSet): """ Returns True if the user has required permissions. """ - if self.action in ('metadata', 'list', 'retrieve', 'partial_update'): + if self.action in ('metadata', 'list', 'retrieve', 'update', 'partial_update'): result = self.request.user.has_perm('users.can_see_name') - elif self.action in ('create', 'update', 'destroy', 'reset_password'): + elif self.action in ('create', 'destroy', 'reset_password'): result = (self.request.user.has_perm('users.can_see_name') and self.request.user.has_perm('users.can_see_extra_data') and self.request.user.has_perm('users.can_manage')) @@ -121,12 +121,13 @@ class UserViewSet(ModelViewSet): 'title', 'first_name', 'last_name', - 'structure_level' + 'structure_level', 'about_me',) - for data in request.data.keys(): - if data not in whitelist: - # Non-staff users are allowed to send only some data. - self.permission_denied(request) + keys = list(request.data.keys()) + for key in keys: + if key not in whitelist: + # Non-staff users are allowed to send only some data. Ignore other data. + del request.data[key] # Validate data and update user. serializer = self.get_serializer( user,