示例#1
0
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
示例#2
0
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
示例#3
0
def is_oldmyuw_user():
    if has_legacy_preference():
        return True
    if is_optin_user():
        return False
    if is_staff_employee():
        return True
    if is_faculty():
        return True
    if is_current_graduate_student():
        return True
    if is_undergrad_student():
        return False
    return True
示例#4
0
def is_oldmyuw_user():
    if has_legacy_preference():
        return True
    if is_optin_user():
        return False
    if is_staff_employee():
        return True
    if is_faculty():
        return True
    if is_current_graduate_student():
        return True
    if is_undergrad_student():
        return False
    return True
示例#5
0
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))
示例#6
0
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))