Merge pull request #1831 from emanuelschuetze/templateFixes2

Several fixes for 2.0b2
This commit is contained in:
Oskar Hahn 2016-01-10 11:26:37 +01:00
commit dd120bbf91
8 changed files with 92 additions and 52 deletions

View File

@ -1,5 +1,6 @@
import mimetypes import mimetypes
from django.conf import settings
from django.db import models as dbmodels from django.db import models as dbmodels
from ..utils.rest_api import FileField, ModelSerializer, SerializerMethodField from ..utils.rest_api import FileField, ModelSerializer, SerializerMethodField
@ -26,6 +27,7 @@ class MediafileSerializer(ModelSerializer):
""" """
Serializer for mediafile.models.Mediafile objects. Serializer for mediafile.models.Mediafile objects.
""" """
media_url_prefix = SerializerMethodField()
filesize = SerializerMethodField() filesize = SerializerMethodField()
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -42,9 +44,13 @@ class MediafileSerializer(ModelSerializer):
'id', 'id',
'title', 'title',
'mediafile', 'mediafile',
'media_url_prefix',
'uploader', 'uploader',
'filesize', 'filesize',
'timestamp',) 'timestamp',)
def get_filesize(self, mediafile): def get_filesize(self, mediafile):
return mediafile.get_filesize() return mediafile.get_filesize()
def get_media_url_prefix(self, mediafile):
return settings.MEDIA_URL

View File

