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


Python Semester.save方法代码示例

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


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

示例1: get_or_create_semester

# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import save [as 别名]
def get_or_create_semester(strm):
    if not (isinstance(strm, basestring) and strm.isdigit() and len(strm)==4):
        raise ValueError, "Bad strm: " + repr(strm)
    oldsem = Semester.objects.filter(name=strm)
    if oldsem:
        return oldsem[0]

    db = SIMSConn()
    db.execute("SELECT strm, term_begin_dt, term_end_dt FROM ps_term_tbl WHERE strm=%s", (strm,))
    row = db.fetchone()
    if row is None:
        raise ValueError, "Not Found: %r" % (strm)
    strm, st, en = row
    
    # create Semester object
    st = datetime.datetime.strptime(st, "%Y-%m-%d").date()
    en = datetime.datetime.strptime(en, "%Y-%m-%d").date()
    sem = Semester(name=strm, start=st, end=en)
    sem.save()
    
    # also create SemesterWeek object for the first week
    first_monday = st
    while first_monday.weekday() != 0:
        first_monday += datetime.timedelta(days=1)    
    wk = SemesterWeek(semester=sem, week=1, monday=first_monday)
    wk.save()
    
    return sem
开发者ID:avacariu,项目名称:coursys,代码行数:30,代码来源:queries.py

示例2: create_fake_semester

# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import save [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

示例3: setUp

# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import save [as 别名]
 def setUp(self):
     p1 = Person(emplid=210012345, userid="test1",
             last_name="Lname", first_name="Fname", pref_first_name="Fn", middle_name="M")
     p1.save()
     
     s = Semester(name="1077", start=date(2007,9,4), end=date(2007,12,3))
     s.save()
 
     unit = Unit.objects.get(label="CMPT")
     self.co1 = CourseOffering(owner=unit, subject="CMPT", number="120", section="D100", semester=s, component="LEC",
                         graded=True, crse_id=11111, class_nbr=22222, campus='BRNBY', title="Computer Stuff",
                         enrl_cap=100, enrl_tot=99, wait_tot=2)
     
     self.co2 = CourseOffering(owner=unit, subject="CMPT", number="165", section="D100", semester=s, component="LEC",
                         graded=True, crse_id=22222, class_nbr=11111, campus='SURRY', title="Web Stuff",
                         enrl_cap=85, enrl_tot=80, wait_tot=4)
     self.co1.save()
     self.co2.save()
开发者ID:avacariu,项目名称:coursys,代码行数:20,代码来源:tests.py

示例4: create_semester

# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import save [as 别名]
def create_semester():
    s = Semester(name="1077", start=date(2007,9,4), end=date(2007,12,3))
    s.save()
    return s
开发者ID:avacariu,项目名称:coursys,代码行数:6,代码来源:tests.py

示例5: create_semesters

# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import save [as 别名]
def create_semesters():
    semester_1124 = Semester(name="1124", start=date(2012,4,4), end=date(2012,9,3))
    semester_1124.save()
    semester_1127 = Semester(name="1127", start=date(2012,9,4), end=date(2012,12,3))
    semester_1127.save()
    semester_1131 = Semester(name="1131", start=date(2013,1,4), end=date(2013,4,3))
    semester_1131.save()
    semester_1134 = Semester(name="1134", start=date(2013,4,4), end=date(2013,9,3))
    semester_1134.save()
    semester_1137 = Semester(name="1137", start=date(2013,9,4), end=date(2013,12,3))
    semester_1137.save()
    semester_1141 = Semester(name="1141", start=date(2014,1,4), end=date(2014,4,3))
    semester_1141.save()
    semester_1144 = Semester(name="1144", start=date(2014,4,4), end=date(2014,9,3))
    semester_1144.save()
    semester_1147 = Semester(name="1147", start=date(2014,9,4), end=date(2014,12,3))
    semester_1147.save()
    semester_1151 = Semester(name="1151", start=date(2015,1,4), end=date(2015,4,3))
    semester_1151.save()
    semester_1154 = Semester(name="1154", start=date(2015,4,4), end=date(2015,9,3))
    semester_1154.save()
    semester_1157 = Semester(name="1157", start=date(2015,9,4), end=date(2015,12,3))
    semester_1157.save()
    semester_1161 = Semester(name="1161", start=date(2016,1,4), end=date(2016,4,3))
    semester_1161.save()
    semester_1164 = Semester(name="1164", start=date(2016,4,4), end=date(2016,9,3))
    semester_1164.save()
    semester_1167 = Semester(name="1167", start=date(2016,9,4), end=date(2016,12,3))
    semester_1167.save()
开发者ID:avacariu,项目名称:coursys,代码行数:31,代码来源:tests.py

示例6: import_semester_info

# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import save [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.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。