当前位置: 首页>>代码示例>>Python>>正文


Python Semester.start方法代码示例

本文整理汇总了Python中coredata.models.Semester.start方法的典型用法代码示例。如果您正苦于以下问题:Python Semester.start方法的具体用法?Python Semester.start怎么用?Python Semester.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coredata.models.Semester的用法示例。


在下文中一共展示了Semester.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_fake_semester

# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import start [as 别名]
def create_fake_semester(strm):
    """
    Create a close-enough Semester object for testing
    """
    strm = str(strm)
    if Semester.objects.filter(name=strm):
        return
    s = Semester(name=strm)
    yr = int(strm[0:3]) + 1900
    if strm[3] == '1':
        mo = 1
    elif strm[3] == '4':
        mo = 5
    elif strm[3] == '7':
        mo = 9

    s.start = datetime.date(yr,mo,5)
    s.end = datetime.date(yr,mo+3,1)
    s.save()

    sw = SemesterWeek(semester=s, week=1)
    mon = s.start
    while mon.weekday() != 0:
        mon -= datetime.timedelta(days=1)
    sw.monday = mon
    sw.save()

    return s
开发者ID:avacariu,项目名称:coursys,代码行数:30,代码来源:testing.py

示例2: import_semester_info

# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import start [as 别名]
def import_semester_info(verbose=False, dry_run=False, long_long_ago=False, bootstrap=False):
    """
    Update information on Semester objects from SIMS

    Finding the reference is tricky. Try Googling 'sfu calendar {{year}} "academic dates"'

    long_long_ago: import from the beginning of time
    bootstrap: don't assume Semester.current() will work, for bootstrapping test data creation
    """
    output = []
    semester_start = semester_first_day()
    semester_end = semester_last_day()
    sims_holidays = all_holidays()

    if not bootstrap:
        # we want semesters 5 years into the future: that's a realistic max horizon for grad promises
        current = Semester.current()
        strms = [current.offset_name(i) for i in range(15)]
    else:
        strms = []

    if long_long_ago:
        strms = sorted(list(set(strms) | set(semester_start.keys())))
    semesters = dict((s.name, s) for s in Semester.objects.filter(name__in=strms))

    semester_weeks = itertools.groupby(
                SemesterWeek.objects.filter(semester__name__in=strms).select_related('semester'),
                lambda sw: sw.semester.name)
    semester_weeks = dict((k,list(v)) for k,v in semester_weeks)

    holidays = itertools.groupby(
                Holiday.objects.filter(semester__name__in=strms, holiday_type='FULL').select_related('semester'),
                lambda h: h.semester.name)
    holidays = dict((k,list(v)) for k,v in holidays)

    for strm in strms:
        url = settings.BASE_ABS_URL + reverse('sysadmin:edit_semester', kwargs={'semester_name': strm})

        # Semester object
        try:
            semester = semesters[strm]
        except KeyError:
            semester = Semester(name=strm)
            semesters[strm] = semester
            output.append("Creating %s." % (strm,))

        # class start and end dates
        try:
            start = semester_start[strm]
        except KeyError:
            # No data found about this semester: if there's a date already around, honour it
            # Otherwise, guess "same day as this semester last year" which is probably wrong but close.
            start = semester.start
            if not semester.start:
                lastyr = semesters[semester.offset_name(-3)]
                start = lastyr.start.replace(year=lastyr.start.year+1)
                output.append("Guessing start date for %s." % (strm,))

        try:
            end = semester_end[strm]
        except KeyError:
            # no classes scheduled yet? Assume 13 weeks exactly
            end = start + datetime.timedelta(days=91)

        if semester.start != start:
            output.append("Changing start date for %s from %s to %s." % (strm, semester.start, start))
            semester.start = start
        if semester.end != end:
            output.append("Changing end date for %s from %s to %s." % (strm, semester.end, end))
            semester.end = end

        if not dry_run:
            semester.save()

        # SemesterWeeks
        weeks = semester_weeks.get(strm, [])
        if not weeks:
            sw = SemesterWeek(semester=semester, week=1, monday=first_monday(start))
            weeks.append(sw)
            assert sw.monday.weekday() == 0
            output.append("Creating week 1 for %s on %s." % (strm, sw.monday))
            if not dry_run:
                sw.save()
        elif weeks[0].monday != first_monday(start):
            sw = weeks[0]
            sw.monday = first_monday(start)
            output.append("Changing first Monday of %s to %s." % (strm, sw.monday))
            if not dry_run:
                sw.save()

        length = semester.end - semester.start
        if not bootstrap and length > datetime.timedelta(days=92) and len(weeks) < 2 \
                and semester.start - datetime.date.today() < datetime.timedelta(days=365):
            # semester is longer than 13 weeks: insist that the user specify reading week reasonably-soon before the semester starts
            message = "Semester %s is long (%s) but has no reading week specified. Please have a look here: %s\n\nYou probably want to enter the Monday of week 5/6/7/8 as the Monday after reading week, a week later than it would otherwise be." % (strm, length, url)
            if verbose:
                output.append('*** ' + message)
            else:
                import_admin_email(source='coredata.importer.import_semester_info', message=message)
        elif not bootstrap:
#.........这里部分代码省略.........
开发者ID:sfu-fas,项目名称:coursys,代码行数:103,代码来源:importer.py


注:本文中的coredata.models.Semester.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。