Skip to content

Commit

Permalink
feat: Adds device names for attendee check-in (#5284)
Browse files Browse the repository at this point in the history
  • Loading branch information
mooocer authored and dr0pdb committed Aug 6, 2018
1 parent 5df97ab commit fed2c00
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
51 changes: 50 additions & 1 deletion app/api/attendees.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ def before_post(self, args, kwargs, data):
"Ticket already sold out"
)

if 'device_name_checkin' in data and data['device_name_checkin'] is not None:
if 'is_checked_in' not in data or not data['is_checked_in']:
raise UnprocessableEntity(
{'pointer': '/data/attributes/device_name_checkin'},
"Attendee needs to be checked in first"
)
elif 'checkin_times' not in data or data['checkin_times'] is None:
raise UnprocessableEntity(
{'pointer': '/data/attributes/device_name_checkin'},
"Check in Times missing"
)
elif len(data['checkin_times'].split(",")) != len(data['device_name_checkin'].split(",")):
raise UnprocessableEntity(
{'pointer': '/data/attributes/device_name_checkin'},
"Check in Times missing for the corresponding device name"
)

if 'checkin_times' in data:
if 'device_name_checkin' not in data or data['device_name_checkin'] is None:
data['device_name_checkin'] = '-'

decorators = (jwt_required,)
methods = ['POST']
schema = AttendeeSchema
Expand Down Expand Up @@ -149,13 +170,41 @@ def before_update_object(self, obj, data, kwargs):
if not has_access('is_registrar', event_id=obj.event_id):
raise ForbiddenException({'source': 'User'}, 'You are not authorized to access this.')

if 'device_name_checkin' in data:
if 'checkin_times' not in data or data['checkin_times'] is None:
raise UnprocessableEntity(
{'pointer': '/data/attributes/device_name_checkin'},
"Check in Times missing"
)

if 'is_checked_in' in data and data['is_checked_in']:
if 'checkin_times' not in data:
if 'checkin_times' not in data or data['checkin_times'] is None:
raise UnprocessableEntity({'pointer': '/data/attributes/checkin_times'},
"Check in time missing while trying to check in attendee")
else:
if obj.checkin_times and data['checkin_times'] not in obj.checkin_times.split(","):
data['checkin_times'] = '{},{}'.format(obj.checkin_times, data['checkin_times'])
elif obj.checkin_times and data['checkin_times'] in obj.checkin_times.split(","):
raise UnprocessableEntity(
{'pointer': '/data/attributes/checkin_times'},
"Check in time already present"
)

if 'device_name_checkin' in data and data['device_name_checkin'] is not None:
if obj.device_name_checkin is not None:
data['device_name_checkin'] = '{},{}'.format(obj.device_name_checkin,
data['device_name_checkin'])

if len(data['checkin_times'].split(",")) != len(data['device_name_checkin'].split(",")):
raise UnprocessableEntity(
{'pointer': '/data/attributes/device_name_checkin'},
"Check in Time missing for the corresponding device name"
)
else:
if obj.device_name_checkin is not None:
data['device_name_checkin'] = '{},{}'.format(obj.device_name_checkin, '-')
else:
data['device_name_checkin'] = '-'

if 'is_checked_out' in data and data['is_checked_out']:
attendee = safe_query(db, TicketHolder, 'id', kwargs['id'], 'attendee_id')
Expand Down
1 change: 1 addition & 0 deletions app/api/schema/attendees.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Meta:

ticket_id = fields.Str(allow_none=True)
is_checked_in = fields.Boolean()
device_name_checkin = fields.Str(allow_none=True)
checkin_times = fields.Str(allow_none=True)
checkout_times = fields.Str(allow_none=True, dump_only=True)
attendee_notes = fields.Str(allow_none=True)
Expand Down
3 changes: 3 additions & 0 deletions app/models/ticket_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TicketHolder(SoftDeletionModel):
ticket = db.relationship('Ticket', backref='ticket_holders')
is_checked_in = db.Column(db.Boolean, default=False)
is_checked_out = db.Column(db.Boolean, default=False)
device_name_checkin = db.Column(db.String)
checkin_times = db.Column(db.String)
checkout_times = db.Column(db.String)
attendee_notes = db.Column(db.String)
Expand Down Expand Up @@ -77,6 +78,7 @@ def __init__(self,
checkin_times=None,
checkout_times=None,
is_checked_out=False,
device_name_checkin=None,
attendee_notes=None,
order_id=None,
pdf_url=None,
Expand Down Expand Up @@ -111,6 +113,7 @@ def __init__(self,
self.checkin_times = checkin_times
self.checkout_times = checkout_times
self.is_checked_out = is_checked_out
self.device_name_checkin = device_name_checkin
self.attendee_notes = attendee_notes
self.pdf_url = pdf_url
self.event_id = event_id
Expand Down
26 changes: 26 additions & 0 deletions migrations/versions/a0c63733e5d2_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""empty message
Revision ID: a0c63733e5d2
Revises: e4311ef3ddf5
Create Date: 2018-08-02 17:57:10.483859
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = 'a0c63733e5d2'
down_revision = 'e4311ef3ddf5'


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('ticket_holders', sa.Column('device_name_checkin', sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('ticket_holders', 'device_name_checkin')
# ### end Alembic commands ###

0 comments on commit fed2c00

Please sign in to comment.