From 53a0fd66635ef721fda402454606dc34e122868e Mon Sep 17 00:00:00 2001 From: sudjoao Date: Thu, 24 Mar 2022 10:25:14 -0300 Subject: [PATCH 1/3] Create ListTextWidget class and update ExhbitForm Co-authored-by: Hugo Sobral --- src/ARte/core/forms.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ARte/core/forms.py b/src/ARte/core/forms.py index 4bdaeeb2..b5d4fd40 100644 --- a/src/ARte/core/forms.py +++ b/src/ARte/core/forms.py @@ -4,6 +4,25 @@ class UploadFileForm(forms.Form): file = forms.ImageField(required=False) +class ListTextWidget(forms.TextInput): + def __init__(self, *args, **kwargs): + super(ListTextWidget, self).__init__(*args, **kwargs) + self._name = 'exhibit-list' + self._list = Exhibit.objects.all().order_by('name') + self.attrs.update({'list':f'list__{self._name}'}) + + def render(self, name, value, attrs=None, renderer=None): + text_html = super(ListTextWidget, self).render(name, value, attrs=attrs) + data_list = f'' + for item in self._list: + data_list += f'' + data_list += '' + return (text_html + data_list) class ExhibitForm(forms.Form): - exhibit = forms.ModelChoiceField(queryset=Exhibit.objects.all().order_by('name')) \ No newline at end of file + exhibit = forms.CharField(required=True) + + def __init__(self, *args, **kwargs): + super(ExhibitForm, self).__init__(*args, **kwargs) + self.fields['exhibit'].widget = ListTextWidget() + self.fields['exhibit'].label = "" \ No newline at end of file From f623f4f2bef9b69191899e44c25047c3ca35f64b Mon Sep 17 00:00:00 2001 From: sudjoao Date: Thu, 24 Mar 2022 10:27:03 -0300 Subject: [PATCH 2/3] Update exhibit_select function to receiven just the exhibit Co-authored-by: Hugo Sobral --- src/ARte/core/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ARte/core/views.py b/src/ARte/core/views.py index f93e5d92..4eb3fa6f 100644 --- a/src/ARte/core/views.py +++ b/src/ARte/core/views.py @@ -88,7 +88,7 @@ def exhibit_select(request): form = ExhibitForm(request.POST) if form.is_valid(): exhibit = form.cleaned_data.get('exhibit') - return redirect("/" + exhibit.slug) + return redirect("/" + exhibit) else: form = ExhibitForm() From 36053f1b32d442c1f378972e3d50c26cb8c8aae3 Mon Sep 17 00:00:00 2001 From: sudjoao Date: Thu, 24 Mar 2022 10:28:42 -0300 Subject: [PATCH 3/3] Add new form in exhibit_select screen and remove unsed function Co-authored-by: Hugo Sobral Co-authored-by: Sofia Patrocinio --- .../core/jinja2/core/exhibit_select.jinja2 | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/ARte/core/jinja2/core/exhibit_select.jinja2 b/src/ARte/core/jinja2/core/exhibit_select.jinja2 index b0270085..22be5ce5 100644 --- a/src/ARte/core/jinja2/core/exhibit_select.jinja2 +++ b/src/ARte/core/jinja2/core/exhibit_select.jinja2 @@ -14,17 +14,9 @@

{{_("Choose the Exhibition you're seeing")}}

-
- -
-
+ {{ csrf_input }} - {% for field in form.visible_fields() %} -

- {{ field }} - {{ field.errors }} -

- {% endfor %} + {{form}}
@@ -32,22 +24,6 @@