|
6 | 6 |
|
7 | 7 |
|
8 | 8 | ALLOWED_TAGS = [ |
9 | | - "p", "ul", "ol", "li", "strong", "em", "div", "span", "a", |
10 | | - "blockquote", "pre", "figure", "figcaption", "br", "code", |
11 | | - "h1", "h2", "h3", "h4", "h5", "h6", |
12 | | - "picture", "source", "img", |
| 9 | + "p", |
| 10 | + "ul", |
| 11 | + "ol", |
| 12 | + "li", |
| 13 | + "strong", |
| 14 | + "em", |
| 15 | + "div", |
| 16 | + "span", |
| 17 | + "a", |
| 18 | + "blockquote", |
| 19 | + "pre", |
| 20 | + "figure", |
| 21 | + "figcaption", |
| 22 | + "br", |
| 23 | + "code", |
| 24 | + "h1", |
| 25 | + "h2", |
| 26 | + "h3", |
| 27 | + "h4", |
| 28 | + "h5", |
| 29 | + "h6", |
| 30 | + "picture", |
| 31 | + "source", |
| 32 | + "img", |
13 | 33 | ] |
14 | 34 | ALLOWED_ATTRIBUTES = [ |
15 | | - "alt", "class", "id", "src", "srcset", "href", "media", |
| 35 | + "alt", |
| 36 | + "class", |
| 37 | + "id", |
| 38 | + "src", |
| 39 | + "srcset", |
| 40 | + "href", |
| 41 | + "media", |
16 | 42 | ] |
17 | 43 |
|
| 44 | + |
18 | 45 | class RichTextField(models.TextField): |
19 | 46 | def formfield(self, **kwargs): |
20 | 47 | kwargs["widget"] = RichTextEditor |
21 | 48 | return super().formfield(**kwargs) |
22 | 49 |
|
23 | 50 | def pre_save(self, model_instance, add): |
24 | 51 | raw_html = getattr(model_instance, self.attname) |
25 | | - sanitized_html = bleach.clean(raw_html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES) |
| 52 | + sanitized_html = bleach.clean( |
| 53 | + raw_html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES |
| 54 | + ) |
26 | 55 | return sanitized_html |
27 | 56 |
|
28 | 57 |
|
|
0 commit comments