from uber.common import *

attendee_fields = [
    'full_name', 'first_name', 'last_name', 'email', 'zip_code', 'cellphone', 'ec_phone', 'badge_status_label', 'checked_in',
    'badge_type_label', 'ribbon_label', 'staffing', 'is_dept_head', 'assigned_depts_labels', 'weighted_hours', 'worked_hours',
    'badge_num'
]
fields = dict({
    'food_restrictions': {
        'sandwich_pref_labels': True,
        'standard_labels': True,
        'freeform': True
    },
    'shifts': {
        'worked_label': True,
        'job': ['type_label', 'location_label', 'name', 'description', 'start_time', 'end_time', 'extra15']
    }
}, **{field: True for field in attendee_fields})


class AttendeeLookup:
    def lookup(self, badge_num):
        with Session() as session:
            attendee = session.query(Attendee).filter_by(badge_num=badge_num).first()
            return attendee.to_dict(fields) if attendee else {'error': 'No attendee found with Badge #{}'.format(badge_num)}

    def search(self, query):
        with Session() as session:
            return [a.to_dict(fields) for a in session.search(query).all()]

services.register(AttendeeLookup(), 'attendee')

from uber.common import *

attendee_fields = [
    'full_name', 'first_name', 'last_name', 'email', 'zip_code', 'cellphone', 'ec_phone', 'badge_status_label', 'checked_in',
    'badge_type_label', 'ribbon_label', 'staffing', 'is_dept_head', 'assigned_depts_labels', 'weighted_hours', 'worked_hours',
    'badge_num'
]
fields = dict({
    'food_restrictions': {
        'sandwich_pref_labels': True,
        'standard_labels': True,
        'freeform': True
    },
    'shifts': {
        'worked_label': True,
        'job': ['type_label', 'location_label', 'name', 'description', 'start_time', 'end_time', 'extra15']
    }
}, **{field: True for field in attendee_fields})


class AttendeeLookup:
    def lookup(self, badge_num):
        with Session() as session:
            attendee = session.query(Attendee).filter_by(badge_num=badge_num).first()
            return attendee.to_dict(fields) if attendee else {'error': 'No attendee found with Badge #{}'.format(badge_num)}

    def search(self, query):
        with Session() as session:
            return [a.to_dict(fields) for a in session.search(query).all()]

services.register(AttendeeLookup(), 'attendee')

job_fields = dict({
    'name': True,
    'description': True,
    'location': True,
    'start_time': True,
    'end_time': True,
    'duration': True,
    'shifts': {
        'attendee': {
            'badge_num': True,
            'full_name': True,
            'first_name': True,
            'last_name': True,
            'email': True,
            'cellphone': True,
            'badge_printed_name': True
        }
    }

})

class JobLookup:
    def lookup(self, location):
        with Session() as session:
            columns = Job.__table__.columns
            location_column = columns['location']
            label_lookup = {val: key for key, val in location_column.type.choices.items()}
            return [job.to_dict(job_fields) for job in session.query(Job).filter_by(location=label_lookup[location]).all()]

services.register(JobLookup(), 'shifts')

Add Job/shift lookup to API