示例#1
0
文件: term.py 项目: fanglinfang/myuw
def get_current_quarter(request):
    """
    Return a restclients.models.sws.Term object
    for the current quarter.
    """
    timer = Timer()
    try:
        comparison_date = get_comparison_date(request)
        term = get_term_by_date(comparison_date)
        after = get_term_after(term)

        if comparison_date > term.grade_submission_deadline.date():
            return after

        return term
    except Exception as ex:
        print ex
        log_exception(logger,
                      'get_current_term',
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      'get_current_term',
                      timer)
    return None
示例#2
0
def _get_schedule(regid, term):
    """
    @return a restclients.models.sws.ClassSchedule object
    Return the actively enrolled sections for the current user
    in the given term/quarter
    """
    if regid is None or term is None:
        return None
    logid = ('get_schedule_by_regid_and_term ' +
             str(regid) + ',' + str(term.year) + ',' + term.quarter)
    timer = Timer()
    try:
        schedule = get_schedule_by_regid_and_term(regid, term, False)

        # XXX - 2015 workaround for MUWM-3390.
        # We want something different for 2016 - MUWM-3391
        non_early_start_sections = []
        for section in schedule.sections:
            if EARLY_FALL_START != section.institute_name:
                non_early_start_sections.append(section)

        schedule.sections = non_early_start_sections
        return schedule
    except Exception as ex:
        log_exception(logger,
                      logid,
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      logid,
                      timer)
    return None
示例#3
0
def get_current_quarter_course_campuses(request):
    """
    Returns a dictionary indicating the campuses that the student
    has enrolled in the current quarter.
    """
    try:
        current_quarter_sche = get_current_quarter_schedule(request)
    except Exception as ex:
        log_exception(logger, 'get_current_quarter_course_campuses',
                      traceback.format_exc())
        current_quarter_sche = None
    return _get_campuses_by_schedule(current_quarter_sche)
示例#4
0
def get_current_quarter_enrollment(request):
    regid = get_regid_of_current_user()

    timer = Timer()
    id = "%s %s" % ("get enrollment by regid", regid)
    try:
        return get_enrollment_by_regid_and_term(regid, get_current_quarter(request))
    except Exception:
        log_exception(logger, id, traceback.format_exc())
    finally:
        log_resp_time(logger, id, timer)
    return None
示例#5
0
def get_current_quarter_course_campuses(request):
    """
    Returns a dictionary indicating the campuses that the student
    has enrolled in the current quarter.
    """
    try:
        current_quarter_sche = get_current_quarter_schedule(request)
    except Exception as ex:
        log_exception(logger,
                      'get_current_quarter_course_campuses',
                      traceback.format_exc())
        current_quarter_sche = None
    return _get_campuses_by_schedule(current_quarter_sche)
示例#6
0
文件: pws.py 项目: fanglinfang/myuw
def _get_person_of_current_user():
    """
    Retrieve the person data using the netid of the current user
    """
    timer = Timer()
    try:
        return PWS().get_person_by_netid(get_netid_of_current_user())
    except Exception as ex:
        log_exception(logger,
                      'pws.get_person_by_netid',
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      'pws.get_person_by_netid',
                      timer)
    return None
示例#7
0
文件: hfs.py 项目: fanglinfang/myuw
def get_account_balances_by_uwnetid(uwnetid):
    """
    returns restclients.models.hfs.HfsAccouts
    for the given uwnetid
    """
    if uwnetid is None:
        return None
    id = "%s %s" % ('get_hfs_accounts', uwnetid)

    try:
        return get_hfs_accounts(uwnetid)
    except Exception as ex:
        log_exception(logger,
                      id,
                      traceback.format_exc())
    return None
示例#8
0
def get_canvas_enrolled_courses():
    """
    Returns calendar information for the current term.
    """
    timer = Timer()
    try:
        regid = get_regid_of_current_user()
        return get_indexed_data_for_regid(regid)
    except AttributeError:
        # If course is not in canvas, skip
        pass
    except Exception as ex:
        log_exception(logger, "get_canvas_enrolled_courses", traceback.format_exc())
    finally:
        log_resp_time(logger, "get_canvas_enrolled_courses", timer)
    return []
示例#9
0
def _get_email_forwarding_by_uwnetid(uwnetid):
    """
    returns restclients.models.uwnetid.UwEmailForwarding object
    for a given uwnetid
    """

    if uwnetid is None:
        return None

    id = "%s %s" % ('_get_email_forwarding_by_uwnetid', uwnetid)
    try:
        return get_email_forwarding(uwnetid)
    except Exception:
        log_exception(logger,
                      id,
                      traceback.format_exc())
    return None
