-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4354 from magfest/fix-magdev1210
Add expiration date for watchlist entries
- Loading branch information
Showing
13 changed files
with
298 additions
and
74 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
alembic/versions/7c43e4352bb0_add_expiration_date_to_watchlist_entries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Add expiration date to WatchList entries | ||
Revision ID: 7c43e4352bb0 | ||
Revises: 2288360ee15d | ||
Create Date: 2024-05-03 19:56:25.359068 | ||
""" | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '7c43e4352bb0' | ||
down_revision = '2288360ee15d' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
|
||
try: | ||
is_sqlite = op.get_context().dialect.name == 'sqlite' | ||
except Exception: | ||
is_sqlite = False | ||
|
||
if is_sqlite: | ||
op.get_context().connection.execute('PRAGMA foreign_keys=ON;') | ||
utcnow_server_default = "(datetime('now', 'utc'))" | ||
else: | ||
utcnow_server_default = "timezone('utc', current_timestamp)" | ||
|
||
def sqlite_column_reflect_listener(inspector, table, column_info): | ||
"""Adds parenthesis around SQLite datetime defaults for utcnow.""" | ||
if column_info['default'] == "datetime('now', 'utc')": | ||
column_info['default'] = utcnow_server_default | ||
|
||
sqlite_reflect_kwargs = { | ||
'listeners': [('column_reflect', sqlite_column_reflect_listener)] | ||
} | ||
|
||
# =========================================================================== | ||
# HOWTO: Handle alter statements in SQLite | ||
# | ||
# def upgrade(): | ||
# if is_sqlite: | ||
# with op.batch_alter_table('table_name', reflect_kwargs=sqlite_reflect_kwargs) as batch_op: | ||
# batch_op.alter_column('column_name', type_=sa.Unicode(), server_default='', nullable=False) | ||
# else: | ||
# op.alter_column('table_name', 'column_name', type_=sa.Unicode(), server_default='', nullable=False) | ||
# | ||
# =========================================================================== | ||
|
||
|
||
def upgrade(): | ||
op.add_column('watch_list', sa.Column('expiration', sa.Date(), nullable=True)) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('watch_list', 'expiration') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import cherrypy | ||
from datetime import date | ||
|
||
from markupsafe import Markup | ||
from wtforms import (BooleanField, DateField, DateTimeField, EmailField, | ||
HiddenField, SelectField, SelectMultipleField, IntegerField, | ||
StringField, TelField, validators, TextAreaField) | ||
from wtforms.validators import ValidationError, StopValidation | ||
|
||
from uber.config import c | ||
from uber.forms import (AddressForm, MultiCheckbox, MagForm, SelectAvailableField, SwitchInput, NumberInputGroup, | ||
HiddenBoolField, HiddenIntField, CustomValidation) | ||
from uber.custom_tags import popup_link | ||
from uber.badge_funcs import get_real_badge_type | ||
from uber.models import Attendee, Session, PromoCodeGroup | ||
from uber.model_checks import invalid_phone_number | ||
from uber.utils import get_age_conf_from_birthday | ||
|
||
|
||
__all__ = ['WatchListEntry'] | ||
|
||
|
||
class WatchListEntry(MagForm): | ||
field_validation, new_or_changed_validation = CustomValidation(), CustomValidation() | ||
|
||
first_names = StringField('First Names', render_kw={'placeholder': 'Use commas to separate possible first names.'}) | ||
last_name = StringField('Last Name') | ||
email = EmailField('Email Address', validators=[ | ||
validators.Optional(), | ||
validators.Length(max=255, message="Email addresses cannot be longer than 255 characters."), | ||
validators.Email(granular_message=True), | ||
], | ||
render_kw={'placeholder': '[email protected]'}) | ||
birthdate = DateField('Date of Birth', validators=[validators.Optional()]) | ||
reason = TextAreaField('Reason', validators=[ | ||
validators.DataRequired("Please enter the reason this attendee is on the watchlist."), | ||
]) | ||
action = TextAreaField('Action', validators=[ | ||
validators.DataRequired("Please describe what, if anything, an attendee should do before " | ||
"they can check in."), | ||
]) | ||
expiration = DateField('Expiration Date', validators=[validators.Optional()]) | ||
active = BooleanField('Automatically place matching attendees in the On Hold status.') | ||
|
||
@field_validation.birthdate | ||
def birthdate_format(form, field): | ||
# TODO: Make WTForms use this message instead of the generic DateField invalid value message | ||
if field.data and not isinstance(field.data, date): | ||
raise StopValidation('Please use the format YYYY-MM-DD for the date of birth.') | ||
elif field.data and field.data > date.today(): | ||
raise ValidationError('Attendees cannot be born in the future.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from datetime import date, timedelta | ||
|
||
from uber.models import WatchList, Session | ||
from uber.tasks import celery | ||
|
||
|
||
__all__ = ['deactivate_expired_watchlist_entries'] | ||
|
||
|
||
@celery.schedule(timedelta(hour=12)) | ||
def deactivate_expired_watchlist_entries(): | ||
with Session() as session: | ||
expired_entries = session.query(WatchList).filter(WatchList.active == True, # noqa: E712 | ||
WatchList.expiration <= date.today()) | ||
|
||
expired_count = expired_entries.count() | ||
|
||
for entry in expired_entries: | ||
entry.active = False | ||
session.add(entry) | ||
|
||
return f"Deactivated {expired_count} expired watchlist entries." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ | |
}, | ||
callback: function (result) { | ||
if (result) { | ||
updateWatchlist(); | ||
formToSubmit.submit(); | ||
} | ||
} | ||
}); | ||
|
Oops, something went wrong.