-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporates attendee_tournaments data model into uber plugin for bac…
…kwards compatibility with legacy servers
- Loading branch information
Showing
6 changed files
with
191 additions
and
9 deletions.
There are no files selected for viewing
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,53 @@ | ||
"""Initial migration | ||
Revision ID: 73b22ccbe472 | ||
Revises: 1ed43776064f | ||
Create Date: 2017-04-24 09:08:30.923731 | ||
""" | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '73b22ccbe472' | ||
down_revision = '1ed43776064f' | ||
branch_labels = ('attendee_tournaments',) | ||
depends_on = None | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import sideboard.lib.sa | ||
|
||
|
||
try: | ||
is_sqlite = op.get_context().dialect.name == 'sqlite' | ||
except: | ||
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 upgrade(): | ||
op.create_table('attendee_tournament', | ||
sa.Column('id', sideboard.lib.sa.UUID(), nullable=False), | ||
sa.Column('first_name', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('last_name', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('email', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('cellphone', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('game', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('availability', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('format', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('experience', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('needs', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('why', sa.Unicode(), server_default='', nullable=False), | ||
sa.Column('volunteering', sa.Boolean(), server_default='False', nullable=False), | ||
sa.Column('status', sa.Integer(), server_default='239694250', nullable=False), | ||
sa.PrimaryKeyConstraint('id', name=op.f('pk_attendee_tournament')) | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table('attendee_tournament') |
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,77 @@ | ||
""" | ||
NO LONGER USED. | ||
The attendee_tournaments module is no longer used, but has been | ||
included for backward compatibility with legacy servers. | ||
""" | ||
|
||
import re | ||
|
||
from sideboard.lib.sa import CoerceUTF8 as UnicodeText | ||
from sqlalchemy import func | ||
from sqlalchemy.types import Boolean | ||
|
||
from uber.config import c | ||
from uber.decorators import validation | ||
from uber.models import MagModel, Attendee | ||
from uber.models.types import Choice, DefaultColumn as Column, MultiChoice | ||
|
||
|
||
__all__ = ['AttendeeTournament'] | ||
|
||
|
||
class AttendeeTournament(MagModel): | ||
first_name = Column(UnicodeText) | ||
last_name = Column(UnicodeText) | ||
email = Column(UnicodeText) | ||
cellphone = Column(UnicodeText) | ||
game = Column(UnicodeText) | ||
availability = Column(MultiChoice(c.TOURNAMENT_AVAILABILITY_OPTS)) | ||
format = Column(UnicodeText) | ||
experience = Column(UnicodeText) | ||
needs = Column(UnicodeText) | ||
why = Column(UnicodeText) | ||
volunteering = Column(Boolean, default=False) | ||
|
||
status = Column( | ||
Choice(c.TOURNAMENT_STATUS_OPTS), default=c.NEW, admin_only=True) | ||
|
||
email_model_name = 'app' | ||
|
||
@property | ||
def full_name(self): | ||
return self.first_name + ' ' + self.last_name | ||
|
||
@property | ||
def matching_attendee(self): | ||
return self.session.query(Attendee).filter( | ||
Attendee.first_name == self.first_name.title(), | ||
Attendee.last_name == self.last_name.title(), | ||
func.lower(Attendee.email) == self.email.lower() | ||
).first() | ||
|
||
|
||
AttendeeTournament.required = [ | ||
('first_name', 'First Name'), | ||
('last_name', 'Last Name'), | ||
('email', 'Email Address'), | ||
('game', 'Game Title'), | ||
('availability', 'Your Availability'), | ||
('format', 'Tournament Format'), | ||
('experience', 'Past Experience'), | ||
('needs', 'Your Needs'), | ||
('why', '"Why?"'), | ||
] | ||
|
||
|
||
@validation.AttendeeTournament | ||
def email(app): | ||
if not re.match(c.EMAIL_RE, app.email): | ||
return 'You did not enter a valid email address' | ||
|
||
|
||
@validation.AttendeeTournament | ||
def cellphone(app): | ||
from uber.model_checks import _invalid_phone_number | ||
if app.cellphone and _invalid_phone_number(app.cellphone): | ||
return 'You did not enter a valid cellphone number' |