From e9fc4261b7979c27c2e1b32f1ae6925097b56e79 Mon Sep 17 00:00:00 2001 From: Shreyas Mayya Date: Mon, 21 Mar 2022 08:59:10 -0400 Subject: [PATCH] fix(profile): remove carriage returns from biographies on save --- tjdests/apps/profile/forms.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tjdests/apps/profile/forms.py b/tjdests/apps/profile/forms.py index 2f1f9aa..411e245 100644 --- a/tjdests/apps/profile/forms.py +++ b/tjdests/apps/profile/forms.py @@ -24,6 +24,17 @@ class ProfilePublishForm(forms.ModelForm): ) def clean(self) -> Dict[str, Any]: + data = self.data.copy() + + # Remove carriage returns from biography + if data.get("biography"): + data["biography"] = data["biography"].replace("\r", "") + self.instance.biography = data["biography"] + if len(data["biography"]) <= self.fields["biography"].max_length: + if self.errors.get("biography"): + del self.errors["biography"] + + self.data = data cleaned_data = super().clean() # Check the GPA: 0.0 <= GPA <= 5.0