def sync(): # TODO: do this async, return 204 cookie = request.cookies.get('catify0') authorizer = auth.Authorizer() syncer.sync_tracks(authorizer, cookie) authorizer.close() return redirect('/', code=302)
def update_prefences(): authorizer = auth.Authorizer() cookie = request.cookies.get('catify0') selected_genres = request.form.getlist('genre') preferences.select_genres(authorizer, cookie, selected_genres) authorizer.close() return redirect('/edit-preferences', code=302)
def post(self): auth = authorizer.Authorizer(self) if not auth.CanAdministerInstitutionFromUrl(): 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") displayRoster = self.request.get("displayRoster") if not displayRoster: logging.fatal("no displayRoster") htmlDesc = self.request.get("htmlDesc") if not htmlDesc: logging.fatal("no htmlDesc") twoPE = self.request.get("twoPE") if not twoPE: logging.fatal("no twoPE") logging.info("*********************") logging.info(twoPE) models.Config.store(institution, session, displayRoster, htmlDesc, twoPE) error_check_logic.Checker.setStatus(institution, session, 'UNKNOWN') self.RedirectToSelf(institution, session, "saved config")
def get(self): try: models.Timer.startTiming() auth = authorizer.Authorizer(self) if not auth.CanAdministerInstitutionFromUrl(): 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") message = self.request.get('message') session_query = urllib.urlencode({ 'institution': institution, 'session': session }) setup_status = error_check_logic.Checker.getStatus( institution, session) groups_classes = models.GroupsClasses.Fetch(institution, session) if not groups_classes: groups_classes = '\n'.join([ "# Sample data. Lines with leading # signs are comments.", "# Change the data below.", "- name: PE_1_day_equivalent", " classes:", " - name: Basketball", " id: 11", " - name: Basketball", " id: 19", " - name: Boxing", " id: 33", " - name: Circuit Training (Beg)", " id: 12", " - name: Circuit Training (Beg)", " id: 43", " - name: Circuit Training (Adv)", " id: 32", " - name: Fitness & Fun", " id: 18", " - name: Walking Club", " id: 50", "- name: PE_2_day_equivalent", " classes:", " - name: Dance", " id: 37", "- name: PE_Mon_or_Tue", " classes:", " - id: 52", " - id: 53", " - id: 54", " - id: 55", " - id: 56", " - id: 57", " - id: 58", "- name: PE_Thu_or_Fri", " classes:", " - id: 59", " - id: 60", " - id: 61", " - id: 62", " - id: 63", " - id: 64", " - id: 65", " - id: 66" ]) template_values = { 'user_email': auth.email, 'institution': institution, 'session': session, 'message': message, 'setup_status': setup_status, 'session_query': session_query, 'groups_classes': groups_classes, 'self': self.request.uri, } template = JINJA_ENVIRONMENT.get_template('groups_classes.html') self.response.write(template.render(template_values)) finally: logging.error(models.Timer.getDataStr())
def get(self): auth = authorizer.Authorizer(self) if not auth.CanAdministerInstitutionFromUrl(): 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") message = self.request.get('message') session_query = urllib.urlencode({'institution': institution, 'session': session}) students = models.Students.FetchJson(institution, session) if students: students.sort(key=lambda(s): (s['last'], s['first'])) homerooms = getStudentsByHomeroom(students) template_values = { 'user_email' : auth.email, 'institution' : institution, 'session' : session, 'message': message, 'session_query': session_query, 'homerooms': homerooms, } template = JINJA_ENVIRONMENT.get_template('report/homeroom.html') self.response.write(template.render(template_values))
def post(self): institution = self.request.get("institution") if not institution: logging.fatal("no institution") session = self.request.get("session") if not session: logging.fatal("no session") auth = authorizer.Authorizer(self) if not (auth.CanAdministerInstitutionFromUrl() or auth.HasTeacherAccess() or (auth.HasStudentAccess() and auth.HasPageAccess(institution, session, "schedule"))): self.response.status = 403 # Forbidden return use_full_description = auth.CanAdministerInstitutionFromUrl() class_ids = self.request.get("class_ids") class_ids = json.loads(class_ids) results = {} classes = models.Classes.FetchJson(institution, session) classes_by_id = {} for c in classes: classes_by_id[c['id']] = c for class_id in class_ids: results[str(class_id)] = logic.GetHoverText( institution, session, use_full_description, classes_by_id[int(class_id)]) self.response.write(json.dumps(results))
def post(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") email = auth.student_email want = self.request.get("want").split(",") if want[0] == '': want.pop(0) dontcare = self.request.get("dontcare").split(",") if dontcare[0] == '': dontcare.pop(0) dontwant = self.request.get("dontwant").split(",") if dontwant[0] == '': dontwant.pop(0) models.Preferences.Store(email, institution, session, want, dontcare, dontwant) if self.request.get("Save") == "Save": logging.info("Form Saved") else: logging.info("Auto Save") self.RedirectToSelf(institution, session, email, "Saved Preferences")
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, "materials"): auth.RedirectTemporary(institution, session) return message = self.request.get('message') session_query = urllib.urlencode({'institution': institution, 'session': session}) welcome_msg = models.Materials.Fetch(institution, session) template_values = { 'user_email' : auth.email, 'institution' : institution, 'session' : session, 'message': message, 'session_query': session_query, 'self': self.request.uri, 'welcome_msg' : welcome_msg, } template = JINJA_ENVIRONMENT.get_template('preregistration.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") message = self.request.get('message') session_query = urllib.urlencode({ 'institution': institution, 'session': session }) email = auth.student_email closed_msg = models.Closed.Fetch(institution, session) template_values = { 'user_email': auth.email, 'institution': institution, 'session': session, 'message': message, 'session_query': session_query, 'closed_msg': closed_msg, } template = JINJA_ENVIRONMENT.get_template('coming_soon.html') self.response.write(template.render(template_values))
def get(self): auth = authorizer.Authorizer(self) if not auth.CanAdministerInstitutionFromUrl(): 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") message = self.request.get('message') session_query = urllib.urlencode({ 'institution': institution, 'session': session }) checker = error_check_logic.Checker(institution, session) setup_status, error_chk_detail = checker.ValidateSetup() template_values = { 'user_email': auth.email, 'institution': institution, 'session': session, 'message': message, 'setup_status': setup_status, 'error_chk_detail': error_chk_detail, 'session_query': session_query, } template = JINJA_ENVIRONMENT.get_template('error_check.html') self.response.write(template.render(template_values))
def decorated_function(*args, **kwargs): authorizer = auth.Authorizer() cookie = request.cookies.get('catify0') if authorizer.attempt_login_if_not_logged_in(cookie): authorizer.close() return f(*args, **kwargs) authorizer.close() return redirect('/spotify-login', code=302)
def make_genre_playlists(): # TODO: do this async, return 204 authorizer = auth.Authorizer() cookie = request.cookies.get('catify0') playlists.make_genre_playlists(authorizer, cookie) authorizer.close() return 'genre playlists created'
def testShouldSaveRecentAccess(self): handler = self.getFakeRequestHandler() self.setupAuthorizer("user_123@host") auth = authorizer.Authorizer(handler) stored_data = authorizer.models.ndb.stored_data self.AssertEqual(1, len(stored_data)) self.AssertEqual(models.RecentAccess, stored_data[0].GetKey()[0]) self.AssertEqual('user_123@host', stored_data[0].GetKey()[1])
def get(self): auth = authorizer.Authorizer(self) if not auth.CanAdministerInstitutionFromUrl(): 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") message = self.request.get('message') session_query = urllib.urlencode({ 'institution': institution, 'session': session }) setup_status = error_check_logic.Checker.getStatus( institution, session) students = models.Students.Fetch(institution, session) students_obj = models.Students.FetchJson(institution, session) if not students_obj: students_obj = [] if not students: students = '\n'.join([ "# Sample data. Lines with leading # signs are comments.", "# Change the data below.", "- email: [email protected]", " first: Stu", " last: Dent1", " current_grade: 8", " current_homeroom: 29", "- email: [email protected]", " first: Stu", " last: Dent2", " current_grade: 7", " current_homeroom: 19", "- email: [email protected]", " first: Stu", " last: Dent3", " current_grade: 6", " current_homeroom: 23", ]) template_values = { 'user_email': auth.email, 'institution': institution, 'session': session, 'message': message, 'setup_status': setup_status, 'session_query': session_query, 'students': students, 'self': self.request.uri, 'students_obj': students_obj, } template = JINJA_ENVIRONMENT.get_template('students.html') self.response.write(template.render(template_values))
def get(self): auth = authorizer.Authorizer(self) if not (auth.CanAdministerInstitutionFromUrl() or auth.HasTeacherAccess()): auth.Redirect() return user_type = 'None' if auth.CanAdministerInstitutionFromUrl(): user_type = 'Admin' elif auth.HasTeacherAccess(): user_type = 'Teacher' institution = self.request.get("institution") if not institution: logging.fatal("no institution") session = self.request.get("session") if not session: logging.fatal("no session") message = self.request.get('message') session_query = urllib.urlencode({ 'institution': institution, 'session': session }) classes = models.Classes.FetchJson(institution, session) dayparts = models.Dayparts.FetchJson(institution, session) dp_dict = {} # used for ordering by col then row for dp in dayparts: dp_dict[dp['name']] = str(dp['col']) + str(dp['row']) rosters = {} for c in classes: rosters[c['id']] = models.ClassRoster.FetchEntity( institution, session, c['id']) c['num_locations'] = len(set(s['location'] for s in c['schedule'])) c['dayorder'] = dp_dict[c['schedule'][0]['daypart']] if classes: classes.sort(key=listOrder) students = models.Students.FetchJson(institution, session) for s in students: s['email'] = s['email'].lower() if students: students.sort(key=lambda (s): s['last']) template_values = { 'user_email': auth.email, 'user_type': user_type, 'institution': institution, 'session': session, 'message': message, 'session_query': session_query, 'classes': classes, 'rosters': rosters, 'students': students, } template = JINJA_ENVIRONMENT.get_template( 'report/attendance_list.html') self.response.write(template.render(template_values))
def post(self): auth = authorizer.Authorizer(self) if not auth.CanAdministerInstitutionFromUrl(): auth.Redirect() return institution = self.request.get("institution") action = self.request.get("action"); if action == "add_admin": email = self.request.get("administrator") models.Admin.Store(institution, email) self.RedirectToSelf(institution, 'added admin %s' % email) return if action == "delete_admin": msgs = [] administrators = self.request.get("administrator", allow_multiple=True) for email in administrators: msgs.append(email) models.Admin.Delete(institution, email) self.RedirectToSelf(institution, 'deleted admins %s' % ','.join(msgs)) return if action == "add_session": name = self.request.get("session") logging.info('adding session: %s for institution: %s' % (name, institution)) models.Session.store(institution, name) # Set current database version when creating a new session # so we don't get upgrade error message. error_check_logic.Checker.setDBVersion(institution, name) self.RedirectToSelf(institution, 'added session %s' % name) return if action == "remove_session": name = self.request.get("session") logging.info('removing session: %s from institution: %s' % (name, institution)) models.Session.delete(institution, name) self.RedirectToSelf(institution, 'removed session %s' % name) return if action == "enable_logins": name = self.request.get("session") logging.info('enable session: %s from institution: %s' % (name, institution)) models.ServingSession.store(institution, name) self.RedirectToSelf(institution, 'enabled logins for %s' % name) return if action == "disable_logins": name = self.request.get("session") logging.info('disable session: %s from institution: %s' % (name, institution)) models.ServingSession.delete(institution) self.RedirectToSelf(institution, 'disabled logins for %s' % name) return name = self.request.get("session") logging.error('Unexpected action: %s session: %s institution: %s' % ( action, name, institution)) return
def edit_preferences(): authorizer = auth.Authorizer() cookie = request.cookies.get('catify0') preferences.add_new_possible_playlists(authorizer, cookie) prefs = preferences.get_user_preferences(authorizer,cookie) authorizer.close() return render_template('edit-preferences.html', preferences=prefs)
def get(self): auth = authorizer.Authorizer(self) if not auth.CanAdministerInstitutionFromUrl(): 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") message = self.request.get('message') session_query = urllib.urlencode({'institution': institution, 'session': session}) setup_status = error_check_logic.Checker.getStatus(institution, session) requirements = models.Requirements.Fetch(institution, session) if not requirements: requirements = '\n'.join([ "# Sample data. Lines with leading # signs are comments.", "# Change the data below.", "- name: PE_REQUIREMENT", " applies_to: []", " exempt:", " - [email protected]", " - [email protected]", " class_or_group_options:", " -", # OR " - PE_Mon_or_Tue", # AND " - PE_Thu_or_Fri", " -", # OR " - PE_2_day_equivalent", " -", # OR " - PE_Mon_or_Tue", # AND " - PE_1_day_equivalent", " -", # OR " - PE_1_day_equivalent", # AND " - PE_Thu_or_Fri", " -", # OR " - PE_1_day_equivalent", # AND " - PE_1_day_equivalent"]) template_values = { 'user_email' : auth.email, 'institution' : institution, 'session' : session, 'message': message, 'setup_status': setup_status, 'session_query': session_query, 'requirements': requirements, 'self': self.request.uri, } template = JINJA_ENVIRONMENT.get_template('requirements.html') self.response.write(template.render(template_values))
def post(self): auth = authorizer.Authorizer(self) if not (auth.CanAdministerInstitutionFromUrl() or auth.HasTeacherAccess()): auth.Redirect() return user_type = 'None' if auth.CanAdministerInstitutionFromUrl(): user_type = 'Admin' elif auth.HasTeacherAccess(): user_type = 'Teacher' institution = self.request.get("institution") if not institution: logging.fatal("no institution") session = self.request.get("session") if not session: logging.fatal("no session") submitted_date = self.request.get("submitted_date") if not submitted_date: logging.fatal("no date") c_id = self.request.get("c_id") if not c_id: logging.fatal("no class id") present_kids = self.request.get("present_kids") absent_kids = self.request.get("absent_kids") if present_kids: present_kids = [e for e in present_kids.split(',')] else: present_kids = [] if absent_kids: absent_kids = [e for e in absent_kids.split(',')] else: absent_kids = [] note = self.request.get("note") teachers = models.Teachers.FetchJson(institution, session) teacher = logic.FindUser(auth.email, teachers) if teacher is None: teacher = {} teacher['first'] = "" teacher['last'] = auth.email attendance = models.Attendance.FetchJson(institution, session, c_id) # Clobber existing data, or if none, create a new element attendance[submitted_date] = { "present": present_kids, "absent": absent_kids, "submitted_by": " ".join([teacher['first'], teacher['last']]), "submitted_date": submitted_date, "note": note, } models.Attendance.store(institution, session, c_id, attendance) self.RedirectToSelf(institution, session, c_id, submitted_date)
def get(self): auth = authorizer.Authorizer(self) if not auth.CanAdministerInstitutionFromUrl(): 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") message = self.request.get('message') session_query = urllib.urlencode({ 'institution': institution, 'session': session }) dayparts = models.Dayparts.FetchJson(institution, session) dp_dict = {} # used for ordering by col then row for dp in dayparts: dp_dict[dp['name']] = str(dp['col']) + str(dp['row']) classes = models.Classes.FetchJson(institution, session) for c in classes: c['dayorder'] = dp_dict[c['schedule'][0]['daypart']] if classes: classes.sort(key=listOrder) students = models.Students.FetchJson(institution, session) students_by_email = {} for s in students: s['email'] = s['email'].lower() students_by_email[s['email']] = s if students: students.sort(key=lambda (s): s['last']) class_rosters = {} for c in classes: class_roster = models.ClassRoster.FetchEntity( institution, session, c['id']) class_roster['emails'].sort() addStudentData(class_roster, students_by_email) class_rosters[c['id']] = class_roster template_values = { 'user_email': auth.email, 'institution': institution, 'session': session, 'message': message, 'session_query': session_query, 'classes': classes, 'class_rosters': class_rosters, } template = JINJA_ENVIRONMENT.get_template('report/signup_main.html') self.response.write(template.render(template_values))
def get_artists(): auth = authorizer.Authorizer() cur = auth.conn.cursor() cur.execute(""" select spotify_id from catify.tracks where audio_features_updated_at < (current_timestamp - interval '48 hours') order by audio_features_updated_at limit 100 """) result = ','.join([x[0] for x in cur]) cur.close() return result