def GET(self, request): """ GET returns 200 with the student account balances of the current user """ timer = Timer() try: profile = get_profile_of_current_user() response = profile.json_data() response['campus'] = get_base_campus(request) response['is_grad_student'] = is_grad_student() try: enrollment = get_current_quarter_enrollment(request) response['class_level'] = enrollment.class_level if len(enrollment.majors) > 0: response['majors'] = [] for major in enrollment.majors: response['majors'].append(major.json_data()) if len(enrollment.minors) > 0: response['minors'] = [] for minor in enrollment.minors: response['minors'].append(minor.json_data()) except Exception: pass log_success_response(logger, timer) return HttpResponse(json.dumps(response)) except Exception: return handle_exception(logger, timer, traceback)
def GET(self, request): """ GET returns 200 with the student account balances of the current user """ timer = Timer() logger = logging.getLogger(__name__) profile = get_profile_of_current_user() if profile is None: log_data_not_found_response(logger, timer) return data_not_found() log_success_response(logger, timer) response = profile.json_data() response['campus'] = get_base_campus(request) enrollment = get_current_quarter_enrollment(request) if enrollment is not None: response['is_grad_student'] = is_grad_student() response['class_level'] = enrollment.class_level if len(enrollment.majors) > 0: response['majors'] = [] for major in enrollment.majors: response['majors'].append(major.json_data()) if len(enrollment.minors) > 0: response['minors'] = [] for minor in enrollment.minors: response['minors'].append(minor.json_data()) logger.debug(response) return HttpResponse(json.dumps(response))
def GET(self, request): """ GET returns 200 with the student account balances of the current user """ timer = Timer() try: profile = get_profile_of_current_user() response = profile.json_data() response['display_name'] = get_display_name_of_current_user() response['campus'] = get_base_campus(request) response['is_grad_student'] = is_grad_student() try: enrollment = get_current_quarter_enrollment(request) response['class_level'] = enrollment.class_level if len(enrollment.majors) > 0: response['majors'] = [] for major in enrollment.majors: response['majors'].append(major.json_data()) if len(enrollment.minors) > 0: response['minors'] = [] for minor in enrollment.minors: response['minors'].append(minor.json_data()) except Exception: pass log_success_response(logger, timer) return HttpResponse(json.dumps(response)) except Exception: return handle_exception(logger, timer, traceback)
def get_all_affiliations(request): """ return a dictionary of affiliation indicators. ["student"]: True if the user is currently an UW student. ["grad"]: True if the user is currently an UW graduate student. ["undergrad"]: True if the user is currently an UW undergraduate student. ["pce"]: True if the user is currently an UW PCE student. ["employee"]: True if the user is currently a uw employee. ["stud_employee"]: True if the user is currently a student employee. ["faculty"]: True if the user is currently faculty. ["seattle"]: True if the user is an UW Seattle student in the current quarter. ["bothell"]: True if the user is an UW Bothell student in the current quarter. ["tacoma"]: True if the user is an UW Tacoma student in the current quarter. ["official_seattle"]: True if the user is an UW Seattle student according to the SWS Enrollment. ["official_bothell"]: True if the user is an UW Bothell student according to the SWS Enrollment. ["official_tacoma"]: True if the user is an UW Tacoma student according to the SWS Enrollment. """ if hasattr(request, 'myuw_user_affiliations'): return request.myuw_user_affiliations enrolled_campuses = get_current_quarter_course_campuses(request) is_fyp = False try: is_fyp = is_thrive_viewer() except Exception: # This fails in unit tests w/o userservice pass data = { "grad": is_grad_student(), "undergrad": is_undergrad_student(), "student": is_student(), "pce": is_pce_student(), "stud_employee": is_student_employee(), "employee": is_employee(), "fyp": is_fyp, "faculty": is_faculty(), "seattle": enrolled_campuses["seattle"] or is_seattle_student(), "bothell": enrolled_campuses["bothell"] or is_bothell_student(), "tacoma": enrolled_campuses["tacoma"] or is_tacoma_student(), } # add 'official' campus info official_campuses = _get_official_campuses(get_main_campus(request)) data = dict(data.items() + official_campuses.items()) # Note: # As the UW Affiliation group (gws) only knows about one campus, # we use registered sections in the current quarter # to determine the campuses. log_info(logger, data) request.myuw_user_affiliations = data return data
def get_all_affiliations(request): """ return a dictionary of affiliation indicators. ["student"]: True if the user is currently an UW student. ["grad"]: True if the user is currently an UW graduate student. ["undergrad"]: True if the user is currently an UW undergraduate student. ["pce"]: True if the user is currently an UW PCE student. ["employee"]: True if the user is currently a uw employee. ["stud_employee"]: True if the user is currently a student employee. ["faculty"]: True if the user is currently faculty. ["seattle"]: True if the user is an UW Seattle student in the current quarter. ["bothell"]: True if the user is an UW Bothell student in the current quarter. ["tacoma"]: True if the user is an UW Tacoma student in the current quarter. ["official_seattle"]: True if the user is an UW Seattle student according to the SWS Enrollment. ["official_bothell"]: True if the user is an UW Bothell student according to the SWS Enrollment. ["official_tacoma"]: True if the user is an UW Tacoma student according to the SWS Enrollment. """ if hasattr(request, 'myuw_user_affiliations'): return request.myuw_user_affiliations enrolled_campuses = get_current_quarter_course_campuses(request) is_fyp = False try: is_fyp = is_thrive_viewer() except Exception: # This fails in unit tests w/o userservice pass data = {"grad": is_grad_student(), "undergrad": is_undergrad_student(), "student": is_student(), "pce": is_pce_student(), "stud_employee": is_student_employee(), "employee": is_employee(), "fyp": is_fyp, "faculty": is_faculty(), "seattle": enrolled_campuses["seattle"] or is_seattle_student(), "bothell": enrolled_campuses["bothell"] or is_bothell_student(), "tacoma": enrolled_campuses["tacoma"] or is_tacoma_student(), } # add 'official' campus info official_campuses = _get_official_campuses(get_main_campus(request)) data = dict(data.items() + official_campuses.items()) # Note: # As the UW Affiliation group (gws) only knows about one campus, # we use registered sections in the current quarter # to determine the campuses. log_info(logger, data) request.myuw_user_affiliations = data return data
def _get_enrollments(request): majors = [] minors = [] try: enrollment = get_current_quarter_enrollment(request) if len(enrollment.majors) > 0: for major in enrollment.majors: majors.append(major.major_name) if len(enrollment.minors) > 0: for minor in enrollment.minors: minors.append(minor.short_name) except Exception: pass return {'is_grad': is_grad_student(), 'majors': majors, 'minors': minors}
def _get_enrollments(request): majors = [] minors = [] enrollment = get_current_quarter_enrollment(request) if enrollment is not None: if len(enrollment.majors) > 0: for major in enrollment.majors: majors.append(major.major_name) if len(enrollment.minors) > 0: for minor in enrollment.minors: minors.append(minor.short_name) return {'is_grad': is_grad_student(), 'majors': majors, 'minors': minors}
def log_session(netid, session_key, request): if session_key is None: session_key = '' session_hash = hashlib.md5(session_key).hexdigest() log_entry = {'netid': netid, 'session_key': session_hash, 'class_level': None, 'is_grad': None, 'campus': None} try: level = get_current_quarter_enrollment(request).class_level log_entry['class_level'] = level is_mobile = request.is_mobile or request.is_tablet log_entry['is_mobile'] = bool(is_mobile) except AttributeError: pass log_entry['is_grad'] = is_grad_student() log_entry['is_ugrad'] = is_undergrad_student() log_entry['campus'] = get_base_campus(request) logger.info(json.dumps(log_entry))
def log_session(netid, session_key, request): if session_key is None: session_key = '' session_hash = hashlib.md5(session_key).hexdigest() log_entry = { 'netid': netid, 'session_key': session_hash, 'class_level': None, 'is_grad': None, 'is_ugrad': None, 'is_student': None, 'campus': None } try: level = get_current_quarter_enrollment(request).class_level log_entry['class_level'] = level is_mobile = request.is_mobile or request.is_tablet log_entry['is_mobile'] = bool(is_mobile) except Exception: pass try: log_entry['is_grad'] = is_grad_student() except Exception: pass try: log_entry['is_ugrad'] = is_undergrad_student() except Exception: pass try: log_entry['is_student'] = is_student() except Exception: pass try: log_entry['campus'] = get_base_campus(request) except Exception: pass logger.info(json.dumps(log_entry))
def load_schedule(request, schedule, summer_term=""): json_data = schedule.json_data() json_data["summer_term"] = summer_term colors = get_colors_by_schedule(schedule) buildings = get_buildings_by_schedule(schedule) canvas_data_by_course_id = [] try: canvas_data_by_course_id = get_indexed_by_decrosslisted( get_canvas_enrolled_courses(), schedule.sections) except Exception as ex: logger.error(ex) pass # Since the schedule is restclients, and doesn't know # about color ids, backfill that data section_index = 0 for section in schedule.sections: section_data = json_data["sections"][section_index] color = colors[section.section_label()] section_data["color_id"] = color section_index += 1 if EARLY_FALL_START == section.institute_name: section_data["early_fall_start"] = True json_data["has_early_fall_start"] = True # if section.is_primary_section: try: section_data["lib_subj_guide"] =\ get_subject_guide_by_section(section) except Exception as ex: logger.error(ex) pass if section.section_label() in canvas_data_by_course_id: enrollment = canvas_data_by_course_id[section.section_label()] # canvas_grade = enrollment.final_grade # section_data["canvas_grade"] = canvas_grade canvas_course = enrollment.course if not canvas_course.is_unpublished(): section_data["canvas_url"] = canvas_course.course_url section_data["canvas_name"] = canvas_course.name # MUWM-596 if section.final_exam and section.final_exam.building: building = buildings[section.final_exam.building] if building: section_data["final_exam"]["longitude"] = building.longitude section_data["final_exam"]["latitude"] = building.latitude section_data["final_exam"]["building_name"] = building.name # Also backfill the meeting building data meeting_index = 0 for meeting in section.meetings: try: mdata = section_data["meetings"][meeting_index] if not mdata["building_tbd"]: building = buildings[mdata["building"]] if building is not None: mdata["latitude"] = building.latitude mdata["longitude"] = building.longitude mdata["building_name"] = building.name for instructor in mdata["instructors"]: if ( not instructor["email1"] and not instructor["email2"] and not instructor["phone1"] and not instructor["phone2"] and not instructor["voicemail"] and not instructor["fax"] and not instructor["touchdial"] and not instructor["address1"] and not instructor["address2"] ): instructor["whitepages_publish"] = False meeting_index += 1 except IndexError as ex: pass # MUWM-443 json_data["sections"] = sorted(json_data["sections"], key=itemgetter('curriculum_abbr', 'course_number', 'section_id', )) # add section index index = 0 for section in json_data["sections"]: section["index"] = index index = index + 1 json_data["is_grad_student"] = is_grad_student() return json_data
def load_schedule(request, schedule, summer_term=""): filter_schedule_sections_by_summer_term(schedule, summer_term) json_data = schedule.json_data() json_data["summer_term"] = summer_term if len(schedule.sections) == 0: return json_data colors = get_colors_by_schedule(schedule) if colors is None and len(schedule.sections) > 0: return None buildings = get_buildings_by_schedule(schedule) # Removing call to Canvas pending MUWM-2106 # Too much! MUWM-2270 # canvas_data_by_course_id = [] canvas_data_by_primary_course_id = get_canvas_enrolled_courses() primary = canvas_data_by_primary_course_id canvas_data_by_course_id = get_indexed_by_decrosslisted(primary, schedule.sections) # Since the schedule is restclients, and doesn't know # about color ids, backfill that data section_index = 0 for section in schedule.sections: section_data = json_data["sections"][section_index] color = colors[section.section_label()] section_data["color_id"] = color section_index += 1 # if section.is_primary_section: section_data["lib_subj_guide"] = get_subject_guide_by_section(section) try: evaluation_json_data = json_for_evaluation( request, get_evaluations_by_section(section), section.summer_term ) except Exception as ex: evaluation_json_data = None if evaluation_json_data is not None: section_data["evaluation_data"] = evaluation_json_data if section.section_label() in canvas_data_by_course_id: enrollment = canvas_data_by_course_id[section.section_label()] canvas_url = enrollment.course_url canvas_name = enrollment.course_name # canvas_grade = enrollment.final_grade section_data["canvas_url"] = canvas_url section_data["canvas_name"] = canvas_name # section_data["canvas_grade"] = canvas_grade # MUWM-596 if section.final_exam and section.final_exam.building: building = buildings[section.final_exam.building] if building: section_data["final_exam"]["longitude"] = building.longitude section_data["final_exam"]["latitude"] = building.latitude section_data["final_exam"]["building_name"] = building.name # Also backfill the meeting building data meeting_index = 0 for meeting in section.meetings: try: mdata = section_data["meetings"][meeting_index] if not mdata["building_tbd"]: building = buildings[mdata["building"]] if building is not None: mdata["latitude"] = building.latitude mdata["longitude"] = building.longitude mdata["building_name"] = building.name for instructor in mdata["instructors"]: if ( not instructor["email1"] and not instructor["email2"] and not instructor["phone1"] and not instructor["phone2"] and not instructor["voicemail"] and not instructor["fax"] and not instructor["touchdial"] and not instructor["address1"] and not instructor["address2"] ): instructor["whitepages_publish"] = False meeting_index += 1 except IndexError as ex: pass # MUWM-443 json_data["sections"] = sorted( json_data["sections"], key=itemgetter("curriculum_abbr", "course_number", "section_id") ) json_data["is_grad_student"] = is_grad_student() return json_data
def load_schedule(request, schedule, summer_term=""): json_data = schedule.json_data() json_data["summer_term"] = summer_term colors = get_colors_by_schedule(schedule) buildings = get_buildings_by_schedule(schedule) canvas_data_by_course_id = [] try: canvas_data_by_course_id = get_indexed_by_decrosslisted( get_canvas_enrolled_courses(), schedule.sections) except Exception as ex: logger.error(ex) pass # Since the schedule is restclients, and doesn't know # about color ids, backfill that data section_index = 0 for section in schedule.sections: section_data = json_data["sections"][section_index] color = colors[section.section_label()] section_data["color_id"] = color section_index += 1 if EARLY_FALL_START == section.institute_name: section_data["early_fall_start"] = True json_data["has_early_fall_start"] = True # if section.is_primary_section: try: section_data["lib_subj_guide"] =\ get_subject_guide_by_section(section) except Exception as ex: logger.error(ex) pass if section.section_label() in canvas_data_by_course_id: enrollment = canvas_data_by_course_id[section.section_label()] # canvas_grade = enrollment.final_grade # section_data["canvas_grade"] = canvas_grade canvas_course = enrollment.course if not canvas_course.is_unpublished(): section_data["canvas_url"] = canvas_course.course_url section_data["canvas_name"] = canvas_course.name # MUWM-596 if section.final_exam and section.final_exam.building: building = buildings[section.final_exam.building] if building: section_data["final_exam"]["longitude"] = building.longitude section_data["final_exam"]["latitude"] = building.latitude section_data["final_exam"]["building_name"] = building.name # Also backfill the meeting building data meeting_index = 0 for meeting in section.meetings: try: mdata = section_data["meetings"][meeting_index] if not mdata["building_tbd"]: building = buildings[mdata["building"]] if building is not None: mdata["latitude"] = building.latitude mdata["longitude"] = building.longitude mdata["building_name"] = building.name for instructor in mdata["instructors"]: if (not instructor["email1"] and not instructor["email2"] and not instructor["phone1"] and not instructor["phone2"] and not instructor["voicemail"] and not instructor["fax"] and not instructor["touchdial"] and not instructor["address1"] and not instructor["address2"]): instructor["whitepages_publish"] = False meeting_index += 1 except IndexError as ex: pass # MUWM-443 json_data["sections"] = sorted(json_data["sections"], key=itemgetter( 'curriculum_abbr', 'course_number', 'section_id', )) # add section index index = 0 for section in json_data["sections"]: section["index"] = index index = index + 1 json_data["is_grad_student"] = is_grad_student() return json_data