From 4ce0299cd079404320fd3b4924cdbd3148b2ac66 Mon Sep 17 00:00:00 2001
From: brenno-silva
Date: Mon, 6 Feb 2023 20:41:06 -0300
Subject: [PATCH 1/3] Adding form validation on slug and name
---
locale/pt_BR/LC_MESSAGES/django.po | 8 ++++++++
src/users/forms.py | 18 ++++++++++++++----
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/locale/pt_BR/LC_MESSAGES/django.po b/locale/pt_BR/LC_MESSAGES/django.po
index f4488058..04e980df 100644
--- a/locale/pt_BR/LC_MESSAGES/django.po
+++ b/locale/pt_BR/LC_MESSAGES/django.po
@@ -150,6 +150,14 @@ msgstr "Por favor sobrescreva o bloco \"conteúdo\" de seu modelo!"
msgid "Jandig Exhibitions"
msgstr "Exposições Jandig"
+#: src/ARte/users/forms.py:248
+msgid "That exhibit slug is already in use. Please choose another slug for your exhibit."
+msgstr "Este link de exibição já está sendo utilizado. Por favor escolha outro link para sua exibição."
+
+#: src/ARte/users/forms.py:250
+msgid "This name is already being used. Please choose another name for your exhibit."
+msgstr "Este nome de exibição já está em uso. Por favor, escolha outro nome."
+
#: src/ARte/core/jinja2/core/collection.jinja2:18
msgid "All Exhibits"
msgstr "Todas Exposições"
diff --git a/src/users/forms.py b/src/users/forms.py
index 7e321b84..e3b6cf9c 100644
--- a/src/users/forms.py
+++ b/src/users/forms.py
@@ -13,7 +13,7 @@
from PIL import Image
from pymarker.core import generate_marker_from_image, generate_patt_from_image
-from core.models import Marker, Object
+from core.models import Marker, Object, Exhibit
from .choices import COUNTRY_CHOICES
@@ -268,11 +268,21 @@ class ExhibitForm(forms.Form):
# FIXME: maybe this can be improved. Possible bug on max artworks per exhibit
artworks = forms.CharField(max_length=1000)
+ def clean_name(self):
+ name = self.cleaned_data["name"]
+ if Exhibit.objects.filter(slug=name).exists():
+ raise forms.ValidationError(
+ _("This name is already being used. Please choose another name for your exhibit."))
+ return name
+
def clean_slug(self):
- data = self.cleaned_data["slug"]
- if not re.match("^[a-zA-Z0-9_]*$", data):
+ slug = self.cleaned_data["slug"]
+ if not re.match("^[a-zA-Z0-9_]*$", slug):
raise forms.ValidationError(_("Url can't contain spaces or special characters"))
- return data
+ if Exhibit.objects.filter(slug=slug).exists():
+ raise forms.ValidationError(
+ _("That exhibit slug is already in use. Please choose another slug for your exhibit."))
+ return slug
def __init__(self, *args, **kwargs):
super(ExhibitForm, self).__init__(*args, **kwargs)
From d0e007910a5038a4746e69f5afb3c1eaadaa074d Mon Sep 17 00:00:00 2001
From: brenno-silva
Date: Tue, 7 Feb 2023 07:56:46 -0300
Subject: [PATCH 2/3] Added validation to exhibition slug and name
---
src/users/jinja2/users/exhibit-create.jinja2 | 37 +++++++++++++++++---
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/src/users/jinja2/users/exhibit-create.jinja2 b/src/users/jinja2/users/exhibit-create.jinja2
index 89068f8f..bb0f4b41 100644
--- a/src/users/jinja2/users/exhibit-create.jinja2
+++ b/src/users/jinja2/users/exhibit-create.jinja2
@@ -38,7 +38,9 @@