def test_create_groups2(self): r = Roster() s1 = Student(onecard_id=1, first_name='a') s2 = Student(onecard_id=2, first_name='b') s3 = Student(onecard_id=3, first_name='c') s4 = Student(onecard_id=4, first_name='d') s5 = Student(onecard_id=5, first_name='e') s6 = Student(onecard_id=6, first_name='f') l = [s1, s2, s3, s4, s5, s6] g1 = Group(id=1) g1.members.append(s1) g1.members.append(s2) g2 = Group(id=2) g2.members.append(s3) g2.members.append(s4) g3 = Group(id=3) g3.members.append(s5) g3.members.append(s6) r.students.append(s1) r.students.append(s2) r.students.append(s3) r.students.append(s4) r.students.append(s5) r.students.append(s6) gen = GroupGenerator() dt = util.mdy_to_date('09/15/2019') start_dt = util.mdy_to_date('09/11/2019') gps = gen.create_groups(r, start_dt, dt, attendance_before_gen=True) assert 3 == len(gps)
def test_gen_groups2(self): r = Roster(id=1) s1 = Student(onecard_id=1, first_name='a') s2 = Student(onecard_id=2, first_name='b') s3 = Student(onecard_id=3, first_name='c') s4 = Student(onecard_id=4, first_name='d') s5 = Student(onecard_id=5, first_name='e') l = [s1, s2, s3, s4, s5] r.students.append(s1) r.students.append(s2) r.students.append(s3) r.students.append(s4) r.students.append(s5) dt = util.mdy_to_date('09/15/2019') start_dt = util.mdy_to_date('09/11/2019') gen = GroupGenerator() a = gen.create_groups(r, start_dt, dt, attendance_before_gen=False) assert len(a) == 2 g1 = Group(id=1) g1.members.append(s1) g1.members.append(s2) g2 = Group(id=2) g2.members.append(s3) g2.members.append(s4) g2.members.append(s5) a = gen.create_groups(r, start_dt, dt, attendance_before_gen=False) assert len(a) == 2
def groups_csv (): labNum = request.args.get('labNum') sec = Section.query.filter_by() date = request.args.get('date') date = util.mdy_to_date(date) year = date.year term = util.get_term(date) section = models.Section.query.filter_by(number=labNum, term=term, year=year).first_or_404() r = models.Roster.query.filter_by(section_id=section.id).first_or_404() #type Roster csv = GroupGenerator().get_groups_csv(r.id, date) filename = 'labgroups' + str(section.number) + '_' + section.title + '_' + date.strftime('%y%m%d' + '.csv') return Response(csv, mimetype="text/csv", headers={"Content-Disposition": "attachment;filename=" + filename})
def roster_admin(): tab = request.form.get('tab') year = request.form.get('year') or request.args.get('year') if not year: year = util.get_current_year() term = request.form.get('term') or request.args.get('term') if not term: term = util.get_current_term() section = None dt = request.args.get('date') # mm/dd/yyyy format if not dt: date = util.today() dt = util.date_to_mdy(date) if request.method == 'POST': if tab == 'section': return process_admin_section_form(year, term, dt, request) else: sec_id = request.form.get('labId') if not sec_id: flash('Please select a section') return redirect(url_for('roster_admin', term=request.form.get('term'), year=request.form.get('year'))) section = Section.query.filter_by(id=sec_id).first_or_404() section.start_date = util.mdy_to_date(request.form.get('startDate')) file = request.files['file'] # if user does not select file, browser also # submit an empty part without filename # if file.filename == '': # flash('No selected file') # return redirect(request.url) process_roster_file_upload(file, section) db.session.commit() return redirect(url_for('roster_admin', section_id=section.id)) #TODO alter rosters_page to take a roster as input rather than meeting_time # return redirect(url_for('rosters_page',meeting_time='wed1')) # show the roster page for the created roster else: sec_id = request.args.get('section_id') if sec_id: section = Section.query.filter_by(id=sec_id).first_or_404() dt = util.date_to_mdy(section.start_date) if section.start_date else dt sections = Section.query.filter_by(year=year, term=term).all() return render_template('admin.html', title='admin', tab='rosters', year=year, term=term, section=section, dt=dt, sections=sections)
def rosters_post(): json = request.get_json() if not json: return abort(400) sec_id = json.get('secId') dt = json.get('date') if not dt or not sec_id: return abort(400) sec = Section.query.filter_by(id=sec_id).first_or_404() r = sec.roster if dt: date = util.mdy_to_date(dt) else: date = util.today() students = json.get('students', []) # caller is sending a sorted list status_codes = [s['status'] for s in students] name_edits = [True if s.get('edited') else False for s in students] if True in name_edits: names = [s['full_name'] for s in students] # names = [s['preferred_fname'] + ' ' + s['last_name'] for s in students ] AttendanceMgr.update_student_names2(r, name_edits, names) AttendanceMgr.update_attendance(r, date, status_codes) db.session.commit() return jsonify({})