From 36edf31707d455d253cf6a8b4d3208e3bb26e0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Beaul=C3=A9?= Date: Sun, 28 Jan 2024 21:36:26 -0400 Subject: [PATCH] Remove empty HTML info-slide if nothing inputted This commit adds a cleaning method for motions, so that if no info-slide has been added, or it was removed, the info-slide re-becomes None rather than something like "`


`". --- tabbycat/motions/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tabbycat/motions/models.py b/tabbycat/motions/models.py index 94b0600d7dd..66aff53d92a 100644 --- a/tabbycat/motions/models.py +++ b/tabbycat/motions/models.py @@ -1,5 +1,6 @@ from django.db import models from django.utils.translation import gettext_lazy as _ +from html2text import html2text class Motion(models.Model): @@ -27,6 +28,11 @@ class Meta: def __str__(self): return self.text + def clean_fields(self, exclude=None): + super().clean_fields(exclude=exclude) + if html2text(self.info_slide or '').isspace() and 'info_slide' not in exclude: + self.info_slide = '' + class DebateTeamMotionPreference(models.Model): """Represents a motion preference submitted by a debate team."""