Skip to content

Commit

Permalink
Remove empty HTML info-slide if nothing inputted
Browse files Browse the repository at this point in the history
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 "`<p><br></p>`".
  • Loading branch information
tienne-B committed Jan 29, 2024
1 parent 45c2765 commit 2acd29a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tabbycat/motions/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -27,6 +28,11 @@ class Meta:
def __str__(self):
return self.text

def clean_fields(self, exclude=None):
super().clean_fields(exclude=exclude)
if not html2text(self.info_slide or '').isspace() and 'info_slide' not in exclude:
self.info_slide = None


class DebateTeamMotionPreference(models.Model):
"""Represents a motion preference submitted by a debate team."""
Expand Down

0 comments on commit 2acd29a

Please sign in to comment.