示例#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 add_date_term_info(request, context):
    actual_now = get_default_date()
    used_now = get_comparison_date(request)

    context["actual_now_date"] = str(actual_now)
    context["effective_now_date"] = str(used_now)
    context["is_using_mock_data"] = is_using_file_dao()

    try:
        actual_term = get_term_by_date(actual_now)
        context["actual_now_term_year"] = actual_term.year
        context["actual_now_term_quarter"] = actual_term.quarter
    except Exception as ex:
        pass

    try:
        used_term = get_term_by_date(used_now)
        context["effective_now_term_year"] = used_term.year
        context["effective_now_term_quarter"] = used_term.quarter
    except Exception as ex:
        pass
    def handle(self, *args, **options):

        if len(args):
            (year, quarter) = args[0].split('-')
            term = get_term_by_year_and_quarter(year, quarter)
        else:
            term = get_term_by_date(datetime.now().date())

        csv_path = generate_unused_course_csv(term)

        if not settings.SIS_IMPORT_CSV_DEBUG:
            print csv_path
示例#4
0
def add_date_term_info(request, context):
    actual_now = get_default_datetime()
    used_now = get_comparison_datetime(request)

    context["actual_now_date"] = str(actual_now)
    context["effective_now_date"] = str(used_now)
    context["is_using_mock_data"] = is_using_file_dao()

    try:
        actual_term = get_term_by_date(actual_now.date())
        context["actual_now_term_year"] = actual_term.year
        context["actual_now_term_quarter"] = actual_term.quarter
    except Exception as ex:
        pass

    try:
        used_term = get_term_by_date(used_now.date())
        context["effective_now_term_year"] = used_term.year
        context["effective_now_term_quarter"] = used_term.quarter
    except Exception as ex:
        pass
示例#5
0
def _admin(request, template):
    if not can_view_support_app(): 
        return HttpResponseRedirect('/')

    curr_date = datetime.now().date()
    try:
        term = get_term_by_date(curr_date)
        curr_year = term.year
        curr_quarter = term.quarter
    except DataFailureException as ex:
        curr_year = curr_date.year
        curr_quarter = ''

    params = {
        'EVENT_UPDATE_FREQ': settings.ADMIN_EVENT_GRAPH_FREQ,
        'IMPORT_UPDATE_FREQ': settings.ADMIN_IMPORT_STATUS_FREQ,
        'CURRENT_QUARTER': curr_quarter,
        'CURRENT_YEAR': curr_year,
        'can_manage_admin_group': True if can_manage_admin_group() else False,
        'can_view_restclients': True if can_view_source_data() else False,
        'admin_group': settings.CANVAS_MANAGER_ADMIN_GROUP,
    }
    return render_to_response(template, params, RequestContext(request))
    def handle(self, *args, **options):

        if len(args):
            (year, quarter) = args[0].split('-')
            target_term = get_term_by_year_and_quarter(year, quarter)

        else:
            curr_date = datetime.now().date()
            curr_term = get_term_by_date(curr_date)

            if curr_date < curr_term.census_day:
                self.update_job()
                return

            target_term = get_term_before(get_term_before(curr_term))

        term_sis_id = target_term.canvas_sis_id()
        try:
            imp = Term.objects.queue_unused_courses(term_sis_id)
        except EmptyQueueException:
            self.update_job()
            return

        try:
            imp.csv_path = generate_unused_course_csv(term_sis_id)
        except:
            imp.csv_errors = traceback.format_exc()

        imp.save()

        try:
            imp.import_csv()
        except MissingImportPathException as ex:
            if not imp.csv_errors:
                imp.delete()

        self.update_job()
示例#7
0
文件: term.py 项目: kroberts-uw/myuw
def get_current_quarter(request):
    """
    Return a restclients.models.sws.Term object
    for the current quarter refered in the user session.
    """
    timer = Timer()
    if hasattr(request, 'myuw_current_quarter'):
        return request.myuw_current_quarter

    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():
            request.myuw_current_quarter = after
            return after

        request.myuw_current_quarter = term
        return term
    finally:
        log_resp_time(logger,
                      'get_current_term',
                      timer)
示例#8
0
    def test_by_date(self):
        with self.settings(
                RESTCLIENTS_SWS_DAO_CLASS='restclients.dao_implementation.sws.File'):

            date = datetime.strptime("2013-01-10", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2013)
            self.assertEquals(term.quarter, 'winter')

            date = datetime.strptime("2013-01-01", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2012)
            self.assertEquals(term.quarter, 'autumn')

            date = datetime.strptime("2013-01-07", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2013)
            self.assertEquals(term.quarter, 'winter')

            date = datetime.strptime("2013-01-06", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2012)
            self.assertEquals(term.quarter, 'autumn')

            date = datetime.strptime("2013-07-04", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2013)
            self.assertEquals(term.quarter, 'summer')

            date = datetime.strptime("2013-12-31", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2013)
            self.assertEquals(term.quarter, 'autumn')
示例#9
0
    def test_by_date(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=SWSF):

            date = datetime.strptime("2013-01-10", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2013)
            self.assertEquals(term.quarter, 'winter')

            date = datetime.strptime("2013-01-01", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2012)
            self.assertEquals(term.quarter, 'autumn')

            date = datetime.strptime("2013-01-07", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2013)
            self.assertEquals(term.quarter, 'winter')

            date = datetime.strptime("2013-01-06", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2012)
            self.assertEquals(term.quarter, 'autumn')

            date = datetime.strptime("2013-07-04", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2013)
            self.assertEquals(term.quarter, 'summer')

            date = datetime.strptime("2013-12-31", "%Y-%m-%d").date()
            term = get_term_by_date(date)

            self.assertEquals(term.year, 2013)
            self.assertEquals(term.quarter, 'autumn')
示例#10
0
def get_current_active_term(dt):
    curr_term = get_term_by_date(dt.date())
    if dt > curr_term.grade_submission_deadline:
        curr_term = get_term_after(curr_term)
    return curr_term