Introduce HtmlTextField, which cleans submitted HTML with nh3 against a tag/attribute allowlist, and use it for ContentAsset.description via Meta.field_classes. Edit descriptions with TinyMCE and render the sanitized HTML on the asset page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
979 B
Python
28 lines
979 B
Python
from django import forms
|
|
|
|
from privatestudio.studio.models import ContentAsset
|
|
from privatestudio.fields import HtmlTextField
|
|
|
|
|
|
class ContentAssetForm(forms.ModelForm):
|
|
class Meta:
|
|
model = ContentAsset
|
|
fields = [
|
|
"kind", "title", "description", "release_date",
|
|
"group", "season_number", "episode_number", "sequence_number",
|
|
]
|
|
widgets = {
|
|
"release_date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"),
|
|
"description": forms.Textarea(attrs={"rows": 4}),
|
|
}
|
|
field_classes = {
|
|
"description": HtmlTextField,
|
|
}
|
|
|
|
def __init__(self, *args, studio, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.fields["group"].queryset = studio.content_groups.all()
|
|
for field in self.fields.values():
|
|
css = "form-select" if isinstance(field.widget, forms.Select) else "form-control"
|
|
field.widget.attrs["class"] = css
|