def testEligibleClassIdsForStudentByGradeAndGroup(self): classes = self.SetupClassesAndStudentGroups() institution = "foo" session = "bar" student = {"email": "member@the_in_crowd.org", "current_grade": 8} # call the unit under test class_ids = logic.EligibleClassIdsForStudent( institution, session, student, classes) self.AssertEqual(['1', '3', '4', '5'], class_ids)
def testEligibleClassIdsForStudentByGrade(self): classes = self.SetupClassesAndStudentGroups() institution = "foo" session = "bar" student = {"email": "*****@*****.**", "current_grade": 8} # call the unit under test class_ids = logic.EligibleClassIdsForStudent( institution, session, student, classes) self.AssertEqual(['1', '3'], class_ids)
def testEligibleClassIdsForStudentByDefault(self): classes = self.SetupClassesAndStudentGroups() institution = "foo" session = "bar" student = {"email": "*****@*****.**", "current_grade": 6} # call the unit under test class_ids = logic.EligibleClassIdsForStudent( institution, session, student, classes) self.AssertEqual(['1'], class_ids)
def RandomPrefs(self, institution, session): students = models.Students.FetchJson(institution, session) classes = models.Classes.FetchJson(institution, session) for student in students: email = student['email'] eligible_class_ids = logic.EligibleClassIdsForStudent( institution, session, student, classes) eligible_class_ids = set(eligible_class_ids) want = random.sample(eligible_class_ids, random.randint(1, 5)) dontwant = random.sample(eligible_class_ids.difference(want), random.randint(1, 5)) # want = [str(item) for item in want] # dontwant = [str(item) for item in dontwant] models.Preferences.Store(email, institution, session, want, [], dontwant)
def get(self): auth = authorizer.Authorizer(self) if not auth.HasStudentAccess(): auth.Redirect() return institution = self.request.get("institution") if not institution: logging.fatal("no institution") session = self.request.get("session") if not session: logging.fatal("no session") if not auth.HasPageAccess(institution, session, "schedule"): auth.RedirectTemporary(institution, session) return message = self.request.get('message') session_query = urllib.urlencode({'institution': institution, 'session': session}) email = auth.student_email dayparts = models.Dayparts.FetchJson(institution, session) if not dayparts: dayparts = [] classes = models.Classes.FetchJson(institution, session) try: _ = [c for c in classes] except TypeError: classes = [] classes_by_daypart = {} dayparts_ordered = [] max_row = max([daypart['row'] for daypart in dayparts]) max_col = max([daypart['col'] for daypart in dayparts]) # order the dayparts by row and col specified in yaml for row in range(max_row): dayparts_ordered.append([]) for col in range(max_col): found_daypart = False for dp in dayparts: if dp['row'] == row+1 and dp['col'] == col+1: dayparts_ordered[row].append(dp['name']) found_daypart = True if found_daypart == False: dayparts_ordered[row].append('') eligible_classes = logic.EligibleClassIdsForStudent( institution, session, auth.student_entity, classes) for daypart in dayparts: classes_by_daypart[daypart['name']] = [] classes_by_id = {} use_full_description = auth.CanAdministerInstitutionFromUrl() for c in classes: class_id = str(c['id']) if class_id not in eligible_classes: continue classes_by_id[class_id] = c c['hover_text'] = logic.GetHoverText(institution, session, use_full_description, c) c['description'] = logic.GetHTMLDescription(institution, session, c) for daypart in [s['daypart'] for s in c['schedule']]: if daypart in classes_by_daypart: classes_by_daypart[daypart].append(c) for daypart in classes_by_daypart: classes_by_daypart[daypart].sort(key=lambda c:c['name']) schedule = models.Schedule.Fetch(institution, session, email) schedule = schedule.split(",") if schedule and schedule[0] == "": schedule = schedule[1:] config = models.Config.Fetch(institution, session) template_values = { 'user_email' : auth.email, 'institution' : institution, 'session' : session, 'message': message, 'session_query': session_query, 'student': auth.student_entity, #'dayparts': dayparts, 'classes_by_daypart': classes_by_daypart, 'dayparts_ordered': dayparts_ordered, 'schedule': json.dumps(schedule), 'classes_by_id': classes_by_id, 'html_desc': config['htmlDesc'], } template = JINJA_ENVIRONMENT.get_template('schedule.html') self.response.write(template.render(template_values))
def get(self): auth = authorizer.Authorizer(self) if not auth.HasStudentAccess(): auth.Redirect() return institution = self.request.get("institution") if not institution: logging.fatal("no institution") session = self.request.get("session") if not session: logging.fatal("no session") if not auth.HasPageAccess(institution, session, "preferences"): auth.RedirectTemporary(institution, session) return message = self.request.get('message') session_query = urllib.urlencode({ 'institution': institution, 'session': session }) classes = models.Classes.FetchJson(institution, session) try: _ = [c for c in classes] except TypeError: classes = [] classes_by_id = {} use_full_description = auth.CanAdministerInstitutionFromUrl() for c in classes: class_id = str(c['id']) class_name = c['name'] class_desc = logic.GetHoverText(institution, session, use_full_description, c) classes_by_id[class_id] = { 'name': class_name, 'description': class_desc } if not classes_by_id: classes_by_id['0'] = {'name': 'None', 'desc': 'None'} eligible_class_ids = set( logic.EligibleClassIdsForStudent(institution, session, auth.student_entity, classes)) prefs = models.Preferences.FetchEntity(auth.student_email, institution, session) want_ids = prefs.want.split(',') dontcare_ids = prefs.dontcare.split(',') dontwant_ids = prefs.dontwant.split(',') new_class_ids = eligible_class_ids.difference(want_ids) new_class_ids = new_class_ids.difference(dontcare_ids) new_class_ids = new_class_ids.difference(dontwant_ids) dontcare_ids = list(new_class_ids) + dontcare_ids if dontcare_ids[len(dontcare_ids) - 1] == '': dontcare_ids.pop() def RemoveDeletedClasses(class_ids): for class_id in class_ids: if class_id in eligible_class_ids: yield class_id want_ids = list(RemoveDeletedClasses(want_ids)) dontcare_ids = list(RemoveDeletedClasses(dontcare_ids)) dontwant_ids = list(RemoveDeletedClasses(dontwant_ids)) logging.info('want: ' + ','.join(want_ids)) logging.info('dont want: ' + ','.join(dontwant_ids)) logging.info('dont care: ' + ','.join(dontcare_ids)) template_values = { 'user_email': auth.email, 'institution': institution, 'session': session, 'message': message, 'session_query': session_query, 'classes': classes_by_id, 'student': auth.student_entity, 'want_ids': want_ids, 'dontwant_ids': dontwant_ids, 'dontcare_ids': dontcare_ids, } template = JINJA_ENVIRONMENT.get_template('preferences.html') self.response.write(template.render(template_values))