Merge pull request #3159 from FinnStutzenstein/Issue3140

fixing validate_html and motion saving (fixes #3140)
This commit is contained in:
Emanuel Schütze 2017-03-28 19:44:52 +02:00 committed by GitHub
commit 9e96db894c
5 changed files with 12 additions and 18 deletions

View File

@ -80,7 +80,8 @@ class ProjectorMessageSerializer(ModelSerializer):
fields = ('id', 'message', ) fields = ('id', 'message', )
def validate(self, data): def validate(self, data):
data['message'] = validate_html(data.get('message', '')) if 'message' in data:
data['message'] = validate_html(data['message'])
return data return data

View File

@ -259,7 +259,8 @@ class MotionChangeRecommendationSerializer(ModelSerializer):
'creation_time',) 'creation_time',)
def validate(self, data): def validate(self, data):
data['text'] = validate_html(data.get('text', '')) if 'text' in data:
data['text'] = validate_html(data['text'])
return data return data
@ -311,8 +312,10 @@ class MotionSerializer(ModelSerializer):
read_only_fields = ('state', 'recommendation',) # Some other fields are also read_only. See definitions above. read_only_fields = ('state', 'recommendation',) # Some other fields are also read_only. See definitions above.
def validate(self, data): def validate(self, data):
data['text'] = validate_html(data.get('text', '')) if 'text'in data:
data['reason'] = validate_html(data.get('reason', '')) data['text'] = validate_html(data['text'])
if 'reason' in data:
data['reason'] = validate_html(data['reason'])
validated_comments = [] validated_comments = []
for comment in data.get('comments', []): for comment in data.get('comments', []):
validated_comments.append(validate_html(comment)) validated_comments.append(validate_html(comment))

View File

@ -187,9 +187,6 @@ angular.module('OpenSlidesApp.motions.motionservices', ['OpenSlidesApp.motions',
return motion['comment ' + field.name]; return motion['comment ' + field.name];
}, },
function (obj) { function (obj) {
motion.title = motion.getTitle(-1);
motion.text = motion.getText(-1);
motion.reason = motion.getReason(-1);
motion['comment ' + field.name] = obj.editor.getData(); motion['comment ' + field.name] = obj.editor.getData();
} }
); );

View File

@ -844,13 +844,8 @@ angular.module('OpenSlidesApp.motions.site', [
return _.indexOf(motion.tags_id, tag.id) > -1; return _.indexOf(motion.tags_id, tag.id) > -1;
}; };
// Use this methon instead of Motion.save(), because otherwise
// you have to provide always a title and a text
$scope.save = function (motion) { $scope.save = function (motion) {
motion.title = motion.getTitle(-1); Motion.save(motion, {method: 'PATCH'});
motion.text = motion.getText(-1);
motion.reason = motion.getReason(-1);
Motion.save(motion);
}; };
// delete single motion // delete single motion
$scope.delete = function (motion) { $scope.delete = function (motion) {
@ -1134,10 +1129,7 @@ angular.module('OpenSlidesApp.motions.site', [
ngDialog.open(MotionForm.getDialog(motion)); ngDialog.open(MotionForm.getDialog(motion));
}; };
$scope.save = function (motion) { $scope.save = function (motion) {
motion.title = motion.getTitle(-1); Motion.save(motion, {method: 'PATCH'});
motion.text = motion.getText(-1);
motion.reason = motion.getReason(-1);
Motion.save(motion);
}; };
// support // support
$scope.support = function () { $scope.support = function () {

View File

@ -13,5 +13,6 @@ class TopicSerializer(ModelSerializer):
fields = ('id', 'title', 'text', 'attachments', 'agenda_item_id') fields = ('id', 'title', 'text', 'attachments', 'agenda_item_id')
def validate(self, data): def validate(self, data):
data['text'] = validate_html(data.get('text', '')) if 'text' in data:
data['text'] = validate_html(['text'])
return data return data