Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync upstream commits December #3

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions pretalx_pages/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import partial

import bleach
from csp.decorators import csp_update
from django import forms
Expand All @@ -17,10 +19,34 @@
UpdateView,
)
from i18nfield.forms import I18nModelForm
from pretalx.common.templatetags import rich_text
from pretalx.common.views.mixins import EventPermissionRequired

from .models import Page

ALLOWED_ATTRIBUTES = dict(rich_text.ALLOWED_ATTRIBUTES)
ALLOWED_ATTRIBUTES["a"] = ["href", "title", "target", "class"]
ALLOWED_ATTRIBUTES["p"] = ["class"]
ALLOWED_ATTRIBUTES["li"] = ["class"]
ALLOWED_ATTRIBUTES["img"] = ["src", "title", "alt", "class"]
CLEANER = bleach.Cleaner(
tags=rich_text.ALLOWED_TAGS
| {"img", "p", "br", "s", "sup", "sub", "u", "h3", "h4", "h5", "h6"},
attributes=ALLOWED_ATTRIBUTES,
protocols=rich_text.ALLOWED_PROTOCOLS | {"data"},
filters=[
partial(
bleach.linkifier.LinkifyFilter,
url_re=rich_text.TLD_REGEX,
parse_email=True,
email_re=rich_text.EMAIL_REGEX,
skip_tags={"pre", "code"},
callbacks=bleach.linkifier.DEFAULT_CALLBACKS
+ [rich_text.safelink_callback],
)
],
)


class PageList(EventPermissionRequired, ListView):
model = Page
Expand Down Expand Up @@ -232,27 +258,5 @@ def get_context_data(self, **kwargs):
ctx = super().get_context_data()
page = self.get_page()
ctx["page_title"] = page.title
from pretalx.common.templatetags.rich_text import (
ALLOWED_ATTRIBUTES,
ALLOWED_PROTOCOLS,
ALLOWED_TAGS,
md,
)

attributes = dict(ALLOWED_ATTRIBUTES)
attributes["a"] = ["href", "title", "target", "class"]
attributes["p"] = ["class"]
attributes["li"] = ["class"]
attributes["img"] = ["src", "title", "alt", "class"]

ctx["content"] = bleach.clean(
md.reset().convert(str(page.text)),
tags=ALLOWED_TAGS
| {"img", "p", "br", "s", "sup", "sub", "u", "h3", "h4", "h5", "h6"},
attributes=attributes,
protocols=ALLOWED_PROTOCOLS
| {
"data",
},
)
ctx["content"] = CLEANER.clean(rich_text.md.reset().convert(str(page.text)))
return ctx
Loading