diff --git a/cypress/integration/event.js b/cypress/integration/event.js new file mode 100644 index 0000000..784ea6a --- /dev/null +++ b/cypress/integration/event.js @@ -0,0 +1,30 @@ +describe('Event', () => { + it('creates event', () => { + cy.login() + cy.createAdminUnit().then(function(adminUnitId) { + cy.visit('/admin_unit/' + adminUnitId + '/events/create') + + cy.get('#name').type("Stadtfest") + + cy.select2('event_place_id', 'Neu') + cy.get('#new_event_place-location-city').type("Goslar") + cy.get('#new_place_container_search_link').click() + cy.select2('event_place_id', 'Gos', 'Goslar, 38640 Goslar') + + cy.select2('organizer_id', 'Neu') + cy.get('#new_organizer-location-city').type("Goslar") + cy.get('#new_organizer_container_search_link').click() + cy.select2('organizer_id', 'Mei', 'Meine Crew') + + cy.get('#submit').click() + cy.url().should('include', '/actions') + cy.get('div.alert').should('contain', 'Veranstaltung erfolgreich erstellt') + + cy.contains('a', 'Veranstaltung bearbeiten').click() + cy.url().should('include', '/update') + cy.get('#submit').click() + cy.url().should('include', '/manage/admin_unit/' + adminUnitId + '/events') + cy.get('div.alert').should('contain', 'Veranstaltung erfolgreich aktualisiert') + }) + }) + }) \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 17fad94..f4aa8a4 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -60,3 +60,19 @@ Cypress.Commands.add('login', (email = "test@test.de", password = "password") => cy.url().should('include', '/manage') cy.getCookie('session').should('exist') }) + +Cypress.Commands.add('select2', (selectId, textToEnter, expectedText = null, expectedValue = null) => { + cy.get('#select2-' + selectId + '-container').click() + cy.get('input[aria-controls="select2-' + selectId + '-results"]') + .type(textToEnter + '{enter}', { + delay: 500, + }) + + if (expectedText) { + cy.get('#select2-' + selectId + '-container').should('have.text', expectedText) + } + + if (expectedValue) { + cy.get('#' + selectId).should('have.value', expectedValue) + } +}) \ No newline at end of file diff --git a/messages.pot b/messages.pot index b0ea7ea..af6336b 100644 --- a/messages.pot +++ b/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-08-06 13:48+0200\n" +"POT-Creation-Date: 2021-08-07 11:28+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -647,8 +647,8 @@ msgstr "" #: project/forms/event.py:233 project/forms/reference.py:14 #: project/forms/reference.py:27 project/forms/reference_request.py:75 -#: project/templates/event/create.html:323 -#: project/templates/event/update.html:183 +#: project/templates/event/create.html:403 +#: project/templates/event/update.html:206 msgid "Rating" msgstr "" @@ -662,8 +662,8 @@ msgstr "" #: project/forms/event.py:245 project/forms/event.py:254 #: project/forms/event.py:318 project/forms/event_suggestion.py:50 #: project/templates/_macros.html:462 project/templates/_macros.html:618 -#: project/templates/event/create.html:248 -#: project/templates/event/update.html:133 +#: project/templates/event/create.html:328 +#: project/templates/event/update.html:156 #: project/templates/event_place/create.html:21 #: project/templates/event_place/delete.html:13 #: project/templates/event_place/update.html:21 @@ -681,8 +681,8 @@ msgstr "" #: project/forms/event.py:261 project/forms/event.py:270 #: project/forms/event.py:326 project/forms/event.py:376 #: project/forms/event_suggestion.py:60 project/templates/_macros.html:500 -#: project/templates/_macros.html:655 project/templates/event/create.html:223 -#: project/templates/event/update.html:124 +#: project/templates/_macros.html:655 project/templates/event/create.html:299 +#: project/templates/event/update.html:147 #: project/templates/organizer/create.html:17 #: project/templates/organizer/delete.html:13 #: project/templates/organizer/update.html:17 @@ -698,7 +698,7 @@ msgid "Enter new organizer" msgstr "" #: project/forms/event.py:276 project/templates/event/create.html:4 -#: project/templates/event/create.html:195 project/templates/layout.html:254 +#: project/templates/event/create.html:271 project/templates/layout.html:254 #: project/templates/manage/events.html:12 #: project/templates/manage/organizers.html:21 msgid "Create event" @@ -724,7 +724,7 @@ msgid "" "Organizers." msgstr "" -#: project/forms/event.py:335 project/templates/event/update.html:114 +#: project/forms/event.py:335 project/templates/event/update.html:137 #: project/templates/oauth2_token/list.html:21 msgid "Status" msgstr "" @@ -758,7 +758,7 @@ msgid "Select the status of the event." msgstr "" #: project/forms/event.py:347 project/templates/event/update.html:4 -#: project/templates/event/update.html:86 +#: project/templates/event/update.html:109 msgid "Update event" msgstr "" @@ -846,13 +846,13 @@ msgstr "" msgid "I would like to be notified by email after the review" msgstr "" -#: project/forms/event_suggestion.py:52 project/templates/event/create.html:253 +#: project/forms/event_suggestion.py:52 project/templates/event/create.html:333 msgid "" "Choose where the event takes place. If the venue is not yet in the list, " "just enter it." msgstr "" -#: project/forms/event_suggestion.py:62 project/templates/event/create.html:227 +#: project/forms/event_suggestion.py:62 project/templates/event/create.html:303 msgid "" "Select the organizer. If the organizer is not yet on the list, just enter" " it." @@ -1059,9 +1059,9 @@ msgstr "" #: project/templates/_macros.html:402 project/templates/_macros.html:578 #: project/templates/event/actions.html:12 -#: project/templates/event/create.html:202 +#: project/templates/event/create.html:278 #: project/templates/event/delete.html:13 -#: project/templates/event/update.html:93 +#: project/templates/event/update.html:116 #: project/templates/reference/delete.html:13 #: project/templates/widget/event_suggestion/create.html:197 msgid "Event" @@ -1348,8 +1348,8 @@ msgstr "" #: project/templates/admin_unit/create.html:49 #: project/templates/admin_unit/update.html:50 -#: project/templates/event/create.html:311 -#: project/templates/event/update.html:171 +#: project/templates/event/create.html:391 +#: project/templates/event/update.html:194 #: project/templates/event_place/create.html:47 #: project/templates/event_place/update.html:47 #: project/templates/organizer/create.html:46 @@ -1460,26 +1460,36 @@ msgid "Enter place or address" msgstr "" #: project/templates/event/create.html:97 +#: project/templates/event/create.html:210 #, python-format msgid "Just use %(term)s" msgstr "" -#: project/templates/event/create.html:212 -#: project/templates/event/update.html:103 +#: project/templates/event/create.html:200 +#: project/templates/event/update.html:96 +msgid "Enter organizer" +msgstr "" + +#: project/templates/event/create.html:288 +#: project/templates/event/update.html:126 msgid "Event date" msgstr "" -#: project/templates/event/create.html:273 +#: project/templates/event/create.html:320 +msgid "Switch to organizer search" +msgstr "" + +#: project/templates/event/create.html:353 msgid "Switch to place search" msgstr "" -#: project/templates/event/create.html:284 -#: project/templates/event/update.html:144 +#: project/templates/event/create.html:364 +#: project/templates/event/update.html:167 msgid "Access" msgstr "" -#: project/templates/event/create.html:298 -#: project/templates/event/update.html:158 +#: project/templates/event/create.html:378 +#: project/templates/event/update.html:181 msgid "Target group" msgstr "" @@ -1783,7 +1793,7 @@ msgstr "" msgid "Event successfully deleted" msgstr "" -#: project/views/event.py:380 +#: project/views/event.py:384 msgid "Referenced event changed" msgstr "" diff --git a/project/static/site.js b/project/static/site.js index 60e0476..ef3d956 100644 --- a/project/static/site.js +++ b/project/static/site.js @@ -254,6 +254,13 @@ function reset_place_form(prefix = '') { $('#' + prefix + 'location-longitude').val(''); } +function reset_organizer_form(prefix = '') { + $('#' + prefix + 'name').val(''); + $('#' + prefix + 'location-street').val(''); + $('#' + prefix + 'location-postalCode').val(''); + $('#' + prefix + 'location-city').val(''); +} + function fill_place_form_with_gmaps_place(place, prefix = '', location_only = false) { var street_number = ""; var route = ""; diff --git a/project/templates/_macros.html b/project/templates/_macros.html index a76d8d0..f12265a 100644 --- a/project/templates/_macros.html +++ b/project/templates/_macros.html @@ -10,7 +10,7 @@ {% set is_required = kwargs['is_required'] if 'is_required' in kwargs else field.flags.required %} {% set label_text = field.label.text + ' *' if is_required else field.label.text %}
- {% if 'ri' in kwargs and kwargs['ri'] == 'checkbox' %} + {% if 'label_hidden' in kwargs or ('ri' in kwargs and kwargs['ri'] == 'checkbox') %} {% else %} {{ field.label(text=label_text, class="mb-0") }} {% endif %} diff --git a/project/templates/event/create.html b/project/templates/event/create.html index 2d84954..178d156 100644 --- a/project/templates/event/create.html +++ b/project/templates/event/create.html @@ -37,8 +37,8 @@ $( function() { } }, organizer_id: { - min: { - param: 1, + required: { + param: true, depends: function(element) { return $('input[type=radio][name=organizer_choice]:checked').val() == "1"; } @@ -176,6 +176,75 @@ $( function() { } } + $('#organizer_id').select2({ + width: '100%', + theme: 'bootstrap4', + tags: true, + ajax: { + url: "{{ url_for('api_v1_organization_organizer_list', id=admin_unit.id) }}", + dataType: 'json', + delay: 250, + cache: true, + data: function (params) { + return { + name: params.term, + per_page: 5 + }; + }, + processResults: function (data) { + return { + results: data.items.map(p => ({"id": p.id, "text": p.name})) + }; + } + }, + placeholder: "{{ _('Enter organizer') }}", + createTag: function (params) { + var term = $.trim(params.term); + + if (term === '') { + return null; + } + + return { + id: term, + text: "{{ _('Just use %(term)s', term='%(term)s') }}".replace("%(term)s", term), + term: term, + is_new_tag: true + } + }, + insertTag: function (data, tag) { + data.push(tag); + }, + templateResult: function (state) { + if ("is_new_tag" in state) { + return $("" + state.text + ""); + } + return state.text; + } + }); + + $('#organizer_id').on('select2:close', function (e) { + var dataArray = $(e.target).select2('data'); + var data = {}; + + if (dataArray.length > 0) { + data = dataArray[0]; + } + + if ("is_new_tag" in data) { + $(this).val(null).trigger('change'); + $('input[type=radio][name=organizer_choice][value=2]').click(); + reset_organizer_form('new_organizer-'); + + $('#new_organizer-name').val(data.term); + + $('#new_organizer_container').find(':input').valid(); + $(this).removeClass('is-valid'); + } else { + $(this).valid(); + } + }); + $('input[type=radio][name=organizer_choice]').on('change', function() { update_organizer_container($(this).val()); }); @@ -184,6 +253,13 @@ $( function() { $(this).valid(); }); + $('#new_organizer_container_search_link').click(function(e){ + e.preventDefault(); + e.stopPropagation(); + reset_organizer_form('new_organizer-'); + $('input[type=radio][name=organizer_choice][value=1]').click(); + }); + update_organizer_container($('input[type=radio][name=organizer_choice]:checked').val()); {{ render_end_container_handling() }} @@ -225,11 +301,11 @@ $( function() {
{{ _("Select the organizer. If the organizer is not yet on the list, just enter it.") }}
- {{ render_radio_buttons(form.organizer_choice) }} +
{{ render_radio_buttons(form.organizer_choice) }}
- {{ render_field_with_errors(form.organizer_id, class="autocomplete w-100", is_required=True) }} + {{ render_field_with_errors(form.organizer_id, class="w-100", label_hidden=True) }}
@@ -239,6 +315,10 @@ $( function() { {{ render_field_with_errors(form.new_organizer.form.location.street) }} {{ render_field_with_errors(form.new_organizer.form.location.postalCode) }} {{ render_field_with_errors(form.new_organizer.form.location.city) }} + +
@@ -255,7 +335,7 @@ $( function() {
- {{ render_field_with_errors(form.event_place_id, class="w-100", is_required=True) }} + {{ render_field_with_errors(form.event_place_id, class="w-100", label_hidden=True) }}
diff --git a/project/templates/event/update.html b/project/templates/event/update.html index 31c7c7e..790035f 100644 --- a/project/templates/event/update.html +++ b/project/templates/event/update.html @@ -73,6 +73,29 @@ placeholder: "{{ _('Enter place or address') }}" }); + $('#organizer_id').select2({ + width: '100%', + theme: 'bootstrap4', + ajax: { + url: "{{ url_for('api_v1_organization_organizer_list', id=event.admin_unit.id) }}", + dataType: 'json', + delay: 250, + cache: true, + data: function (params) { + return { + name: params.term, + per_page: 5 + }; + }, + processResults: function (data) { + return { + results: data.items.map(p => ({"id": p.id, "text": p.name})) + }; + } + }, + placeholder: "{{ _('Enter organizer') }}" + }); + $('#organizer_id,#event_place_id').on('select2:select', function (e) { $(this).valid(); }); @@ -124,7 +147,7 @@ {{ _('Organizer') }}
- {{ render_field_with_errors(form.organizer_id, class="autocomplete w-100") }} + {{ render_field_with_errors(form.organizer_id, class="w-100", label_hidden=True) }}
@@ -133,7 +156,7 @@ {{ _('Place') }}
- {{ render_field_with_errors(form.event_place_id, class="w-100") }} + {{ render_field_with_errors(form.event_place_id, class="w-100", label_hidden=True) }}
diff --git a/project/translations/de/LC_MESSAGES/messages.mo b/project/translations/de/LC_MESSAGES/messages.mo index 603ae8f..9476bdc 100644 Binary files a/project/translations/de/LC_MESSAGES/messages.mo and b/project/translations/de/LC_MESSAGES/messages.mo differ diff --git a/project/translations/de/LC_MESSAGES/messages.po b/project/translations/de/LC_MESSAGES/messages.po index da760e3..14e9c68 100644 --- a/project/translations/de/LC_MESSAGES/messages.po +++ b/project/translations/de/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-08-06 13:48+0200\n" +"POT-Creation-Date: 2021-08-07 11:28+0200\n" "PO-Revision-Date: 2020-06-07 18:51+0200\n" "Last-Translator: FULL NAME \n" "Language: de\n" @@ -674,8 +674,8 @@ msgstr "Wähle Kategorien, die zur Veranstaltung passen." #: project/forms/event.py:233 project/forms/reference.py:14 #: project/forms/reference.py:27 project/forms/reference_request.py:75 -#: project/templates/event/create.html:323 -#: project/templates/event/update.html:183 +#: project/templates/event/create.html:403 +#: project/templates/event/update.html:206 msgid "Rating" msgstr "Bewertung" @@ -691,8 +691,8 @@ msgstr "" #: project/forms/event.py:245 project/forms/event.py:254 #: project/forms/event.py:318 project/forms/event_suggestion.py:50 #: project/templates/_macros.html:462 project/templates/_macros.html:618 -#: project/templates/event/create.html:248 -#: project/templates/event/update.html:133 +#: project/templates/event/create.html:328 +#: project/templates/event/update.html:156 #: project/templates/event_place/create.html:21 #: project/templates/event_place/delete.html:13 #: project/templates/event_place/update.html:21 @@ -710,8 +710,8 @@ msgstr "Neuen Ort eingeben" #: project/forms/event.py:261 project/forms/event.py:270 #: project/forms/event.py:326 project/forms/event.py:376 #: project/forms/event_suggestion.py:60 project/templates/_macros.html:500 -#: project/templates/_macros.html:655 project/templates/event/create.html:223 -#: project/templates/event/update.html:124 +#: project/templates/_macros.html:655 project/templates/event/create.html:299 +#: project/templates/event/update.html:147 #: project/templates/organizer/create.html:17 #: project/templates/organizer/delete.html:13 #: project/templates/organizer/update.html:17 @@ -727,7 +727,7 @@ msgid "Enter new organizer" msgstr "Neuen Veranstalter eingeben" #: project/forms/event.py:276 project/templates/event/create.html:4 -#: project/templates/event/create.html:195 project/templates/layout.html:254 +#: project/templates/event/create.html:271 project/templates/layout.html:254 #: project/templates/manage/events.html:12 #: project/templates/manage/organizers.html:21 msgid "Create event" @@ -757,7 +757,7 @@ msgstr "" "Wähle den Veranstalter. Du kannst Veranstalter unter Verwaltung > " "Veranstalter hinzufügen und ändern." -#: project/forms/event.py:335 project/templates/event/update.html:114 +#: project/forms/event.py:335 project/templates/event/update.html:137 #: project/templates/oauth2_token/list.html:21 msgid "Status" msgstr "Status" @@ -791,7 +791,7 @@ msgid "Select the status of the event." msgstr "Wähle den Status der Veranstaltung." #: project/forms/event.py:347 project/templates/event/update.html:4 -#: project/templates/event/update.html:86 +#: project/templates/event/update.html:109 msgid "Update event" msgstr "Veranstaltung aktualisieren" @@ -879,7 +879,7 @@ msgstr "Bitte gib deine Email-Adresse oder deine Telefonnummer für die Prüfung msgid "I would like to be notified by email after the review" msgstr "Ich möchte per Email benachrichtigt werden nach der Prüfung" -#: project/forms/event_suggestion.py:52 project/templates/event/create.html:253 +#: project/forms/event_suggestion.py:52 project/templates/event/create.html:333 msgid "" "Choose where the event takes place. If the venue is not yet in the list, " "just enter it." @@ -887,7 +887,7 @@ msgstr "" "Wähle aus, wo die Veranstaltung stattfindet. Ist der Veranstaltungsort " "noch nicht in der Liste, trage ihn einfach ein." -#: project/forms/event_suggestion.py:62 project/templates/event/create.html:227 +#: project/forms/event_suggestion.py:62 project/templates/event/create.html:303 msgid "" "Select the organizer. If the organizer is not yet on the list, just enter" " it." @@ -1096,9 +1096,9 @@ msgstr "Zuletzt aktualisiert am %(updated_at)s." #: project/templates/_macros.html:402 project/templates/_macros.html:578 #: project/templates/event/actions.html:12 -#: project/templates/event/create.html:202 +#: project/templates/event/create.html:278 #: project/templates/event/delete.html:13 -#: project/templates/event/update.html:93 +#: project/templates/event/update.html:116 #: project/templates/reference/delete.html:13 #: project/templates/widget/event_suggestion/create.html:197 msgid "Event" @@ -1387,8 +1387,8 @@ msgstr "Bearbeiten" #: project/templates/admin_unit/create.html:49 #: project/templates/admin_unit/update.html:50 -#: project/templates/event/create.html:311 -#: project/templates/event/update.html:171 +#: project/templates/event/create.html:391 +#: project/templates/event/update.html:194 #: project/templates/event_place/create.html:47 #: project/templates/event_place/update.html:47 #: project/templates/organizer/create.html:46 @@ -1501,26 +1501,36 @@ msgid "Enter place or address" msgstr "Orte oder Adresse eingeben" #: project/templates/event/create.html:97 +#: project/templates/event/create.html:210 #, python-format msgid "Just use %(term)s" msgstr "Verwende einfach %(term)s" -#: project/templates/event/create.html:212 -#: project/templates/event/update.html:103 +#: project/templates/event/create.html:200 +#: project/templates/event/update.html:96 +msgid "Enter organizer" +msgstr "Veranstalter eingeben" + +#: project/templates/event/create.html:288 +#: project/templates/event/update.html:126 msgid "Event date" msgstr "Termin" -#: project/templates/event/create.html:273 +#: project/templates/event/create.html:320 +msgid "Switch to organizer search" +msgstr "Zur Veranstaltersuche wechseln" + +#: project/templates/event/create.html:353 msgid "Switch to place search" msgstr "Zur Ortssuche wechseln" -#: project/templates/event/create.html:284 -#: project/templates/event/update.html:144 +#: project/templates/event/create.html:364 +#: project/templates/event/update.html:167 msgid "Access" msgstr "Zugang" -#: project/templates/event/create.html:298 -#: project/templates/event/update.html:158 +#: project/templates/event/create.html:378 +#: project/templates/event/update.html:181 msgid "Target group" msgstr "Zielgruppe" @@ -1827,7 +1837,7 @@ msgstr "Der eingegebene Name entspricht nicht dem Namen der Veranstaltung" msgid "Event successfully deleted" msgstr "Veranstaltung erfolgreich gelöscht" -#: project/views/event.py:380 +#: project/views/event.py:384 msgid "Referenced event changed" msgstr "Empfohlene Veranstaltung wurde geändert" diff --git a/project/translations/en/LC_MESSAGES/messages.mo b/project/translations/en/LC_MESSAGES/messages.mo index 07ccd8f..bd9a4fc 100644 Binary files a/project/translations/en/LC_MESSAGES/messages.mo and b/project/translations/en/LC_MESSAGES/messages.mo differ diff --git a/project/translations/en/LC_MESSAGES/messages.po b/project/translations/en/LC_MESSAGES/messages.po index ed92e3f..da0f454 100644 --- a/project/translations/en/LC_MESSAGES/messages.po +++ b/project/translations/en/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-08-06 13:48+0200\n" +"POT-Creation-Date: 2021-08-07 11:28+0200\n" "PO-Revision-Date: 2021-04-30 15:04+0200\n" "Last-Translator: FULL NAME \n" "Language: en\n" @@ -648,8 +648,8 @@ msgstr "" #: project/forms/event.py:233 project/forms/reference.py:14 #: project/forms/reference.py:27 project/forms/reference_request.py:75 -#: project/templates/event/create.html:323 -#: project/templates/event/update.html:183 +#: project/templates/event/create.html:403 +#: project/templates/event/update.html:206 msgid "Rating" msgstr "" @@ -663,8 +663,8 @@ msgstr "" #: project/forms/event.py:245 project/forms/event.py:254 #: project/forms/event.py:318 project/forms/event_suggestion.py:50 #: project/templates/_macros.html:462 project/templates/_macros.html:618 -#: project/templates/event/create.html:248 -#: project/templates/event/update.html:133 +#: project/templates/event/create.html:328 +#: project/templates/event/update.html:156 #: project/templates/event_place/create.html:21 #: project/templates/event_place/delete.html:13 #: project/templates/event_place/update.html:21 @@ -682,8 +682,8 @@ msgstr "" #: project/forms/event.py:261 project/forms/event.py:270 #: project/forms/event.py:326 project/forms/event.py:376 #: project/forms/event_suggestion.py:60 project/templates/_macros.html:500 -#: project/templates/_macros.html:655 project/templates/event/create.html:223 -#: project/templates/event/update.html:124 +#: project/templates/_macros.html:655 project/templates/event/create.html:299 +#: project/templates/event/update.html:147 #: project/templates/organizer/create.html:17 #: project/templates/organizer/delete.html:13 #: project/templates/organizer/update.html:17 @@ -699,7 +699,7 @@ msgid "Enter new organizer" msgstr "" #: project/forms/event.py:276 project/templates/event/create.html:4 -#: project/templates/event/create.html:195 project/templates/layout.html:254 +#: project/templates/event/create.html:271 project/templates/layout.html:254 #: project/templates/manage/events.html:12 #: project/templates/manage/organizers.html:21 msgid "Create event" @@ -725,7 +725,7 @@ msgid "" "Organizers." msgstr "" -#: project/forms/event.py:335 project/templates/event/update.html:114 +#: project/forms/event.py:335 project/templates/event/update.html:137 #: project/templates/oauth2_token/list.html:21 msgid "Status" msgstr "" @@ -759,7 +759,7 @@ msgid "Select the status of the event." msgstr "" #: project/forms/event.py:347 project/templates/event/update.html:4 -#: project/templates/event/update.html:86 +#: project/templates/event/update.html:109 msgid "Update event" msgstr "" @@ -847,13 +847,13 @@ msgstr "" msgid "I would like to be notified by email after the review" msgstr "" -#: project/forms/event_suggestion.py:52 project/templates/event/create.html:253 +#: project/forms/event_suggestion.py:52 project/templates/event/create.html:333 msgid "" "Choose where the event takes place. If the venue is not yet in the list, " "just enter it." msgstr "" -#: project/forms/event_suggestion.py:62 project/templates/event/create.html:227 +#: project/forms/event_suggestion.py:62 project/templates/event/create.html:303 msgid "" "Select the organizer. If the organizer is not yet on the list, just enter" " it." @@ -1060,9 +1060,9 @@ msgstr "" #: project/templates/_macros.html:402 project/templates/_macros.html:578 #: project/templates/event/actions.html:12 -#: project/templates/event/create.html:202 +#: project/templates/event/create.html:278 #: project/templates/event/delete.html:13 -#: project/templates/event/update.html:93 +#: project/templates/event/update.html:116 #: project/templates/reference/delete.html:13 #: project/templates/widget/event_suggestion/create.html:197 msgid "Event" @@ -1349,8 +1349,8 @@ msgstr "" #: project/templates/admin_unit/create.html:49 #: project/templates/admin_unit/update.html:50 -#: project/templates/event/create.html:311 -#: project/templates/event/update.html:171 +#: project/templates/event/create.html:391 +#: project/templates/event/update.html:194 #: project/templates/event_place/create.html:47 #: project/templates/event_place/update.html:47 #: project/templates/organizer/create.html:46 @@ -1461,26 +1461,36 @@ msgid "Enter place or address" msgstr "" #: project/templates/event/create.html:97 +#: project/templates/event/create.html:210 #, python-format msgid "Just use %(term)s" msgstr "" -#: project/templates/event/create.html:212 -#: project/templates/event/update.html:103 +#: project/templates/event/create.html:200 +#: project/templates/event/update.html:96 +msgid "Enter organizer" +msgstr "" + +#: project/templates/event/create.html:288 +#: project/templates/event/update.html:126 msgid "Event date" msgstr "" -#: project/templates/event/create.html:273 +#: project/templates/event/create.html:320 +msgid "Switch to organizer search" +msgstr "" + +#: project/templates/event/create.html:353 msgid "Switch to place search" msgstr "" -#: project/templates/event/create.html:284 -#: project/templates/event/update.html:144 +#: project/templates/event/create.html:364 +#: project/templates/event/update.html:167 msgid "Access" msgstr "" -#: project/templates/event/create.html:298 -#: project/templates/event/update.html:158 +#: project/templates/event/create.html:378 +#: project/templates/event/update.html:181 msgid "Target group" msgstr "" @@ -1784,7 +1794,7 @@ msgstr "" msgid "Event successfully deleted" msgstr "" -#: project/views/event.py:380 +#: project/views/event.py:384 msgid "Referenced event changed" msgstr "" diff --git a/project/views/event.py b/project/views/event.py index 1ce4b4d..1d0cd88 100644 --- a/project/views/event.py +++ b/project/views/event.py @@ -5,7 +5,6 @@ from flask import flash, jsonify, redirect, render_template, request, url_for from flask_babelex import gettext from flask_security import auth_required, current_user from sqlalchemy.exc import SQLAlchemyError -from sqlalchemy.sql import func from project import app, db from project.access import ( @@ -102,8 +101,7 @@ def event_create_for_admin_unit_id(id): form = CreateEventForm( admin_unit_id=admin_unit.id, category_ids=[upsert_event_category("Other").id] ) - prepare_event_form(form, admin_unit) - form.organizer_id.choices.insert(0, (0, "")) + prepare_event_form(form) # Vorlagen event_suggestion = None @@ -116,6 +114,7 @@ def event_create_for_admin_unit_id(id): event_template = Event.query.get_or_404(event_template_id) if not form.is_submitted(): form.process(obj=event_template) + prepare_organizer(form) prepare_event_place(form) if not event_template: @@ -189,7 +188,7 @@ def event_update(event_id): access_or_401(event.admin_unit, "event:update") form = UpdateEventForm(obj=event, start=event.start, end=event.end) - prepare_event_form(form, event.admin_unit) + prepare_event_form(form) if not form.is_submitted(): form.category_ids.data = [c.id for c in event.categories] @@ -278,15 +277,18 @@ def prepare_event_place(form): form.event_place_id.choices = [(place.id, get_place_str(place))] -def prepare_event_form(form, admin_unit): - form.organizer_id.choices = [ - (o.id, o.name) - for o in EventOrganizer.query.filter( - EventOrganizer.admin_unit_id == admin_unit.id - ).order_by(func.lower(EventOrganizer.name)) - ] +def prepare_organizer(form): + if form.organizer_id.data and form.organizer_id.data > 0: + organizer = EventOrganizer.query.get(form.organizer_id.data) + + if organizer: + form.organizer_id.choices = [(organizer.id, organizer.name)] + + +def prepare_event_form(form): form.category_ids.choices = get_event_category_choices() + prepare_organizer(form) prepare_event_place(form) if not form.start.data: @@ -332,6 +334,7 @@ def prepare_event_form_for_suggestion(form, event_suggestion): form.organizer_choice.data = 2 form.new_organizer.form.name.data = event_suggestion.organizer_text + prepare_organizer(form) prepare_event_place(form)