From 087af7e742393d57f4fd1bdb460d78ecb17d6116 Mon Sep 17 00:00:00 2001 From: Vidya Ramakrishnan Date: Thu, 5 Oct 2023 17:11:00 +0530 Subject: [PATCH] Remove mandatory email requirement from new participant form --- funnel/forms/sync_ticket.py | 19 +++++----- funnel/models/sync_ticket.py | 2 +- migrations/versions/017c60414c03_.py | 57 ++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 migrations/versions/017c60414c03_.py diff --git a/funnel/forms/sync_ticket.py b/funnel/forms/sync_ticket.py index fae507f95..57b5f6f85 100644 --- a/funnel/forms/sync_ticket.py +++ b/funnel/forms/sync_ticket.py @@ -175,8 +175,8 @@ class TicketParticipantForm(forms.Form): ) email = forms.EmailField( __("Email"), - validators=[forms.validators.DataRequired(), forms.validators.ValidEmail()], - filters=[forms.filters.strip()], + validators=[forms.validators.Optional(), forms.validators.ValidEmail()], + filters=[forms.filters.none_if_empty()], ) phone = forms.StringField( __("Phone number"), @@ -219,13 +219,14 @@ def set_queries(self) -> None: def validate(self, *args, **kwargs) -> bool: """Validate form.""" result = super().validate(*args, **kwargs) - with db.session.no_autoflush: - accountemail = AccountEmail.get(email=self.email.data) - if accountemail is not None: - self.user = accountemail.account - else: - self.user = None - return result + if self.email is not None: + with db.session.no_autoflush: + accountemail = AccountEmail.get(email=self.email.data) + if accountemail is not None: + self.user = accountemail.account + else: + self.user = None + return result @TicketParticipant.forms('badge') diff --git a/funnel/models/sync_ticket.py b/funnel/models/sync_ticket.py index d51940425..ad3cf1f17 100644 --- a/funnel/models/sync_ticket.py +++ b/funnel/models/sync_ticket.py @@ -207,7 +207,7 @@ class TicketParticipant(EmailAddressMixin, UuidMixin, BaseMixin, Model): """A participant in one or more events, synced from an external ticket source.""" __tablename__ = 'ticket_participant' - __email_optional__ = False + __email_optional__ = True __email_for__ = 'participant' fullname = with_roles( diff --git a/migrations/versions/017c60414c03_.py b/migrations/versions/017c60414c03_.py new file mode 100644 index 000000000..d61b7bb30 --- /dev/null +++ b/migrations/versions/017c60414c03_.py @@ -0,0 +1,57 @@ +"""empty message + +Revision ID: 017c60414c03 +Revises: 4f9ca10b7b9d +Create Date: 2023-10-05 15:08:34.540672 + +""" + +from typing import Optional, Tuple, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = '017c60414c03' +down_revision: str = '4f9ca10b7b9d' +branch_labels: Optional[Union[str, Tuple[str, ...]]] = None +depends_on: Optional[Union[str, Tuple[str, ...]]] = None + + +def upgrade(engine_name: str = '') -> None: + """Upgrade all databases.""" + # Do not modify. Edit `upgrade_` instead + globals().get(f'upgrade_{engine_name}', lambda: None)() + + +def downgrade(engine_name: str = '') -> None: + """Downgrade all databases.""" + # Do not modify. Edit `downgrade_` instead + globals().get(f'downgrade_{engine_name}', lambda: None)() + + + + + +def upgrade_() -> None: + """Upgrade default database.""" + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('ticket_participant', schema=None) as batch_op: + batch_op.alter_column('email_address_id', + existing_type=sa.INTEGER(), + nullable=True) + + # ### end Alembic commands ### + + +def downgrade_() -> None: + """Downgrade default database.""" + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('ticket_participant', schema=None) as batch_op: + batch_op.alter_column('email_address_id', + existing_type=sa.INTEGER(), + nullable=False) + + # ### end Alembic commands ### +