示例#10
0
def _get_account_by_uwnetid(uwnetid):
    """
    returns restclients.models.library.MyLibAccount object
    for a given uwnetid
    """

    if uwnetid is None:
        return None

    id = "%s %s" % ('_get_account_by_uwnetid', uwnetid)
    try:
        return get_account(uwnetid)
    except Exception:
        log_exception(logger,
                      id,
                      traceback.format_exc())
    return None
示例#11
0
文件: term.py 项目: fanglinfang/myuw
def get_next_quarter(request):
    """
    Returna restclients.models.sws.Term object
    for the next quarter.
    """
    timer = Timer()
    try:
        current = get_current_quarter(request)
        return get_term_after(current)
    except Exception as ex:
        log_exception(logger,
                      'get_next_term',
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      'get_next_term',
                      timer)
    return None
示例#12
0
文件: gws.py 项目: fanglinfang/myuw
def _is_member(groupid):
    """
    Return True if the current user netid is
    an effective member of the given group
    """
    timer = Timer()
    try:
        return GWS().is_effective_member(groupid,
                                         get_netid_of_current_user())
    except Exception as ex:
        log_exception(logger,
                      'gws.is_effective_member of ' + groupid,
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      'gws.is_effective_member of ' + groupid,
                      timer)
    return None
示例#13
0
文件: term.py 项目: fanglinfang/myuw
def _get_term_by_year_and_quarter(year, quarter):
    """
    Returns Term object by the given year and quarter.
    If year and quarter are None, return the current term
    """
    logid = ('get_term_by_year_and_quarter ' +
             str(year) + "," + quarter)
    timer = Timer()
    try:
        return sws_term.get_term_by_year_and_quarter(year, quarter)
    except Exception as ex:
        log_exception(logger,
                      logid,
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      logid,
                      timer)
    return None
示例#14
0
def get_profile_of_current_user():
    """
    Return restclients.models.sws.SwsPerson object
    """
    regid = get_regid_of_current_user()

    timer = Timer()
    id = "%s %s" % ('get sws.person by regid', regid)
    try:
        return get_person_by_regid(regid)
    except Exception:
        log_exception(logger,
                      id,
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      id,
                      timer)
    return None
示例#15
0
def get_subject_guide_by_section(section):
    """
    returns a url string
    """
    id = "%s %s %s %s %s" % ('get_subject_guide',
                             section.curriculum_abbr,
                             section.sln,
                             section.term.quarter,
                             section.term.year)
    try:
        return get_subject_guide(section.curriculum_abbr,
                                 section.sln,
                                 section.term.quarter,
                                 section.term.year)
    except Exception:
        log_exception(logger,
                      id,
                      traceback.format_exc())
    return None
示例#16
0
def _get_account_balances_by_regid(user_regid):
    """
    returns restclients.models.sws.Finance object for a given regid
    """

    if user_regid is None:
        return None

    timer = Timer()
    id = "%s %s" % ('_get_account_balances_by_regid', user_regid)
    try:
        return get_account_balances_by_regid(user_regid)
    except Exception:
        log_exception(logger,
                      id,
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      id,
                      timer)
    return None
示例#17
0
def get_colors_by_regid_and_schedule(regid, schedule):
    if schedule is None or len(schedule.sections) == 0:
        return None
    timer = Timer()
    try:
        return _indexed_colors_by_section_label(
            CourseColor.objects.filter(
                regid=regid,
                year=schedule.term.year,
                quarter=schedule.term.quarter),
            regid,
            schedule)
    except Exception as ex:
        log_exception(logger,
                      'query CourseColor',
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      'query CourseColor',
                      timer)
    return None
示例#18
0
def _get_notices_by_regid(user_regid):
    """
    returns SWS notices for a given regid with
    myuw specific categories
    """

    if user_regid is None:
        return None

    timer = Timer()

    try:
        notices = get_notices_by_regid(user_regid)
        if notices is not None:
            return categorize_notices(notices)
    except Exception:
        log_exception(logger,
                      'Notice.get_notices',
                      traceback.format_exc())
    finally:
        log_resp_time(logger,
                      'Notice.get_notices',
                      timer)
    return None
