OpenSlides/openslides/utils/validate.py
Emanuel Schütze 3d264683ff Assignment improvements
- Use ckeditor for assignment description field (e.g. for candidatures
  using html).
- Use 2 decimal places for percentage of voting results (motions/assignments)
- Allow css style attributes 'float' and 'padding'.
- Remove progress bar in election result slide to get more space (height)
  for candidate rows.
2017-12-05 14:04:35 +01:00

33 lines
966 B
Python

import bleach
allowed_tags = [
'a', 'img', # links and images
'br', 'p', 'span', 'blockquote', # text layout
'strike', 'strong', 'u', 'em', 'sup', 'sub', 'pre', # text formatting
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', # headings
'ol', 'ul', 'li', # lists
'table', 'caption', 'thead', 'tbody', 'th', 'tr', 'td', # tables
]
allowed_attributes = {
'*': ['class', 'style'],
'img': ['alt', 'src', 'title'],
'a': ['href', 'title'],
'th': ['scope'],
'ol': ['start'],
}
allowed_styles = [
'color', 'background-color', 'height', 'width', 'text-align', 'float', 'padding'
]
def validate_html(html: str) -> str:
"""
This method takes a string and escapes all non-whitelisted html entries.
Every field of a model that is loaded trusted in the DOM should be validated.
"""
return bleach.clean(
html,
tags=allowed_tags,
attributes=allowed_attributes,
styles=allowed_styles)