def test_default_all_system(self): today = util.today() y = today.year term = util.get_term(today) sec = Section(year=y, term=term, number=1, start_date=util.today()) sec2 = Section(year=y, term=term, number=2, start_date=util.today()) sec3 = Section(year=2019, term=term, number=3, start_date=util.today()) partner.db.session.add(sec) partner.db.session.add(sec2) partner.db.session.add(sec3) partner.db.session.commit() response = self.app.get('/rest/sections') assert 200 == response.status_code json_data = response.get_json() assert 2 == len(json_data) s1 = json_data[0] s2 = json_data[1] assert s1['number'] == sec.number assert s1['year'] == sec.year assert s1['term'] == sec.term assert s1['start_date'] == util.date_to_mdy(sec.start_date) assert s2['number'] == sec2.number assert s2['year'] == sec2.year assert s2['term'] == sec2.term assert s2['start_date'] == util.date_to_mdy(sec2.start_date)
def sections(): app.logger.debug("Inside sections") headers = request.headers print(headers) sec_id = request.args.get('id') year = request.args.get('year') term = request.args.get('term') date = request.args.get( 'date' ) # an optional parameter which, if given, will include attendance data for the date if date: date = util.parse_date(date) else: date = util.today() if not year: year = date.year if not term: term = util.get_term(date) if sec_id: sections = Section.query.filter_by(id=sec_id).all() else: sections = Section.query.filter_by(year=year, term=term).all() sections = SectionMgr.get_sections_with_roster_data(sections, date) return jsonify(sections)
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 rosters(): year = request.args.get('year') term = request.args.get('term') number = request.args.get('number') date = request.args.get( 'date' ) # an optional parameter which, if given, will include attendance data for the date if date: date = util.parse_date(date) else: date = util.today() if not year: year = date.year if not term: term = util.get_term(date) if not number: number = 1 sec = Section.query.filter_by(year=year, term=term, number=number).first_or_404() roster = sec.roster students = roster.sorted_students() AttendanceMgr.set_attendance_status(students, date) return jsonify(sec.roster.to_dict(students))
def test_get_by_year(self): today = util.today() y = today.year term = util.get_term(today) sec = Section(year=y, term=term, number=1, start_date=today) sec2 = Section(year=2019, term='fall', number=2, start_date=util.today()) partner.db.session.add(sec) partner.db.session.add(sec2) partner.db.session.commit() yr = sec.year # today's month will be used to figure out a term for default in lookup response = self.app.get(f'/rest/sections?year{yr}') assert 200 == response.status_code json_data = response.get_json() # its no longer 2019 so we should only get back one section for today's year assert 1 == len(json_data) s1 = json_data[0] assert s1['number'] == sec.number assert s1['year'] == sec.year assert s1['term'] == sec.term assert s1['start_date'] == util.date_to_mdy(sec.start_date)