示例#19
0
文件: page.py 项目: mattventura/myuw
def index(request,
          year=None,
          quarter=None,
          summer_term=None):

    netid = UserService().get_user()
    if not netid:
        log_invalid_netid_response(logger, timer)
        return invalid_session()

    if _is_mobile(request):
        # On mobile devices, all students get the current myuw.  Non-students
        # are sent to the legacy site.
        try:
            if not is_student():
                logger.info("%s not a student, redirect to legacy!" % netid)
                return redirect_to_legacy_site()
        except Exception as ex:
            log_exception(logger,
                          '%s is_student' % netid,
                          traceback.format_exc())
            logger.info("%s, redirected to legacy!" % netid)
            return redirect_to_legacy_site()

    else:
        # On the desktop, we're migrating users over.  There are 2 classes of
        # users - mandatory and opt-in switchers.  The mandatory users, who
        # are users who haven't been at the UW long enough to be accustomed to
        # the existing myuw.
        # The other class of users can opt to use the legacy myuw instead.
        # Check to see if they have a set preference, and if not, keep them on
        # the new version
        if not is_mandatory_switch_user():
            if is_optin_switch_user():
                if has_legacy_preference():
                    return redirect_to_legacy_site()
            else:
                return redirect_to_legacy_site()

    timer = Timer()
    context = {
        "year": year,
        "quarter": quarter,
        "summer_term": summer_term,
        "home_url": "/",
        "err": None,
        "user": {
            "netid": None,
            "affiliations": get_all_affiliations(request)
        },
        "card_display_dates": get_card_visibilty_date_values(request),
    }

    context["user"]["session_key"] = request.session.session_key
    log_session(netid, request.session.session_key, request)
    try:
        my_uwemail_forwarding = get_email_forwarding_for_current_user()
        if my_uwemail_forwarding.is_active():
            c_user = context["user"]
            c_user["email_is_uwgmail"] = my_uwemail_forwarding.is_uwgmail()
            c_user["email_is_uwlive"] = my_uwemail_forwarding.is_uwlive()
    except Exception:
        log_exception(logger,
                      'get_email_forwarding_for_current_user',
                      traceback.format_exc())
        pass

    context["user"]["netid"] = netid
    if year is None or quarter is None:
        cur_term = get_current_quarter(request)
        if cur_term is None:
            context["err"] = "No current quarter data!"
        else:
            context["year"] = cur_term.year
            context["quarter"] = cur_term.quarter
    else:
        pass
    log_success_response_with_affiliation(logger, timer, request)
    return render_to_response("index.html",
                              context,
                              context_instance=RequestContext(request))
示例#20
0
文件: page.py 项目: vegitron/myuw
def index(request,
          year=None,
          quarter=None,
          summer_term=None):

    timer = Timer()
    netid = UserService().get_user()
    if not netid:
        log_invalid_netid_response(logger, timer)
        return invalid_session()

    if _is_mobile(request):
        # On mobile devices, all students get the current myuw.  Non-students
        # are sent to the legacy site.
        try:
            if not is_student():
                logger.info("%s not a student, redirect to legacy!" % netid)
                return redirect_to_legacy_site()
        except Exception:
            log_exception(logger,
                          '%s is_student' % netid,
                          traceback.format_exc())
            logger.info("%s, redirected to legacy!" % netid)
            return redirect_to_legacy_site()

    else:
        if is_oldmyuw_user():
            return redirect_to_legacy_site()

    context = {
        "year": year,
        "quarter": quarter,
        "summer_term": summer_term,
        "home_url": "/",
        "err": None,
        "user": {
            "netid": None,
            "affiliations": get_all_affiliations(request)
        },
        "card_display_dates": get_card_visibilty_date_values(request),
    }

    context["user"]["session_key"] = request.session.session_key
    log_session(netid, request.session.session_key, request)
    try:
        my_uwemail_forwarding = get_email_forwarding_for_current_user()
        if my_uwemail_forwarding.is_active():
            c_user = context["user"]
            c_user["email_is_uwgmail"] = my_uwemail_forwarding.is_uwgmail()
            c_user["email_is_uwlive"] = my_uwemail_forwarding.is_uwlive()
    except Exception:
        log_exception(logger,
                      'get_email_forwarding_for_current_user',
                      traceback.format_exc())
        pass

    context["user"]["netid"] = netid
    if year is None or quarter is None:
        cur_term = get_current_quarter(request)
        if cur_term is None:
            context["err"] = "No current quarter data!"
        else:
            context["year"] = cur_term.year
            context["quarter"] = cur_term.quarter
    else:
        pass
    log_success_response_with_affiliation(logger, timer, request)
    return render_to_response("index.html",
                              context,
                              context_instance=RequestContext(request))