Skip to content

Commit

Permalink
Merge pull request #347 from Instanssi/nh3-html-field
Browse files Browse the repository at this point in the history
NH3 html field
  • Loading branch information
katajakasa authored Apr 1, 2024
2 parents e27eb3d + 59a3e32 commit 93757f8
Show file tree
Hide file tree
Showing 75 changed files with 944 additions and 912 deletions.
Empty file.
11 changes: 11 additions & 0 deletions backend/Instanssi/common/html/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import Any

import nh3
from django.db.models import TextField


class SanitizedHtmlField(TextField):
def to_python(self, value: Any) -> str | None:
if value := super().to_python(value):
value = nh3.clean(value)
return value
20 changes: 20 additions & 0 deletions backend/Instanssi/ext_blog/migrations/0007_alter_blogentry_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.0.3 on 2024-04-01 22:05

from django.db import migrations

import Instanssi.common.html.fields


class Migration(migrations.Migration):

dependencies = [
("ext_blog", "0006_alter_blogentry_date"),
]

operations = [
migrations.AlterField(
model_name="blogentry",
name="text",
field=Instanssi.common.html.fields.SanitizedHtmlField(verbose_name="Teksti"),
),
]
3 changes: 2 additions & 1 deletion backend/Instanssi/ext_blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
from django.db.models import QuerySet
from django.utils import timezone

from Instanssi.common.html.fields import SanitizedHtmlField
from Instanssi.kompomaatti.models import Event


class BlogEntry(models.Model):
event = models.ForeignKey(Event, verbose_name="Tapahtuma", on_delete=models.PROTECT)
user = models.ForeignKey(User, verbose_name="Käyttäjä", on_delete=models.SET_NULL, null=True)
title = models.CharField("Otsikko", help_text="Lyhyt otsikko entrylle.", max_length=128)
text = models.TextField("Teksti")
text = SanitizedHtmlField("Teksti")
date = models.DateTimeField("Aika", default=timezone.now)
public = models.BooleanField(
"Julkinen",
Expand Down

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
55 changes: 55 additions & 0 deletions backend/Instanssi/management/site/assets/BlogView-B2-Dt3Bh.js

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Loading

0 comments on commit 93757f8

Please sign in to comment.