2 Commits
Author SHA1 Message Date
Shaun Kruger e582cb9234 Add icon config 2026-12-01 20:58:47 -07:00
Shaun KrugerandClaude Opus 5.5 5bb9a70c11 Add sanitized rich-text descriptions for content assets
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>
2026-12-01 20:57:31 -07:00
8 changed files with 78 additions and 2 deletions
+1 -1
View File
@@ -13,5 +13,5 @@ __pycache__/
db.sqlite3
privatestudio/settings/local.py
static/
privatestudio/static/bundle/
node_modules/
+42
View File
@@ -0,0 +1,42 @@
import nh3
from django import forms
from django.forms import Textarea
NH3_TAGS = {
"a",
"p",
"strong",
"img",
"ul",
"ol",
"li",
"b",
"s",
"u",
}
NH3_ATTR = {
"a": {
"href",
"target",
},
"img": {
"alt",
"src",
},
}
class HtmlTextField(forms.CharField):
widget = Textarea
def to_python(self, value):
value = super().to_python(value)
if value not in self.empty_values:
value = nh3.clean(
value,
tags=NH3_TAGS,
attributes=NH3_ATTR,
)
return value
+4
View File
@@ -1,6 +1,7 @@
from django import forms
from privatestudio.studio.models import ContentAsset
from privatestudio.fields import HtmlTextField
class ContentAssetForm(forms.ModelForm):
@@ -14,6 +15,9 @@ class ContentAssetForm(forms.ModelForm):
"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)
+3
View File
@@ -14,6 +14,9 @@
{# <meta name="description" content="{{ page.search_description }}" />#}
{# {% endif %}#}
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="{% static 'favicon.ico' %}" sizes="any" />
<link rel="icon" href="{% static 'favicon.svg' %}" type="image/svg+xml" />
<link rel="apple-touch-icon" href="{% static 'apple-touch-icon.png' %}" />
{# Force all links in the live preview panel to be opened in a new tab #}
{% if request.in_preview_panel %}
@@ -0,0 +1,16 @@
<script type="application/javascript">
tinymce.init({
selector: '{{ selector }}',
license_key: 'gpl',
menubar: '',
toolbar: 'undo redo | bold italic | bullist numlist | link emoticons',
plugins: [
'link', 'emoticons', 'lists'
],
setup: function (editor) {
editor.on('change', function () {
tinymce.triggerSave();
})
}
})
</script>
@@ -30,7 +30,7 @@
<dt class="col-sm-3">Title</dt>
<dd class="col-sm-9">{{ content_asset.title }}</dd>
<dt class="col-sm-3">Description</dt>
<dd class="col-sm-9">{{ content_asset.description|linebreaksbr|default:"—" }}</dd>
<dd class="col-sm-9">{{ content_asset.description|default:"—"|safe }}</dd>
<dt class="col-sm-3">Release date</dt>
<dd class="col-sm-9">{{ content_asset.release_date|default:"—" }}</dd>
<dt class="col-sm-3">Series / Collection</dt>
@@ -72,4 +72,6 @@
{% endif %}
</form>
{% endwith %}
{% include 'includes/_tinymce.html' with selector="textarea#id_description" %}
{% endblock %}
+1
View File
@@ -16,6 +16,7 @@ dependencies = [
"whitenoise~=6.11.0",
"pytz~=2026.5",
"django-allauth[socialaccount]~=65.0.2",
"nh3==0.2.20",
]
dynamic = ["version"]
+8
View File
@@ -16,3 +16,11 @@ form.simpleform label {
font-weight: bold;
font-size: 1.2em;
}
div.tox-tinymce div.tox-promotion {
display: none;
}
//span.tox-statusbar__branding {
// display: none;
//}