@ -4,24 +4,40 @@
angular.module('OpenSlidesApp.mediafiles', []) angular.module('OpenSlidesApp.mediafiles', [])
.factory('Mediafile', ['DS', function(DS) { .factory('Mediafile', [
return DS.defineResource({ 'DS',
name: 'mediafiles/mediafile', 'jsDataModel',
computed: { function(DS, jsDataModel) {
is_presentable: ['filetype', function (filetype) { var name = 'mediafiles/mediafile';
var PRESENTABLE_FILE_TYPES = ['application/pdf']; return DS.defineResource({
return _.contains(PRESENTABLE_FILE_TYPES, filetype); name: name,
}], computed: {
filename: [function () { is_presentable: ['filetype', function (filetype) {
var filename = this.mediafile.name; var PRESENTABLE_FILE_TYPES = ['application/pdf'];
return /\/(.+?)$/.exec(filename)[1]; return _.contains(PRESENTABLE_FILE_TYPES, filetype);
}], }],
title_or_filename: ['title', 'mediafile', function (title) { mediafileUrl: [function () {
return title || this.filename; 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) {}]); .run(['Mediafile', function(Mediafile) {}]);

View File

@ -82,22 +82,39 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
}; };
}) })
.controller('MediafileCreateCtrl', function($scope, $state, $timeout, Upload) { .controller('MediafileCreateCtrl', [
$scope.mediafile = {}; '$scope',
$scope.save = uploadFile($timeout, $scope, $state, Upload); '$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) { .controller('MediafileUpdateCtrl', [
$scope.mediafile = mediafile; '$scope',
$scope.save = uploadFile($timeout, $scope, $state, Upload, mediafile); '$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) { return function(file) {
file.upload = Upload.upload({ file.upload = Upload.upload({
url: '/rest/mediafiles/mediafile/' + (mediafile ? mediafile.id : ''), url: '/rest/mediafiles/mediafile/' + (mediafile ? mediafile.id : ''),
method: mediafile ? 'PUT' : 'POST', 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) { file.upload.then(function (response) {

View File

@ -53,11 +53,11 @@
<tbody> <tbody>
<tr ng-repeat="mediafile in mediafiles | filter: filter.search | <tr ng-repeat="mediafile in mediafiles | filter: filter.search |
orderBy: sortColumn:reverse"> orderBy: sortColumn:reverse">
<td><a ng-href="/media/{{ mediafile.mediafile.name }}" target="_self">{{ mediafile.title_or_filename }}</a> <td><a ng-href="{{ mediafile.mediafileUrl }}" target="_blank">{{ mediafile.title_or_filename }}</a>
<td class="optional">{{ mediafile.mediafile.type }} <td class="optional">{{ mediafile.mediafile.type }}
<td>{{ mediafile.filesize }} <td>{{ mediafile.filesize }}
<td>{{ mediafile.timestamp }} <td>{{ mediafile.timestamp }}
<td>{{ mediafile.uploader }} <td>{{ mediafile.uploader.get_full_name() }}
<td os-perms="mediafiles.can_manage core.can_manage_projector" class="nobr"> <td os-perms="mediafiles.can_manage core.can_manage_projector" class="nobr">
<!-- projector, TODO: add link to activate slide --> <!-- projector, TODO: add link to activate slide -->
<a href="#TODO" ng-if="mediafile.is_presentable" os-perms-lite="core.can_manage_projector" <a href="#TODO" ng-if="mediafile.is_presentable" os-perms-lite="core.can_manage_projector"

View File

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

View File

@ -71,11 +71,11 @@
</div> </div>
<div class="col-sm-4"> <div class="col-sm-4">
<!-- Category --> <!-- Category -->
<h3 translate>Category</h3> <h3 ng-if="motion.category" translate>Category</h3>
{{ motion.category.name }}</a> {{ motion.category.name }}
<!-- Tags --> <!-- Tags -->
<h3 translate>Tags</h3> <h3 ng-if="motion.tags.length > 0" translate>Tags</h3>
<span ng-repeat="tag in motion.tags"> <span ng-repeat="tag in motion.tags">
{{ tag.name }}{{$last ? '' : ', '}} {{ tag.name }}{{$last ? '' : ', '}}
</span> </span>
@ -100,11 +100,11 @@
</div> </div>
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<h3 translate>Voting result</h3> <h3 ng-if="motion.polls.length > 0" translate>Voting result</h3>
<ol class="slimlist"> <ol class="slimlist">
<li ng-repeat="poll in motion.polls" class="spacer"> <li ng-repeat="poll in motion.polls" class="spacer">
<translate>Vote</translate> <translate>Vote</translate>
<button os-perms-lite="motions.can_manage" ng-click="poll.isEditMode=true;" <button os-perms="motions.can_manage" ng-click="$parent.poll.isEditMode=true;"
class="btn btn-default btn-xs"> class="btn btn-default btn-xs">
<i class="fa fa-pencil"></i> <i class="fa fa-pencil"></i>
</button> </button>
@ -163,7 +163,7 @@
</div> </div>
</form> </form>
</div> </div>
<div ng-show="!poll.isEditMode && poll.yes >= -2" class="pollresults"> <div ng-show="!poll.isEditMode" class="pollresults">
<!-- yes --> <!-- yes -->
<div class="result_label"> <div class="result_label">
<i class="fa fa-thumbs-up"></i> <i class="fa fa-thumbs-up"></i>
@ -240,16 +240,16 @@
<div class="white-space-pre-line" ng-bind-html="motion.getReason()"></div> <div class="white-space-pre-line" ng-bind-html="motion.getReason()"></div>
</div> </div>
<!-- attachments <!-- attachments -->
TODO: make 'motion.attachments' useable and itteratable in template <h3 ng-if="motion.attachments.length > 0" translate>Attachments</h3>
<div ng-if="motion.attachments"> <ul>
<h3 translate>Attachments</h3> <li ng-repeat="attachment in motion.attachments">
</div> <a href="{{ attachment.mediafileUrl }}" target="_blank">{{ attachment.title_or_filename }}</a>
--> </ul>
<!-- log --> <!-- log -->
<button type="button" class="btn btn-default spacer" ng-click="isCollapsed = !isCollapsed" translate> <button type="button" class="btn btn-default spacer" ng-click="isCollapsed = !isCollapsed" translate>
Show log Show history
</button> </button>
<div uib-collapse="isCollapsed"> <div uib-collapse="isCollapsed">
<div class="well well-sm"> <div class="well well-sm">

View File

@ -546,7 +546,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
function($scope, $state, User, user) { function($scope, $state, User, user) {
$scope.user = user; // autoupdate is not activated $scope.user = user; // autoupdate is not activated
$scope.save = function (user) { $scope.save = function (user) {
User.save(user).then( User.save(user, { method: 'PATCH' }).then(
function(success) { function(success) {
$state.go('users.user.list'); $state.go('users.user.list');
}, },

View File

@ -37,9 +37,9 @@ class UserViewSet(ModelViewSet):
""" """
Returns True if the user has required permissions. 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') 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 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_see_extra_data') and
self.request.user.has_perm('users.can_manage')) self.request.user.has_perm('users.can_manage'))
@ -121,12 +121,13 @@ class UserViewSet(ModelViewSet):
'title', 'title',
'first_name', 'first_name',
'last_name', 'last_name',
'structure_level' 'structure_level',
'about_me',) 'about_me',)
for data in request.data.keys(): keys = list(request.data.keys())
if data not in whitelist: for key in keys:
# Non-staff users are allowed to send only some data. if key not in whitelist:
self.permission_denied(request) # Non-staff users are allowed to send only some data. Ignore other data.
del request.data[key]
# Validate data and update user. # Validate data and update user.
serializer = self.get_serializer( serializer = self.get_serializer(
user, user,