def bidder_signup(self, session, message='', page=1, search_text='', order=''): filters = [] search_text = search_text.strip() if search_text: order = order or 'badge_printed_name' if re.match('\w-[0-9]{4}', search_text): attendees = session.query(Attendee).join( Attendee.art_show_bidder).filter( ArtShowBidder.bidder_num.ilike('%{}%'.format( search_text[2:]))) else: # Sorting by bidder number requires a join, which would filter out anyone without a bidder number order = 'badge_printed_name' if order == 'bidder_num' else order try: badge_num = int(search_text) except: filters.append( Attendee.badge_printed_name.ilike( '%{}%'.format(search_text))) else: filters.append( or_( Attendee.badge_num == badge_num, Attendee.badge_printed_name.ilike( '%{}%'.format(search_text)))) attendees = session.query(Attendee).filter(*filters) else: attendees = session.query(Attendee).join(Attendee.art_show_bidder) if 'bidder_num' in str(order) or not order: attendees = attendees.join(Attendee.art_show_bidder).order_by( ArtShowBidder.bidder_num.desc() if '-' in str(order) else ArtShowBidder.bidder_num) else: attendees = attendees.order(order) count = attendees.count() page = int(page) or 1 if not count and search_text: message = 'No matches found' pages = range(1, int(math.ceil(count / 100)) + 1) attendees = attendees[-100 + 100 * page:100 * page] return { 'message': message, 'page': page, 'pages': pages, 'search_text': search_text, 'search_results': bool(search_text), 'attendees': attendees, 'order': Order(order), }
def comments(self, session, order='last_name'): return { 'order': Order(order), 'attendees': session.query(Attendee).filter( Attendee.comments != '').order_by(order).all() }
def staffers(self, session, message='', order='first_name'): staffers = session.staffers().all() return { 'order': Order(order), 'message': message, 'taken_hours': sum([s.weighted_hours - s.nonshift_hours for s in staffers], 0.0), 'total_hours': sum([j.weighted_hours * j.slots for j in session.query(Job).all()], 0.0), 'staffers': sorted(staffers, reverse=order.startswith('-'), key=lambda s: getattr(s, order.lstrip('-'))) }
def artist_check_in_out(self, session, checkout=False, message='', page=1, search_text='', order='first_name'): filters = [ArtShowApplication.status != c.DECLINED] if checkout: filters.append(ArtShowApplication.checked_in != None) else: filters.append(ArtShowApplication.checked_out == None) search_text = search_text.strip() search_filters = [] if search_text: for attr in [ 'first_name', 'last_name', 'legal_name', 'full_name', 'last_first', 'badge_printed_name' ]: search_filters.append( getattr(Attendee, attr).ilike('%' + search_text + '%')) for attr in ['artist_name', 'banner_name']: search_filters.append( getattr(ArtShowApplication, attr).ilike('%' + search_text + '%')) applications = session.query(ArtShowApplication).join(ArtShowApplication.attendee)\ .filter(*filters).filter(or_(*search_filters))\ .order_by(Attendee.first_name.desc() if '-' in str(order) else Attendee.first_name) count = applications.count() page = int(page) or 1 if not count and search_text: message = 'No matches found' pages = range(1, int(math.ceil(count / 100)) + 1) applications = applications[-100 + 100 * page:100 * page] return { 'message': message, 'page': page, 'pages': pages, 'search_text': search_text, 'search_results': bool(search_text), 'applications': applications, 'order': Order(order), 'checkout': checkout, }
def index(self, session, message='', page='0', search_text='', uploaded_id='', order='last_first', invalid=''): # DEVELOPMENT ONLY: it's an extremely convenient shortcut to show the first page # of search results when doing testing. it's too slow in production to do this by # default due to the possibility of large amounts of reg stations accessing this # page at once. viewing the first page is also rarely useful in production when # there are thousands of attendees. if c.DEV_BOX and not int(page): page = 1 filter = Attendee.badge_status.in_([c.NEW_STATUS, c.COMPLETED_STATUS]) if not invalid else None attendees = session.query(Attendee) if invalid else session.query(Attendee).filter(filter) total_count = attendees.count() count = 0 search_text = search_text.strip() if search_text: attendees = session.search(search_text) if invalid else session.search(search_text, filter) count = attendees.count() if not count: attendees = attendees.options(joinedload(Attendee.group)) count = total_count attendees = attendees.order(order) page = int(page) if search_text: page = page or 1 if search_text and count == total_count: message = 'No matches found' elif search_text and count == 1 and (not c.AT_THE_CON or search_text.isdigit()): raise HTTPRedirect( 'form?id={}&message={}', attendees.one().id, 'This attendee was the only search result') pages = range(1, int(math.ceil(count / 100)) + 1) attendees = attendees[-100 + 100*page: 100*page] if page else [] return { 'message': message if isinstance(message, str) else message[-1], 'page': page, 'pages': pages, 'invalid': invalid, 'search_text': search_text, 'search_results': bool(search_text), 'attendees': attendees, 'order': Order(order), 'attendee_count': total_count, 'checkin_count': session.query(Attendee).filter(Attendee.checked_in != None).count(), 'attendee': session.attendee(uploaded_id, allow_invalid=True) if uploaded_id else None } # noqa: E711
def index(self, session, message='', order='name', show='all'): which = { 'all': [], 'tables': [Group.tables > 0, Group.status != c.DECLINED], 'groups': [Group.tables == 0] }[show] # TODO: think about using a SQLAlchemy column property for .badges and then just use .order() groups = sorted( session.query(Group).filter(*which).options( joinedload('attendees')).all(), reverse=order.startswith('-'), key=lambda g: [getattr(g, order.lstrip('-')).lower(), g.tables]) return { 'show': show, 'groups': groups, 'message': message, 'order': Order(order), 'total_groups': len(groups), 'total_badges': sum(g.badges for g in groups), 'tabled_badges': sum(g.badges for g in groups if g.tables and g.status != c.DECLINED), 'untabled_badges': sum(g.badges for g in groups if not g.tables), 'tabled_groups': len([g for g in groups if g.tables and g.status != c.DECLINED]), 'untabled_groups': len([g for g in groups if not g.tables]), 'tables': sum(g.tables for g in groups), 'unapproved_tables': sum(g.tables for g in groups if g.status == c.UNAPPROVED), 'waitlisted_tables': sum(g.tables for g in groups if g.status == c.WAITLISTED), 'approved_tables': sum(g.tables for g in groups if g.status == c.APPROVED) }
def sales_search(self, session, message='', page=1, search_text='', order=''): filters = [] search_text = search_text.strip() if search_text: order = order or 'badge_num' if re.match('\w-[0-9]{4}', search_text): attendees = session.query(Attendee).join( Attendee.art_show_bidder).filter( ArtShowBidder.bidder_num.ilike('%{}%'.format( search_text[2:]))) else: # Sorting by bidder number requires a join, which would filter out anyone without a bidder number order = 'badge_num' if order == 'bidder_num' else order try: badge_num = int(search_text) except: raise HTTPRedirect( 'sales_search?message={}', 'Please search by bidder number or badge number.') else: filters.append(or_(Attendee.badge_num == badge_num)) attendees = session.query(Attendee).filter(*filters) else: attendees = session.query(Attendee).join( Attendee.art_show_receipts) if 'bidder_num' in str(order): attendees = attendees.join(Attendee.art_show_bidder).order_by( ArtShowBidder.bidder_num.desc() if '-' in str(order) else ArtShowBidder.bidder_num) else: attendees = attendees.order(order or 'badge_num') count = attendees.count() page = int(page) or 1 if not count and search_text: message = 'No matches found' if not search_text: attendees = [ a for a in attendees if a.art_show_receipt and a.art_show_receipt.pieces ] pages = range(1, int(math.ceil(count / 100)) + 1) attendees = attendees[-100 + 100 * page:100 * page] return { 'message': message, 'page': page, 'pages': pages, 'search_text': search_text, 'search_results': bool(search_text), 'attendees': attendees, 'order': Order(order), }