def load_development_data(): csv_reader = csv.DictReader(_default_users_csv.splitlines()) team_codes = list(TeamMember.team_definitions.keys()) # Sort for deterministic order team_codes.sort() for row in csv_reader: # This script can be run more than once. Do not create user if s/he exists in BOAC db. user = AuthorizedUser.find_by_uid(row['uid']) if not user: user = AuthorizedUser(**row) db.session.add(user) # Random UIDs get test data (saved cohorts) if '1' in user.uid: next_codes = [ team_codes.pop(), team_codes.pop(), team_codes.pop(), team_codes.pop() ] for team_code in next_codes: create_team_members(db.session, team_code) create_cohort(next_codes[0], next_codes[1], user.uid) create_cohort(next_codes[2], next_codes[3], user.uid) db.session.add( TeamMember(code='FHW', member_uid='61889', member_csid='11667051', member_name='Brigitte Lin')) db.session.commit()
def load_cohort_from_csv(app, csv_file='tmp/FilteredAscStudents.csv'): with open(csv_file) as f: reader = csv.DictReader(f) for r in reader: if r['AcadYr'] != THIS_ACAD_YR or r['SportActiveYN'] != 'Yes': continue asc_sport_code_core = r['cSportCodeCore'] if asc_sport_code_core not in SPORT_TRANSLATIONS: app.logger.error( 'Unmapped Sport Code {} has SportActiveYN for SID {}'. format( asc_sport_code_core, r['SID'], )) continue sis_sport_code = SPORT_TRANSLATIONS[asc_sport_code_core] record = TeamMember( member_csid=r['SID'], member_name=r['cName'], code=sis_sport_code, asc_sport_code=r['SportCode'], asc_sport=r['Sport'], asc_sport_code_core=asc_sport_code_core, asc_sport_core=r['acSportCore'], ) db.session.add(record) app.logger.info('Loaded {} TeamMember records from {}'.format( len(db.session.new), csv_file, )) db.session.commit()
def teams_members(): params = request.get_json() team_codes = get_param(params, 'teamCodes', []) order_by = get_param(params, 'orderBy', 'member_name') offset = get_param(params, 'offset', 0) limit = get_param(params, 'limit', 50) return jsonify( TeamMember.summarize_team_members(team_codes, order_by, offset, limit))
def create_team_members(db_session, team_code): team_members = [ TeamMember(code=team_code, member_uid='111', member_csid='1111', member_name='Lin, Brigitte'), TeamMember(code=team_code, member_uid='222', member_csid='2222', member_name='Garza, Isabel'), TeamMember(code=team_code, member_uid='333', member_csid='3333', member_name='Cooper, Terry'), ] for team_member in team_members: db_session.add(team_member)
def get_cohort(code): params = request.get_json() order_by = get_param(params, 'orderBy', 'member_name') if code.isdigit(): offset = get_param(params, 'offset', 0) limit = get_param(params, 'limit', 50) cohort = CohortFilter.find_by_id(int(code), order_by, offset, limit) else: cohort = TeamMember.for_code(code) load_member_profiles(cohort) # Translate requested order_by to naming convention of TeamMember sort_by = 'uid' if order_by == 'member_uid' else 'name' cohort['members'].sort(key=lambda member: member[sort_by]) return tolerant_jsonify(cohort)
def summarize(cohort, order_by='member_name', offset=0, limit=50): filter_criteria = json.loads(cohort.filter_criteria) team_codes = filter_criteria[ 'teams'] if 'teams' in filter_criteria else None summary = { 'id': cohort.id, 'label': cohort.label, 'owners': [user.uid for user in cohort.owners], } if limit > 0 and len(team_codes) > 0: summary.update( TeamMember.summarize_team_members(team_codes, order_by, offset, limit)) # Return a serializable object return summary
def teams_list(): return jsonify(TeamMember.all_teams())
def main(app): from boac.models.team_member import TeamMember cohorts_csv = '{}/cohorts.csv'.format(os.path.expanduser('~/tmp/fixtures')) TeamMember.load_csv(cohorts_csv) print('\nDone. Data inserted in BOAC db.'.format(cohorts_csv), end='\n\n')
def all_students(): sort_by = request.args['sortBy'] if 'sortBy' in request.args else None return tolerant_jsonify(TeamMember.all_athletes(sort_by=sort_by))