Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REVIEW] Creating exhibit with repeated name crashes the frontend #528

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions locale/pt_BR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 14 additions & 4 deletions src/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
49 changes: 44 additions & 5 deletions src/users/jinja2/users/exhibit-create.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,29 @@

<p id="artworks-selected">
{{ form.visible_fields()[2].as_hidden() }}
{{ form.visible_fields()[2].errors }}
<div id="artwork-error">
{{ form.visible_fields()[2].errors }}
</div>
</p>
<button type="button" id="next-info" class="select-btn next-btn">
{{ _('Next') }}
</button>
</div>
<div id="artwork-modal" class="tab">
<h4 class="modal-title">{{ _('Exhibit Information (2/2)') }}</h4>
<p class="upload-field" id="info-name-field">
<p id="exhibit-name-field" class="upload-field">
{{ form.visible_fields()[0] }}
{{ form.visible_fields()[0].errors }}
<div id="exhibit-name-error">
{{ form.visible_fields()[0].errors }}
</div>
</p>
<p class="gallery-title">{{ _('Your exhibit URL will look like this') }}</p>
<label class="url-helper">https://jandig.app/</label>
<p style="float: right; width: 65%">
<p id="exhibit-slug-field" style="float: right; width: 65%">
{{ form.visible_fields()[1] }}
{{ form.visible_fields()[1].errors }}
<div id="exhibit-slug-error">
{{ form.visible_fields()[1].errors }}
</div>
</p>
<input class="select-btn next-btn" onclick="cleanSlug()" type="submit" value="{{ _('Publish Exhibit') }}"/>
</div>
Expand All @@ -65,6 +71,7 @@
const ARTWORK_TAB = 1;

let currentTab = MARKER_TAB;

function showTab(tabNumber){
let tabs = $('.tab');
tabs.hide();
Expand All @@ -80,6 +87,7 @@
}
}
}

function activateNextButton(){
if(validateTab('artworks')){
$('#next-info').prop('disabled', false);
Expand All @@ -96,6 +104,17 @@
}
}

function checkMessage(innerText, messageList) {
var contain = false;

messageList.forEach((message) => {
if(innerText.includes(message))
contain = true;
});

return contain;
}

setInterval(activateNextButton, 100);
// modal events
$('#select-artworks').click(function(){
Expand All @@ -107,6 +126,26 @@
currentTab = ARTWORK_TAB;
showTab(currentTab);
})
$('#create-exhibit').ready(function () {
let artworkError = $('#artwork-error')[0].innerText;
let exhibitNameError = $('#exhibit-name-error')[0].innerText;
let exhibitSlugError = $('#exhibit-slug-error')[0].innerText;

if (checkMessage(artworkError, ["Este campo é obrigatório",
"This field is required"])) {
$('#form-modal').modal('toggle');
currentTab = MARKER_TAB;
showTab(currentTab);
} else if (checkMessage(exhibitNameError, ["This name is already being used",
"Este nome de exibição já está em uso"]) ||
checkMessage(exhibitSlugError, ["That exhibit slug is already in use",
"Este link de exibição já está sendo utilizado"])) {
$('#form-modal').modal('toggle');
currentTab = ARTWORK_TAB;
showTab(currentTab);
}
})

</script>
</section>
{% endblock %}