本文整理汇总了Python中coredata.models.Semester.week_weekday方法的典型用法代码示例。如果您正苦于以下问题:Python Semester.week_weekday方法的具体用法?Python Semester.week_weekday怎么用?Python Semester.week_weekday使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coredata.models.Semester
的用法示例。
在下文中一共展示了Semester.week_weekday方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_semester_info
# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import week_weekday [as 别名]
#.........这里部分代码省略.........
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:
# also check that the last day of classes is at a coherent time. Might reveal problems with reading week specification.
endweek,_ = semester.week_weekday(semester.end, weeks=weeks)
if endweek not in [12, 13, 14]:
message = "Semester %s ends in week %i (should be 13 or 14). That's weird. Have a look here to see if things are coherent: %s" % (strm, endweek, url)
if verbose:
output.append('*** ' + message)
else:
import_admin_email(source='coredata.importer.import_semester_info', message=message)
# Holidays
hs = holidays.get(strm, [])
h_start, h_end = Semester.start_end_dates(semester)
for dt, desc in [(d,h) for d,h in sims_holidays if h_start <= d <= h_end]:
existing = [h for h in hs if h.date == dt]
if existing:
holiday = existing[0]
else:
holiday = Holiday(semester=semester, date=dt, holiday_type='FULL')
output.append("Adding holiday %s on %s." % (desc, dt))
holiday.description = desc
if not dry_run:
holiday.save()
if verbose:
print('\n'.join(output))