Place and Organizer required in Event.create #93

This commit is contained in:
Daniel Grams 2021-01-25 14:51:55 +01:00
parent 1abd24762f
commit 8bcfe5def6
4 changed files with 23 additions and 11 deletions

View File

@ -35,7 +35,10 @@ class EventPlaceLocationForm(FlaskForm):
class EventPlaceForm(FlaskForm):
name = StringField(lazy_gettext("Name"), validators=[Optional()])
name = StringField(
lazy_gettext("Name"),
validators=[Optional()],
)
location = FormField(EventPlaceLocationForm, default=lambda: Location())
def populate_obj(self, obj):
@ -50,7 +53,10 @@ class OrganizerForm(EventPlaceForm):
class EventOrganizerForm(FlaskForm):
name = StringField(lazy_gettext("Organizator"), validators=[Optional()])
name = StringField(
lazy_gettext("Organizator"),
validators=[Optional()],
)
url = URLField(lazy_gettext("Link URL"), validators=[Optional()])
email = EmailField(lazy_gettext("Email"), validators=[Optional()])
phone = StringField(lazy_gettext("Phone"), validators=[Optional()])
@ -249,7 +255,9 @@ class CreateEventForm(BaseEventForm):
coerce=int,
)
event_place_id = SelectField(
lazy_gettext("Place"), validators=[Optional()], coerce=int
lazy_gettext("Place"),
validators=[Optional()],
coerce=int,
)
new_event_place = FormField(EventPlaceForm, default=lambda: EventPlace())
@ -263,7 +271,9 @@ class CreateEventForm(BaseEventForm):
coerce=int,
)
organizer_id = SelectField(
lazy_gettext("Organizer"), validators=[Optional()], coerce=int
lazy_gettext("Organizer"),
validators=[Optional()],
coerce=int,
)
new_organizer = FormField(OrganizerForm, default=lambda: EventOrganizer())

View File

@ -1,5 +1,6 @@
{% macro render_field_with_errors(field) %}
{% set label_text = field.label.text + ' *' if field.flags.required else field.label.text %}
{% 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 %}
<div class="form-group row {% if field.errors %} has-error{% endif -%}">
{% if 'ri' in kwargs and kwargs['ri'] == 'checkbox' %}
{% else %}
@ -52,8 +53,9 @@
{% endif %}
{% endif %}
<small class="form-text text-muted w-100">
{{ field.description }} {% if field.flags.required %}{{ _('This field is required.') }}{% else %}{{ _('This field is optional.') }}{% endif %}
{{ field.description }} {% if is_required %}{{ _('This field is required.') }}{% else %}{{ _('This field is optional.') }}{% endif %}
</small>
{% if field.errors %}

View File

@ -89,12 +89,12 @@ $( function() {
</div>
<div class="my-4" id="existing_organizer_container">
{{ render_field_with_errors(form.organizer_id, class="autocomplete w-100") }}
{{ render_field_with_errors(form.organizer_id, class="autocomplete w-100", is_required=True) }}
</div>
<div class="my-4" id="new_organizer_container">
{{ form.new_organizer.hidden_tag() }}
{{ render_field_with_errors(form.new_organizer.form.name) }}
{{ render_field_with_errors(form.new_organizer.form.name, is_required=True) }}
{{ form.new_organizer.form.location.hidden_tag() }}
{{ render_field_with_errors(form.new_organizer.form.location.street) }}
{{ render_field_with_errors(form.new_organizer.form.location.postalCode) }}
@ -115,12 +115,12 @@ $( function() {
</div>
<div class="my-4" id="existing_place_container">
{{ render_field_with_errors(form.event_place_id, class="autocomplete w-100") }}
{{ render_field_with_errors(form.event_place_id, class="autocomplete w-100", is_required=True) }}
</div>
<div class="my-4" id="new_place_container">
{{ form.new_event_place.hidden_tag() }}
{{ render_field_with_errors(form.new_event_place.form.name) }}
{{ render_field_with_errors(form.new_event_place.form.name, is_required=True) }}
{{ form.new_event_place.form.location.hidden_tag() }}
{{ render_field_with_errors(form.new_event_place.form.location.street) }}
{{ render_field_with_errors(form.new_event_place.form.location.postalCode) }}

View File

@ -663,7 +663,7 @@ msgstr "Veranstalter"
#: project/forms/event.py:259
msgid "Select existing organizer"
msgstr "Vorhandenen Veranstalter auswählem"
msgstr "Vorhandenen Veranstalter auswählen"
#: project/forms/event.py:260
msgid "Enter new organizer"