def show_info(self, session, id, message='', promo_image=None, **params): game = session.indie_game(id=id) if cherrypy.request.method == 'POST': game.apply( params, bools=[ 'tournament_at_event', 'has_multiplayer', 'leaderboard_challenge' ], restricted=False ) # Setting restricted to false lets us define custom bools and checkgroups game.studio.name = params.get('studio_name', '') if promo_image: image = session.indie_game_image(params) image.game = game image.content_type = promo_image.content_type.value image.extension = promo_image.filename.split('.')[-1].lower() image.is_screenshot = False message = check(image) if not message: with open(image.filepath, 'wb') as f: shutil.copyfileobj(promo_image.file, f) message = check(game) or check(game.studio) if not message: if game.tournament_at_event and not game.promo_image and not promo_image: message = 'Please upload a high resolution image of cover art or the game logo.' else: session.add(game) raise HTTPRedirect('index?message={}', 'Game information uploaded') return {'message': message, 'game': game}
def show_info(self, session, id, message='', promo_image=None, **params): game = session.indie_game(id=id) cherrypy.session['studio_id'] = game.studio.id if cherrypy.request.method == 'POST': game.apply(params, bools=['tournament_at_event', 'has_multiplayer', 'leaderboard_challenge'], restricted=False) # Setting restricted to false lets us define custom bools and checkgroups game.studio.name = params.get('studio_name', '') if not params.get('contact_phone', ''): message = "Please enter a phone number for MIVS staff to contact your studio." else: game.studio.contact_phone = params.get('contact_phone', '') if promo_image: image = session.indie_game_image(params) image.game = game image.content_type = promo_image.content_type.value image.extension = promo_image.filename.split('.')[-1].lower() image.is_screenshot = False message = check(image) if not message: with open(image.filepath, 'wb') as f: shutil.copyfileobj(promo_image.file, f) message = check(game) or check(game.studio) if not message: session.add(game) if game.studio.group.guest: raise HTTPRedirect('../guests/mivs_show_info?guest_id={}&message={}', game.studio.group.guest.id, 'Game information uploaded') raise HTTPRedirect('index?message={}', 'Game information uploaded') return { 'message': message, 'game': game, }
def show_info(self, session, id, message='', promo_image=None, **params): game = session.indie_game(id=id) if cherrypy.request.method == 'POST': game.apply(params, bools=['tournament_at_event', 'has_multiplayer', 'leaderboard_challenge'], restricted=False) # Setting restricted to false lets us define custom bools and checkgroups game.studio.name = params.get('studio_name', '') if promo_image: image = session.indie_game_image(params) image.game = game image.content_type = promo_image.content_type.value image.extension = promo_image.filename.split('.')[-1].lower() image.is_screenshot = False message = check(image) if not message: with open(image.filepath, 'wb') as f: shutil.copyfileobj(promo_image.file, f) message = check(game) or check(game.studio) if not message: if game.tournament_at_event and not game.promo_image and not promo_image: message = 'Please upload a high resolution image of cover art or the game logo.' else: session.add(game) raise HTTPRedirect('index?message={}', 'Game information uploaded') return { 'message': message, 'game': game }
def team(self, session, message='', **params): params.pop('id', None) team = session.mits_team(dict(params, id=cherrypy.session.get('mits_team_id', 'None')), restricted=True) applicant = session.mits_applicant(params, restricted=True) if cherrypy.request.method == 'POST': if 'no_showcase' in params: team.showcase_interest = False if 'no_panel' in params: team.panel_interest = False if 'no_hotel_space' in params: for applicant in team.applicants: applicant.declined_hotel_space = True message = check(team) if not message and team.is_new: applicant.team = team message = check(applicant) if not message: session.add(team) if team.is_new: applicant.primary_contact = True session.add(applicant) raise HTTPRedirect('continue_app?id={}', team.id) return { 'message': message, 'team': team, 'applicant': applicant }
def team(self, session, message='', **params): params.pop('id', None) team = session.mits_team(dict(params, id=cherrypy.session.get( 'mits_team_id', 'None')), restricted=True) applicant = session.mits_applicant(params, restricted=True) if cherrypy.request.method == 'POST': if 'no_showcase' in params: team.showcase_interest = False if 'no_panel' in params: team.panel_interest = False if 'no_hotel_space' in params: for applicant in team.applicants: applicant.declined_hotel_space = True message = check(team) if not message and team.is_new: applicant.team = team message = check(applicant) if not message: session.add(team) if team.is_new: applicant.primary_contact = True session.add(applicant) raise HTTPRedirect('continue_app?id={}', team.id) return {'message': message, 'team': team, 'applicant': applicant}
def transfer_badge(self, session, message='', **params): old = session.attendee(params['id']) assert old.is_transferable, 'This badge is not transferrable.' session.expunge(old) attendee = session.attendee(params, restricted=True) if 'first_name' in params: message = check(attendee, prereg=True) if (old.first_name == attendee.first_name and old.last_name == attendee.last_name) \ or (old.legal_name and old.legal_name == attendee.legal_name): message = 'You cannot transfer your badge to yourself.' elif not message and (not params['first_name'] and not params['last_name']): message = check(attendee, prereg=True) if not message and (not params['first_name'] and not params['last_name']): message = 'First and Last names are required.' if not message: subject = c.EVENT_NAME + ' Registration Transferred' body = render('emails/reg_workflow/badge_transfer.txt', { 'new': attendee, 'old': old }, encoding=None) try: send_email.delay( c.REGDESK_EMAIL, [old.email, attendee.email, c.REGDESK_EMAIL], subject, body, model=attendee.to_dict('id')) except Exception: log.error('unable to send badge change email', exc_info=True) if attendee.amount_unpaid: raise HTTPRedirect('attendee_donation_form?id={}', attendee.id) else: raise HTTPRedirect( 'badge_updated?id={}&message={}', attendee.id, 'Your registration has been transferred') else: for attr in c.UNTRANSFERABLE_ATTRS: setattr(attendee, attr, getattr(Attendee(), attr)) return { 'old': old, 'attendee': attendee, 'message': message, 'affiliates': session.affiliates() }
def index(self, session, message='', **params): attendee = None if cherrypy.request.method == 'GET' and params.get('attendee_id', ''): try: attendee = session.attendee(id=params['attendee_id']) except Exception: message = \ 'We could not find you by your confirmation number. ' \ 'Is the URL correct?' if attendee and attendee.group: for field in MarketplaceApplication.MATCHING_DEALER_FIELDS: params[field] = params[field] if field in params else getattr( attendee.group, field, None) app = session.marketplace_application(params, restricted=True, ignore_csrf=True) if not (c.AFTER_MARKETPLACE_REG_START and c.BEFORE_MARKETPLACE_DEADLINE): return render('static_views/marketplace_closed.html') if c.AFTER_MARKETPLACE_DEADLINE \ else render('static_views/marketplace_not_open.html') if cherrypy.request.method == 'POST': attendee, message = session.attendee_from_marketplace_app(**params) message = message or check(attendee) or check(app, prereg=True) if not message: if c.AFTER_MARKETPLACE_WAITLIST: app.status = c.WAITLISTED session.add(attendee) app.attendee = attendee session.add(app) send_email(c.MARKETPLACE_APP_EMAIL, c.MARKETPLACE_APP_EMAIL, 'Marketplace Application Received', render('emails/marketplace/reg_notification.txt', {'app': app}), model=app) session.commit() raise HTTPRedirect('confirmation?id={}', app.id) return { 'message': message, 'app': app, 'attendee': attendee, 'attendee_id': app.attendee_id or params.get('attendee_id', ''), 'logged_in_account': session.current_attendee_account(), 'new_badge': params.get('new_badge', '') }
def index(self, session, message='', **params): app = session.art_show_application(params, restricted=True, ignore_csrf=True) attendee = None if not c.ART_SHOW_OPEN: return render('static_views/art_show_closed.html') if c.AFTER_ART_SHOW_DEADLINE \ else render('static_views/art_show_not_open.html') if cherrypy.request.method == 'GET' and params.get('attendee_id', ''): try: attendee = session.attendee(id=params['attendee_id']) except Exception: message = \ 'We could not find you by your confirmation number. ' \ 'Is the URL correct?' if cherrypy.request.method == 'POST': attendee, message = session.attendee_from_art_show_app(**params) if attendee and attendee.badge_status == c.NOT_ATTENDING \ and app.delivery_method == c.BRINGING_IN: message = 'You cannot bring your own art ' \ 'if you are not attending.' message = message or check(attendee) or check(app, prereg=True) if not message: if c.AFTER_ART_SHOW_WAITLIST: app.status = c.WAITLISTED session.add(attendee) app.attendee = attendee session.add(app) send_email(c.ART_SHOW_EMAIL, c.ART_SHOW_EMAIL, 'Art Show Application Received', render('emails/art_show/reg_notification.txt', {'app': app}), model=app) session.commit() raise HTTPRedirect('confirmation?id={}', app.id) return { 'message': message, 'app': app, 'attendee': attendee, 'attendee_id': app.attendee_id or params.get('attendee_id', ''), 'logged_in_account': session.current_attendee_account(), 'not_attending': params.get('not_attending', ''), 'new_badge': params.get('new_badge', '') }
def screenshot(self, session, game_id, message='', use_in_promo='', image=None, **params): screenshot = session.indie_game_image(params, applicant=True) screenshot.game = session.indie_game(game_id, applicant=True) if cherrypy.request.method == 'POST': screenshot.filename = image.filename screenshot.content_type = image.content_type.value screenshot.extension = image.filename.split('.')[-1].lower() if use_in_promo: screenshot.use_in_promo = True message = check(screenshot) if not message: with open(screenshot.filepath, 'wb') as f: shutil.copyfileobj(image.file, f) if use_in_promo: raise HTTPRedirect('show_info?id={}&message={}', screenshot.game.id, 'Screenshot Uploaded') else: raise HTTPRedirect('index?message={}', 'Screenshot Uploaded') return { 'message': message, 'use_in_promo': use_in_promo, 'screenshot': screenshot }
def form(self, session, message='', return_to='', omit_badge='', check_in='', **params): attendee = session.attendee( params, checkgroups=Attendee.all_checkgroups, bools=Attendee.all_bools, allow_invalid=True) if 'first_name' in params: attendee.group_id = params['group_opt'] or None if (c.AT_THE_CON and omit_badge) or not attendee.badge_num: attendee.badge_num = None if 'no_override' in params: attendee.overridden_price = None message = '' if c.BADGE_PROMO_CODES_ENABLED and 'promo_code' in params: message = session.add_promo_code_to_attendee( attendee, params.get('promo_code')) if not message: message = check(attendee) if not message: # Free group badges are only considered 'registered' when they are actually claimed. if attendee.paid == c.PAID_BY_GROUP and attendee.group_id and attendee.group.cost == 0: attendee.registered = localized_now() if check_in: attendee.checked_in = localized_now() session.add(attendee) if attendee.is_new and \ session.attendees_with_badges().filter_by(first_name=attendee.first_name, last_name=attendee.last_name, email=attendee.email).count(): raise HTTPRedirect('duplicate?id={}&return_to={}', attendee.id, return_to or 'index') msg_text = '{} has been saved'.format(attendee.full_name) if params.get('save') == 'save_return_to_search': if return_to: raise HTTPRedirect(return_to + '&message={}', 'Attendee data saved') else: raise HTTPRedirect( 'index?uploaded_id={}&message={}&search_text={}', attendee.id, msg_text, '{} {}'.format(attendee.first_name, attendee.last_name) if c.AT_THE_CON else '') else: raise HTTPRedirect('form?id={}&message={}&return_to={}', attendee.id, msg_text, return_to) return { 'message': message, 'attendee': attendee, 'check_in': check_in, 'return_to': return_to, 'omit_badge': omit_badge, 'admin_can_change_status': session.admin_attendee().is_dept_head_of(c.DEFAULT_REGDESK_INT), 'group_opts': [(g.id, g.name) for g in session.query(Group).order_by(Group.name).all()], 'unassigned': { group_id: unassigned for group_id, unassigned in session.query(Attendee.group_id, func.count('*')).filter( Attendee.group_id != None, Attendee.first_name == '').group_by(Attendee.group_id).all()} } # noqa: E711
def update(self, session, password='', message='', **params): account = session.admin_account(params, checkgroups=['access']) if account.is_new: if c.AT_OR_POST_CON and not password: message = 'You must enter a password' else: password = password if c.AT_OR_POST_CON else genpasswd() account.hashed = bcrypt.hashpw(password, bcrypt.gensalt()) message = message or check(account) if not message: message = 'Account settings uploaded' attendee = session.attendee(account.attendee_id) # dumb temporary hack, will fix later with tests account.attendee = attendee session.add(account) if account.is_new and not c.AT_OR_POST_CON: body = render('emails/accounts/new_account.txt', { 'account': account, 'password': password, 'creator': AdminAccount.admin_name() }, encoding=None) send_email.delay( c.ADMIN_EMAIL, attendee.email, 'New ' + c.EVENT_NAME + ' Ubersystem Account', body, model=attendee.to_dict('id')) else: session.rollback() raise HTTPRedirect('index?message={}', message)
def new(self, session, message='', **params): if params.get('id'): raise HTTPRedirect('form?id={}', params['id']) department = session.department(params, bools=Department.all_bools, checkgroups=Department.all_checkgroups) if cherrypy.request.method == 'POST': message = check_dept_admin(session) if not message: message = check(department) if not message: attendee = session.admin_attendee() has_email = bool(attendee.email) department.memberships = [ DeptMembership(attendee=attendee, is_dept_head=True, is_poc=has_email, is_checklist_admin=has_email) ] session.add(department) raise HTTPRedirect('form?id={}', department.id) return {'department': department, 'message': message}
def pre_checkin_check(attendee, group): if c.NUMBERED_BADGES: min_badge, max_badge = c.BADGE_RANGES[attendee.badge_type] if not attendee.badge_num: return 'Badge number is required' elif not (min_badge <= int(attendee.badge_num) <= max_badge): return ('{a.full_name} has a {a.badge_type_label} badge, but ' '{a.badge_num} is not a valid number for ' '{a.badge_type_label} badges').format(a=attendee) if c.COLLECT_EXACT_BIRTHDATE: if not attendee.birthdate: return 'You may not check someone in without a valid date of birth.' elif not attendee.age_group or attendee.age_group == c.AGE_UNKNOWN: return 'You may not check someone in without confirming their age.' if attendee.checked_in: return attendee.full_name + ' was already checked in!' if group and attendee.paid == c.PAID_BY_GROUP and group.amount_unpaid: return 'This attendee\'s group has an outstanding balance of ${}'.format(group.amount_unpaid) if attendee.paid == c.NOT_PAID: return 'You cannot check in an attendee that has not paid.' return check(attendee)
def schedule(self, session, message='', **params): times = session.mits_times(params, applicant=True, checkgroups=['showcase_availability']) team = session.logged_in_mits_team() if cherrypy.request.method == 'POST': if 'showcase_availability' in params: if params.get('showcase_consent'): team.showcase_interest = True else: message = "You must consent to using your information for the showcase." else: team.showcase_interest = False message = message or check(times) if not message: session.add(times) raise HTTPRedirect('index?message={}', 'Times saved') return { 'team': team, 'times': times, 'message': message, 'list': [(val, desc, val in times.showcase_availability_ints) for val, desc in c.MITS_SHOWCASE_SCHEDULE_OPTS] }
def form(self, session, slug, department_id, csrf_token=None, comments=None): attendee = session.admin_attendee() department = session.query(Department).options( subqueryload(Department.dept_checklist_items)).get(department_id) conf = DeptChecklistConf.instances[slug] item = department.checklist_item_for_slug(slug) if not item: item = DeptChecklistItem( attendee=attendee, department=department, slug=slug) if comments is not None: # since this form doesn't use our normal utility methods, we need to check the csrf_token manually check_csrf(csrf_token) item.comments = comments message = check(item) if not message: session.add(item) message = conf.name + ' checklist data uploaded' raise HTTPRedirect( 'index?department_id={}&message={}', department_id, message) return { 'item': item, 'conf': conf, 'department': department }
def new(self, session, message='', **params): if params.get('id', 'None') != 'None': raise HTTPRedirect('form?id={}', params['id']) if 'advance_notices' in params: ns = listify(params.get('advance_notices', [])) params['advance_notices'] = [int(n) for n in ns if n != ''] admin_account = session.current_admin_account() attraction = session.attraction( params, bools=Attraction.all_bools, checkgroups=Attraction.all_checkgroups) if not attraction.department_id: attraction.department_id = None if cherrypy.request.method == 'POST': message = check(attraction) if not message: attraction.owner = admin_account session.add(attraction) raise HTTPRedirect('form?id={}', attraction.id) return { 'admin_account': admin_account, 'attraction': attraction, 'message': message, }
def game(self, session, message='', **params): game = session.mits_game(params, applicant=True) if cherrypy.request.method == 'POST': documents = params.get('upload_documents', []) documents = documents if isinstance(documents, list) else [documents] if not documents[0].filename and not game.documents: message = "You must upload at least one rulesbook or other document." else: message = check(game) if not message: for doc in [d for d in documents if d.filename]: new_doc = MITSDocument(game_id=game.id, filename=doc.filename) with open(new_doc.filepath, 'wb') as f: shutil.copyfileobj(doc.file, f) session.add(new_doc) pictures = params.get('upload_pictures', []) pictures = pictures if isinstance(pictures, list) else [pictures] for pic in [p for p in pictures if p.filename]: new_pic = MITSPicture( game_id=game.id, filename=pic.filename, content_type=pic.content_type.value, extension=pic.filename.split('.')[-1].lower()) with open(new_pic.filepath, 'wb') as f: shutil.copyfileobj(pic.file, f) session.add(new_pic) session.add(game) raise HTTPRedirect('index?message={}', 'Game saved') return {'game': game, 'message': message}
def form(self, session, new_app='', message='', **params): if new_app and 'attendee_id' in params: app = session.art_show_application(params, ignore_csrf=True, bools=['us_only']) else: app = session.art_show_application(params, bools=['us_only']) attendee = None app_paid = 0 if new_app else app.amount_paid attendee_attrs = session.query(Attendee.id, Attendee.last_first, Attendee.badge_type, Attendee.badge_num) \ .filter(Attendee.first_name != '', Attendee.badge_status not in [c.INVALID_STATUS, c.WATCHED_STATUS]) attendees = [ (id, '{} - {}{}'.format(name.title(), c.BADGES[badge_type], ' #{}'.format(badge_num) if badge_num else '')) for id, name, badge_type, badge_num in attendee_attrs ] if cherrypy.request.method == 'POST': if new_app: attendee, message = \ session.attendee_from_art_show_app( **params) else: attendee = app.attendee message = message or check(app) if not message: if attendee: if params.get('badge_status', ''): attendee.badge_status = params['badge_status'] if 'app_paid' in params \ and int(params['app_paid']) != app_paid \ and int(params['app_paid']) > 0: attendee.amount_paid -= app_paid attendee.amount_paid += int(params['app_paid']) session.add(attendee) app.attendee = attendee if 'mark_paid' in params and app.status in [ c.APPROVED, c.PAID ]: app.status = c.APPROVED if int( params['mark_paid']) == 0 else c.PAID session.add(app) if params.get('save') == 'save_return_to_search': return_to = 'index?' else: return_to = 'form?id=' + app.id + '&' raise HTTPRedirect(return_to + 'message={}', 'Application updated') return { 'message': message, 'app': app, 'attendee': attendee, 'app_paid': app_paid, 'attendee_id': app.attendee_id or params.get('attendee_id', ''), 'all_attendees': sorted(attendees, key=lambda tup: tup[1]), 'new_app': new_app, }
def save_art_show_piece(self, session, app_id, message='', **params): restricted = False if params[ 'return_to'] == '/art_show_admin/pieces' else True piece = session.art_show_piece(params, restricted=restricted, bools=['for_sale', 'no_quick_sale']) app = session.art_show_application(app_id) if cherrypy.request.method == 'POST': piece.app_id = app.id piece.app = app message = check(piece) if not message: session.add(piece) if not restricted and 'voice_auctioned' not in params: piece.voice_auctioned = False elif not restricted and 'voice_auctioned' in params and params[ 'voice_auctioned']: piece.voice_auctioned = True session.commit() return { 'error': message, 'success': 'Piece "{}" successfully saved'.format(piece.name) }
def update(self, session, password='', message='', **params): account = session.admin_account(params) if account.is_new: if c.AT_OR_POST_CON and not password: message = 'You must enter a password' else: password = password if c.AT_OR_POST_CON else genpasswd() account.hashed = bcrypt.hashpw(password, bcrypt.gensalt()) message = message or check(account) if not message: message = 'Account settings uploaded' attendee = session.attendee( account.attendee_id ) # dumb temporary hack, will fix later with tests account.attendee = attendee session.add(account) if account.is_new and not c.AT_OR_POST_CON: session.commit() body = render('emails/accounts/new_account.txt', { 'account': account, 'password': password, 'creator': AdminAccount.admin_name() }, encoding=None) send_email.delay(c.ADMIN_EMAIL, attendee.email, 'New ' + c.EVENT_NAME + ' Ubersystem Account', body, model=attendee.to_dict('id')) else: session.rollback() raise HTTPRedirect('index?message={}', message)
def pre_checkin_check(attendee, group): if c.NUMBERED_BADGES: min_badge, max_badge = c.BADGE_RANGES[attendee.badge_type] if not attendee.badge_num: return 'Badge number is required' elif not (min_badge <= int(attendee.badge_num) <= max_badge): return ('{a.full_name} has a {a.badge_type_label} badge, but ' '{a.badge_num} is not a valid number for ' '{a.badge_type_label} badges').format(a=attendee) if c.COLLECT_EXACT_BIRTHDATE: if not attendee.birthdate: return 'You may not check someone in without a valid date of birth.' elif not attendee.age_group or attendee.age_group == c.AGE_UNKNOWN: return 'You may not check someone in without confirming their age.' if attendee.checked_in: return attendee.full_name + ' was already checked in!' if group and attendee.paid == c.PAID_BY_GROUP and group.amount_unpaid: return 'This attendee\'s group has an outstanding balance of ${}'.format( '%0.2f' % group.amount_unpaid) if attendee.paid == c.NOT_PAID: return 'You cannot check in an attendee that has not paid.' return check(attendee)
def edit(self, session, message='', **params): app = session.marketplace_application(params, restricted=True, ignore_csrf=True) return_to = params['return_to'] \ if 'return_to' in params else '/marketplace/edit' if 'id' not in params: message = 'Invalid marketplace application ID. ' \ 'Please try going back in your browser.' if cherrypy.request.method == 'POST': message = check(app, prereg=True) if not message: session.add(app) session.commit( ) # Make sure we update the DB or the email will be wrong! send_email.delay( c.MARKETPLACE_APP_EMAIL, app.email, 'Marketplace Application Updated', render('emails/marketplace/appchange_notification.html', {'app': app}, encoding=None), 'html', model=app.to_dict('id')) raise HTTPRedirect('..{}?id={}&message={}', return_to, app.id, 'Your application has been updated') else: session.rollback() return { 'message': message, 'app': app, 'return_to': 'edit', }
def update(self, id, params): """ Update an attendee using their unique ID, returned by our lookup functions. `params` should be a dictionary with column name: value to update values. Use labels for Choice and MultiChoice columns, and a string like "no" or "yes" for Boolean columns. Date and DateTime columns should be parsed correctly as long as they follow a standard format. Example: <pre>{"first_name": "First", "paid": "doesn't need to", "ribbons": "Staff, Panelist"}</pre> """ with Session() as session: attendee = session.attendee(id, allow_invalid=True) if not attendee: raise HTTPError(404, 'No attendee found with this ID') for key, val in params.items(): params[key] = _parse_if_datetime(key, val) params[key] = _parse_if_boolean(key, val) attendee.apply(params, restricted=False) message = check(attendee) if message: session.rollback() raise HTTPError(400, message) # Staff (not volunteers) also almost never need to pay by default if attendee.staffing and not attendee.orig_value_of('staffing') \ and c.VOLUNTEER_RIBBON not in attendee.ribbon_ints and 'paid' not in params: attendee.paid = c.NEED_NOT_PAY return attendee.id
def checklist_info(self, session, message='', event_id=None, **params): guest = session.guest_group(params) if not session.admin_can_see_guest_group(guest): raise HTTPRedirect( 'index?message={}', 'You cannot view {} groups'.format( guest.group_type_label.lower())) if cherrypy.request.method == 'POST': if event_id: guest.event_id = event_id message = check(guest) if not message: for field in [ 'estimated_loadin_minutes', 'estimated_performance_minutes' ]: if field in params: field_name = "load-in" if field == 'estimated_loadin_minutes' else 'performance' if not params.get(field): message = "Please enter more than 0 estimated {} minutes".format( field_name) elif not str(params.get(field, '')).isdigit(): message = "Please enter a whole number for estimated {} minutes".format( field_name) if not message: raise HTTPRedirect('index?message={}{}', guest.group.name, ' data uploaded') events = session.query(Event).filter_by(location=c.CONCERTS).order_by( Event.start_time).all() return { 'guest': guest, 'message': message, 'events': [(event.id, event.name) for event in events] }
def form(self, session, message='', **params): department_id = params.get('id') if not department_id or department_id == 'None': raise HTTPRedirect('index') if cherrypy.request.method == 'POST': department = session.department( params, bools=Department.all_bools, checkgroups=Department.all_checkgroups) message = check(department) if not message: session.add(department) raise HTTPRedirect('form?id={}&message={}', department.id, 'Department updated successfully') else: department = session.query(Department) \ .filter_by(id=department_id) \ .order_by(Department.id) \ .options( subqueryload(Department.dept_roles).subqueryload(DeptRole.dept_memberships), subqueryload(Department.members).subqueryload(Attendee.shifts).subqueryload(Shift.job), subqueryload(Department.members).subqueryload(Attendee.admin_account), subqueryload(Department.dept_heads).subqueryload(Attendee.dept_memberships), subqueryload(Department.pocs).subqueryload(Attendee.dept_memberships), subqueryload(Department.checklist_admins).subqueryload(Attendee.dept_memberships)) \ .one() return { 'admin': session.admin_attendee(), 'message': message, 'department': department }
def new(self, session, message='', **params): if params.get('id', 'None') != 'None': raise HTTPRedirect('form?id={}', params['id']) if 'advance_notices' in params: ns = listify(params.get('advance_notices', [])) params['advance_notices'] = [int(n) for n in ns if n != ''] admin_account = session.current_admin_account() attraction = session.attraction(params, bools=Attraction.all_bools, checkgroups=Attraction.all_checkgroups) if not attraction.department_id: attraction.department_id = None if cherrypy.request.method == 'POST': message = check(attraction) if not message: attraction.owner = admin_account session.add(attraction) raise HTTPRedirect('form?id={}', attraction.id) return { 'admin_account': admin_account, 'attraction': attraction, 'message': message, }
def form(self, session, message='', **params): defaults = {} if params.get('id') == 'None' and cherrypy.request.method != 'POST': defaults = cherrypy.session.get( 'job_defaults', defaultdict(dict))[params['department_id']] params.update(defaults) job = session.job(params, bools=['extra15'], allowed=['department_id', 'start_time', 'type'] + list(defaults.keys())) if cherrypy.request.method == 'POST': message = check(job) if not message: session.add(job) if params.get('id') == 'None': defaults = cherrypy.session.get('job_defaults', defaultdict(dict)) defaults[params['department_id']] = { field: getattr(job, field) for field in c.JOB_DEFAULTS } cherrypy.session['job_defaults'] = defaults tgt_start_time = str(job.start_time_local).replace(" ", "T") raise HTTPRedirect('index?department_id={}&time={}', job.department_id, tgt_start_time) if 'start_time' in params and 'type' not in params: local_start_time = c.EVENT_TIMEZONE.localize( datetime.strptime(params['start_time'], "%Y-%m-%d %H:%M:%S")) if c.EPOCH <= local_start_time < c.ESCHATON: job.type = c.REGULAR else: job.type = c.SETUP if local_start_time < c.EPOCH else c.TEARDOWN departments = session.admin_attendee().depts_where_can_admin can_admin_dept = any(job.department_id == d.id for d in departments) if not can_admin_dept and (job.department or job.department_id): job_department = job.department or session.query(Department).get( job.department_id) if job.is_new: departments = sorted(departments + [job_department], key=lambda d: d.name) else: departments = [job_department] dept_roles = defaultdict(list) for department in departments: for d in department.dept_roles: dept_roles[d.department_id].append( (d.id, d.name, d.description)) return { 'job': job, 'message': message, 'dept_roles': dept_roles, 'dept_opts': [(d.id, d.name) for d in departments], 'defaults': 'defaults' in locals() and defaults }
def access_groups(self, session, message='', **params): access_group = session.access_group(params) if cherrypy.request.method == "POST": for key in params: if key.endswith('_read_only_access'): col_key = key[:-17] if params[key] != "0": access_group.read_only_access[col_key] = params[key] elif col_key in access_group.read_only_access: del access_group.read_only_access[col_key] elif key.endswith('_access'): col_key = key[:-7] if params[key] != "0": access_group.access[col_key] = params[key] elif col_key in access_group.access: del access_group.access[col_key] session.add(access_group) message = check(access_group) or '' if not message: session.commit() raise HTTPRedirect( 'access_groups?message={}'.format("Success!")) return { 'message': message, 'access_group': access_group, }
def form(self, session, slug, department_id, csrf_token=None, comments=None): attendee = session.admin_attendee() department = session.query(Department).options( subqueryload(Department.dept_checklist_items)).get(department_id) conf = DeptChecklistConf.instances[slug] item = department.checklist_item_for_slug(slug) if not item: item = DeptChecklistItem(attendee=attendee, department=department, slug=slug) if comments is not None: # since this form doesn't use our normal utility methods, we need to check the csrf_token manually check_csrf(csrf_token) item.comments = comments message = check(item) if not message: session.add(item) message = conf.name + ' checklist data uploaded' raise HTTPRedirect('index?department_id={}&message={}', department_id, message) return {'item': item, 'conf': conf, 'department': department}
def new(self, session, message='', **params): if params.get('id'): raise HTTPRedirect('form?id={}', params['id']) department = session.department( params, bools=Department.all_bools, checkgroups=Department.all_checkgroups) if cherrypy.request.method == 'POST': message = check_dept_admin(session) if not message: message = check(department) if not message: attendee = session.admin_attendee() has_email = bool(attendee.email) department.memberships = [DeptMembership( attendee=attendee, is_dept_head=True, is_poc=has_email, is_checklist_admin=has_email)] session.add(department) raise HTTPRedirect('form?id={}', department.id) return { 'department': department, 'message': message }
def form(self, session, message='', **params): department_id = params.get('id') if not department_id or department_id == 'None': raise HTTPRedirect('index') if cherrypy.request.method == 'POST': department = session.department( params, bools=Department.all_bools, checkgroups=Department.all_checkgroups) message = check(department) if not message: session.add(department) raise HTTPRedirect( 'form?id={}&message={}', department.id, 'Department updated successfully') else: department = session.query(Department) \ .filter_by(id=department_id) \ .order_by(Department.id) \ .options( subqueryload(Department.dept_roles).subqueryload(DeptRole.dept_memberships), subqueryload(Department.members).subqueryload(Attendee.shifts).subqueryload(Shift.job), subqueryload(Department.members).subqueryload(Attendee.admin_account), subqueryload(Department.dept_heads).subqueryload(Attendee.dept_memberships), subqueryload(Department.pocs).subqueryload(Attendee.dept_memberships), subqueryload(Department.checklist_admins).subqueryload(Attendee.dept_memberships)) \ .one() return { 'admin': session.admin_attendee(), 'message': message, 'department': department }
def form(self, session, message='', return_to='', omit_badge='', check_in='', **params): attendee = session.attendee( params, checkgroups=Attendee.all_checkgroups, bools=Attendee.all_bools, allow_invalid=True) if 'first_name' in params: attendee.group_id = params['group_opt'] or None if (c.AT_THE_CON and omit_badge) or not attendee.badge_num: attendee.badge_num = None if 'no_override' in params: attendee.overridden_price = None message = '' if c.BADGE_PROMO_CODES_ENABLED and 'promo_code' in params: message = session.add_promo_code_to_attendee(attendee, params.get('promo_code')) if not message: message = check(attendee) if not message: # Free group badges are only considered 'registered' when they are actually claimed. if attendee.paid == c.PAID_BY_GROUP and attendee.group_id and attendee.group.cost == 0: attendee.registered = localized_now() if check_in: attendee.checked_in = localized_now() session.add(attendee) if attendee.is_new and \ session.attendees_with_badges().filter_by(first_name=attendee.first_name, last_name=attendee.last_name, email=attendee.email).count(): raise HTTPRedirect('duplicate?id={}&return_to={}', attendee.id, return_to or 'index') msg_text = '{} has been saved'.format(attendee.full_name) if params.get('save') == 'save_return_to_search': if return_to: raise HTTPRedirect(return_to + '&message={}', 'Attendee data saved') else: raise HTTPRedirect( 'index?uploaded_id={}&message={}&search_text={}', attendee.id, msg_text, '{} {}'.format(attendee.first_name, attendee.last_name) if c.AT_THE_CON else '') else: raise HTTPRedirect('form?id={}&message={}&return_to={}', attendee.id, msg_text, return_to) return { 'message': message, 'attendee': attendee, 'check_in': check_in, 'return_to': return_to, 'omit_badge': omit_badge, 'admin_can_change_status': session.admin_attendee().is_dept_head_of(c.DEFAULT_REGDESK_INT), 'group_opts': [(g.id, g.name) for g in session.query(Group).order_by(Group.name).all()], 'unassigned': { group_id: unassigned for group_id, unassigned in session.query(Attendee.group_id, func.count('*')).filter( Attendee.group_id != None, Attendee.first_name == '').group_by(Attendee.group_id).all()} } # noqa: E711
def register_group_member(self, session, group_id, message='', **params): # Safe to ignore csrf tokens here, because an attacker would need to know the group id a priori group = session.group(group_id, ignore_csrf=True) attendee = session.attendee(params, restricted=True, ignore_csrf=True) must_be_staffing = False if group.unassigned[0].staffing: must_be_staffing = True attendee.staffing = True params['staffing'] = True message = check_pii_consent(params, attendee) or message if not message and 'first_name' in params: message = check(attendee, prereg=True) if not message and not params['first_name']: message = 'First and Last Name are required fields' if not message: if not group.unassigned: raise HTTPRedirect( 'register_group_member?group_id={}&message={}', group_id, 'No more unassigned badges exist in this group') attrs_to_preserve_from_unassigned_group_member = [ 'id', 'group_id', 'badge_type', 'badge_num', 'base_badge_price', 'ribbon', 'paid', 'overridden_price', 'requested_hotel_info'] attendee = group.unassigned[0] for attr in attrs_to_preserve_from_unassigned_group_member: if attr in params: del params[attr] attendee.apply(params, restricted=True) # Free group badges are considered registered' when they are actually claimed. if group.cost == 0: attendee.registered = localized_now() if attendee.amount_unpaid: raise HTTPRedirect('attendee_donation_form?id={}', attendee.id) else: raise HTTPRedirect('badge_updated?id={}&message={}', attendee.id, 'Badge registered successfully') return { 'message': message, 'group_id': group_id, 'group': group, 'attendee': attendee, 'affiliates': session.affiliates(), 'badge_cost': 0, 'must_be_staffing': must_be_staffing, }
def test_more_custom_badges_for_dept_head( self, admin_attendee, session, monkeypatch, after_printed_badge_deadline, department, expected): monkeypatch.setattr(Attendee, 'is_dept_head_of', lambda s, d: d == department) session.regular_attendee.badge_type = session.regular_attendee.badge_type session.regular_attendee.badge_type = c.STAFF_BADGE session.regular_attendee.badge_num = None assert expected == check(session.regular_attendee)
def transfer_badge(self, session, message='', **params): old = session.attendee(params['id']) assert old.is_transferable, 'This badge is not transferrable.' session.expunge(old) attendee = session.attendee(params, restricted=True) if 'first_name' in params: message = check(attendee, prereg=True) if (old.first_name == attendee.first_name and old.last_name == attendee.last_name) \ or (old.legal_name and old.legal_name == attendee.legal_name): message = 'You cannot transfer your badge to yourself.' elif not message and (not params['first_name'] and not params['last_name']): message = check(attendee, prereg=True) if not message and (not params['first_name'] and not params['last_name']): message = 'First and Last names are required.' if not message: subject = c.EVENT_NAME + ' Registration Transferred' body = render('emails/reg_workflow/badge_transfer.txt', {'new': attendee, 'old': old}, encoding=None) try: send_email.delay( c.REGDESK_EMAIL, [old.email, attendee.email, c.REGDESK_EMAIL], subject, body, model=attendee.to_dict('id')) except Exception: log.error('unable to send badge change email', exc_info=True) if attendee.amount_unpaid: raise HTTPRedirect('attendee_donation_form?id={}', attendee.id) else: raise HTTPRedirect( 'badge_updated?id={}&message={}', attendee.id, 'Your registration has been transferred') else: for attr in c.UNTRANSFERABLE_ATTRS: setattr(attendee, attr, getattr(Attendee(), attr)) return { 'old': old, 'attendee': attendee, 'message': message, 'affiliates': session.affiliates() }
def move(self, session, id, location, start_slot): event = session.event(id) event.location = int(location) event.start_time = c.EPOCH + timedelta(minutes=30 * int(start_slot)) resp = {'error': check(event)} if not resp['error']: session.commit() return resp
def test_promo_code_not_is_expired(self): expire = datetime.now(pytz.UTC) - timedelta(days=9) promo_code = PromoCode(discount=1, expiration_date=expire) attendee = Attendee(promo_code=promo_code, placeholder=True, first_name='First', last_name='Last') assert check(attendee, prereg=True) == 'That promo code is expired.'
def test_promo_code_is_useful_special_price(self, monkeypatch): monkeypatch.setattr(c, 'get_attendee_price', lambda r: 0) promo_code = PromoCode(discount=1, expiration_date=next_week) attendee = Attendee(promo_code=promo_code, placeholder=True, first_name='First', last_name='Last') assert check(attendee, prereg=True) == \ "That promo code doesn't make your badge any cheaper. You may already have other discounts."
def test_promo_code_does_not_help_minor(self, monkeypatch): promo_code = PromoCode(discount=1, expiration_date=next_week) attendee = Attendee(birthdate=last_week, promo_code=promo_code, placeholder=True, first_name='First', last_name='Last') assert check(attendee, prereg=True) == \ "You are already receiving an age based discount, you can't use a promo code on top of that."
def edit_judge(self, session, message='', **params): judge = session.indie_judge(params, checkgroups=['genres', 'platforms']) if cherrypy.request.method == 'POST': message = check(judge) if not message: raise HTTPRedirect('index?message={}', 'Judge info updated') return {'judge': judge, 'message': message}
def process_panel_app(session, app, panelist, other_panelists_compiled, **params): """ Checks various parts of a new panel application, either submitted by guests or by non-attendees, and then adds them to a session. """ message = check(app) or check_other_panelists(other_panelists_compiled) or '' if not message: session.add_all([app, panelist] + other_panelists_compiled) return message
def edit_judge(self, session, message='', **params): judge = session.indie_judge(params, checkgroups=['genres', 'platforms'], bools=['no_game_submission']) if cherrypy.request.method == 'POST': message = check(judge) if not message: raise HTTPRedirect('index?message={}', 'Judge info updated') return { 'judge': judge, 'message': message }
def studio(self, session, message='', **params): params.pop('id', None) studio = session.indie_studio(dict(params, id=cherrypy.session.get('studio_id', 'None')), restricted=True) developer = session.indie_developer(params) if cherrypy.request.method == 'POST': message = check(studio) if not message and studio.is_new: message = check(developer) if not message: session.add(studio) if studio.is_new: developer.studio, developer.primary_contact = studio, True session.add(developer) raise HTTPRedirect('continue_app?id={}', studio.id) return { 'message': message, 'studio': studio, 'developer': developer }
def game(self, session, message='', **params): game = session.mits_game(params, bools=['personally_own', 'unlicensed', 'professional'], applicant=True) if cherrypy.request.method == 'POST': message = check(game) if not message: session.add(game) raise HTTPRedirect('index?message={}', 'Game saved') return { 'game': game, 'message': message }
def create_judge(self, session, message='', first_name='', last_name='', email='', **params): judge = session.indie_judge(params, checkgroups=['genres', 'platforms']) if cherrypy.request.method == 'POST': message = check(judge) if not message and not first_name or not last_name or not email: message = 'First name, last name, and email address are all required to add a judge' if not message: # only match on last name and email, to prevent nickname issues; this could cause # problems if we had two judges with the same last name AND the same email address attendee = session.query(Attendee).filter_by(last_name=last_name, email=email).first() if attendee and attendee.admin_account: if attendee.admin_account.judge: raise HTTPRedirect( 'index?message={}{}', attendee.full_name, ' is already registered as a judge') else: attendee.admin_account.judge = judge attendee.admin_account.access = ','.join(map(str, set( attendee.admin_account.access_ints + [c.INDIE_JUDGE]))) raise HTTPRedirect('index?message={}{}', attendee.full_name, ' has been granted judge access') if not attendee: attendee = Attendee(first_name=first_name, last_name=last_name, email=email, placeholder=True, badge_type=c.ATTENDEE_BADGE, paid=c.NEED_NOT_PAY) session.add(attendee) password = genpasswd() attendee.admin_account = AdminAccount( judge=judge, access=str(c.INDIE_JUDGE), hashed=bcrypt.hashpw(password, bcrypt.gensalt()) ) email_body = render('emails/accounts/new_account.txt', { 'password': password, 'account': attendee.admin_account }, encoding=None) send_email.delay( c.MIVS_EMAIL, attendee.email, 'New {} Ubersystem Account'.format(c.EVENT_NAME), email_body, model=attendee.to_dict('id')) raise HTTPRedirect( 'index?message={}{}', attendee.full_name, ' has been given an admin account as an Indie Judge') return { 'message': message, 'judge': judge, 'first_name': first_name, 'last_name': last_name, 'email': email }
def index(self, session, message='', **params): if cherrypy.request.method == 'POST': game = session.indie_game(params, applicant=True) message = check(game) if not message: session.add(game) raise HTTPRedirect('index?message={}', 'Game information updated') return { 'message': message, 'studio': session.logged_in_studio() }
def register_group_member(self, session, group_id, message='', **params): # Safe to ignore csrf tokens here, because an attacker would need to know the group id a priori group = session.group(group_id, ignore_csrf=True) attendee = session.attendee(params, restricted=True, ignore_csrf=True) message = check_pii_consent(params, attendee) or message if not message and 'first_name' in params: message = check(attendee, prereg=True) if not message and not params['first_name']: message = 'First and Last Name are required fields' if not message: if not group.unassigned: raise HTTPRedirect( 'register_group_member?group_id={}&message={}', group_id, 'No more unassigned badges exist in this group') attrs_to_preserve_from_unassigned_group_member = [ 'id', 'group_id', 'badge_type', 'badge_num', 'base_badge_price', 'ribbon', 'paid', 'overridden_price', 'requested_hotel_info'] attendee = group.unassigned[0] for attr in attrs_to_preserve_from_unassigned_group_member: if attr in params: del params[attr] attendee.apply(params, restricted=True) # Free group badges are considered registered' when they are actually claimed. if group.cost == 0: attendee.registered = localized_now() if attendee.amount_unpaid: raise HTTPRedirect('attendee_donation_form?id={}', attendee.id) else: raise HTTPRedirect('badge_updated?id={}&message={}', attendee.id, 'Badge registered successfully') return { 'message': message, 'group_id': group_id, 'group': group, 'attendee': attendee, 'affiliates': session.affiliates(), 'badge_cost': 0 }
def code(self, session, game_id, message='', **params): code = session.indie_game_code(params, bools=['unlimited_use'], applicant=True) code.game = session.indie_game(game_id, applicant=True) if cherrypy.request.method == 'POST': message = check(code) if not message: session.add(code) raise HTTPRedirect('index?message={}', 'Code added') return { 'message': message, 'code': code }
def game(self, session, message='', **params): game = session.indie_game(params, checkgroups=['genres', 'platforms'], bools=['agreed_liability', 'agreed_showtimes'], applicant=True) if cherrypy.request.method == 'POST': message = check(game) if not message: session.add(game) raise HTTPRedirect('index?message={}', 'Game information uploaded') return { 'game': game, 'message': message }
def panel(self, session, message='', **params): times_params = {'id': params.pop('schedule_id', None)} if cherrypy.request.method == 'POST': times_params['availability'] = params.pop('availability', '') panel_app = session.mits_panel_application(params, applicant=True, bools=['participation_interest']) times = session.mits_times(times_params, applicant=True, checkgroups=['availability']) team = session.logged_in_mits_team() if cherrypy.request.method == 'POST': if 'availability' in times_params: team.panel_interest = True if not panel_app.participation_interest and (not panel_app.name or not panel_app.description): message = "Please fill in both a panel name and description and/or " \ "mark that you're interested in participating in a panel run by someone else." else: team.panel_interest = False if panel_app.participation_interest or panel_app.name or panel_app.description: message = "Please tell us your availability for a panel." if not message: message = check(panel_app) message = message or check(times) if not message: session.add(panel_app) session.add(times) raise HTTPRedirect('index?message={}', 'Panel application saved') return { 'times': times, 'panel_app': panel_app, 'message': message, 'list': [ (val, desc, val in times.availability_ints) for val, desc in c.MITS_SCHEDULE_OPTS ] }
def form(self, session, message='', **params): defaults = {} if params.get('id') == 'None' and cherrypy.request.method != 'POST': defaults = cherrypy.session.get('job_defaults', defaultdict(dict))[params['department_id']] params.update(defaults) job = session.job( params, bools=['extra15'], allowed=['department_id', 'start_time', 'type'] + list(defaults.keys())) if cherrypy.request.method == 'POST': message = check(job) if not message: session.add(job) if params.get('id') == 'None': defaults = cherrypy.session.get('job_defaults', defaultdict(dict)) defaults[params['department_id']] = {field: getattr(job, field) for field in c.JOB_DEFAULTS} cherrypy.session['job_defaults'] = defaults tgt_start_time = str(job.start_time_local).replace(" ", "T") raise HTTPRedirect('index?department_id={}&time={}', job.department_id, tgt_start_time) if 'start_time' in params and 'type' not in params: local_start_time = c.EVENT_TIMEZONE.localize(datetime.strptime(params['start_time'], "%Y-%m-%d %H:%M:%S")) if c.EPOCH <= local_start_time < c.ESCHATON: job.type = c.REGULAR else: job.type = c.SETUP if local_start_time < c.EPOCH else c.TEARDOWN departments = session.admin_attendee().depts_where_can_admin can_admin_dept = any(job.department_id == d.id for d in departments) if not can_admin_dept and (job.department or job.department_id): job_department = job.department or session.query(Department).get(job.department_id) if job.is_new: departments = sorted(departments + [job_department], key=lambda d: d.name) else: departments = [job_department] dept_roles = defaultdict(list) for department in departments: for d in department.dept_roles: dept_roles[d.department_id].append((d.id, d.name, d.description)) return { 'job': job, 'message': message, 'dept_roles': dept_roles, 'dept_opts': [(d.id, d.name) for d in departments], 'defaults': 'defaults' in locals() and defaults }
def update_promo_code(self, session, message='', **params): if 'id' in params: promo_code = session.promo_code(params) message = check(promo_code) if message: session.rollback() else: if 'expire' in params: promo_code.expiration_date = localized_now() - timedelta(days=1) message = 'Promo code updated' session.commit() raise HTTPRedirect('view_promo_codes?message={}', message)
def record_mpoint_cashout(self, session, badge_num, amount): try: attendee = session.attendee(badge_num=badge_num) except Exception: return {'success': False, 'message': 'No one has badge number {}'.format(badge_num)} mfc = MPointsForCash(attendee=attendee, amount=amount) message = check(mfc) if message: return {'success': False, 'message': message} else: session.add(mfc) session.commit() message = '{mfc.attendee.full_name} exchanged {mfc.amount} MPoints for cash'.format(mfc=mfc) return {'id': mfc.id, 'success': True, 'message': message}
def record_old_mpoint_exchange(self, session, badge_num, amount): try: attendee = session.attendee(badge_num=badge_num) except Exception: return {'success': False, 'message': 'No one has badge number {}'.format(badge_num)} ome = OldMPointExchange(attendee=attendee, amount=amount) message = check(ome) if message: return {'success': False, 'message': message} else: session.add(ome) session.commit() message = "{ome.attendee.full_name} exchanged {ome.amount} of last year's MPoints".format(ome=ome) return {'id': ome.id, 'success': True, 'message': message}
def mark_item_complete(self, session, slug, department_id): attendee = session.admin_attendee() department = session.query(Department).options( subqueryload(Department.dept_checklist_items)).get(department_id) if department.checklist_item_for_slug(slug): message = 'Checklist item already marked as complete' else: item = DeptChecklistItem(attendee=attendee, department=department, slug=slug) message = check(item) if not message: session.add(item) message = 'Checklist item marked as complete' raise HTTPRedirect( 'index?department_id={}&message={}', department_id, message)
def applicant(self, session, message='', **params): applicant = session.mits_applicant(params, applicant=True) if applicant.attendee_id: raise HTTPRedirect( '../preregistration/confirm?id={}&return_to={}', applicant.attendee_id, '../mits_applications/') if cherrypy.request.method == 'POST': message = check(applicant) if not message: session.add(applicant) raise HTTPRedirect('index?message={}', 'Team member uploaded') return { 'message': message, 'applicant': applicant }
def document(self, session, message='', upload=None, **params): doc = session.mits_document(params, applicant=True) if cherrypy.request.method == 'POST': message = check(doc) if not message and not upload: message = 'You must select a document to upload' if not message: doc.filename = upload.filename with open(doc.filepath, 'wb') as f: shutil.copyfileobj(upload.file, f) raise HTTPRedirect('index?message={}', 'Document Uploaded') return { 'doc': doc, 'message': message }
def test_check_admin_account_access_new(self, session, admin_account, admin_access, access_changes, expected): admin_access = ','.join(map(str, admin_access)) access_changes = ','.join(map(str, access_changes)) admin_account.access = admin_access session.commit() session.refresh(admin_account) test_attendee = Attendee(email='*****@*****.**') session.add(test_attendee) session.commit() test_admin_account = AdminAccount( access=access_changes, attendee_id=test_attendee.id, hashed='<bcrypted>') message = check(test_admin_account) assert message == expected
def picture(self, session, message='', image=None, **params): picture = session.mits_picture(params, applicant=True) if cherrypy.request.method == 'POST': message = check(picture) if not message and (not image or not image.filename): message = 'You must select a picture to upload' if not message: picture.filename = image.filename picture.content_type = image.content_type.value picture.extension = image.filename.split('.')[-1].lower() with open(picture.filepath, 'wb') as f: shutil.copyfileobj(image.file, f) raise HTTPRedirect('index?message={}', 'Picture Uploaded') return { 'message': message, 'picture': picture }