本文整理汇总了Python中compair.models.Course.start_date方法的典型用法代码示例。如果您正苦于以下问题:Python Course.start_date方法的具体用法?Python Course.start_date怎么用?Python Course.start_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类compair.models.Course
的用法示例。
在下文中一共展示了Course.start_date方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from compair.models import Course [as 别名]
# 或者: from compair.models.Course import start_date [as 别名]
def post(self):
"""
Create new course
"""
require(CREATE, Course,
title="Course Not Saved",
message="Sorry, your role in the system does not allow you to save courses.")
params = new_course_parser.parse_args()
new_course = Course(
name=params.get("name"),
year=params.get("year"),
term=params.get("term"),
sandbox=params.get("sandbox"),
start_date=params.get('start_date'),
end_date=params.get('end_date', None)
)
if new_course.start_date is not None:
new_course.start_date = datetime.datetime.strptime(
new_course.start_date,
'%Y-%m-%dT%H:%M:%S.%fZ')
if new_course.end_date is not None:
new_course.end_date = datetime.datetime.strptime(
new_course.end_date,
'%Y-%m-%dT%H:%M:%S.%fZ')
if new_course.start_date and new_course.end_date and new_course.start_date > new_course.end_date:
abort(400, title="Course Not Saved", message="Course end time must be after course start time.")
try:
# create the course
db.session.add(new_course)
# also need to enrol the user as an instructor
new_user_course = UserCourse(
course=new_course,
user_id=current_user.id,
course_role=CourseRole.instructor
)
db.session.add(new_user_course)
db.session.commit()
except exc.SQLAlchemyError as e:
db.session.rollback()
current_app.logger.error("Failed to add new course. " + str(e))
raise
on_course_create.send(
self,
event_name=on_course_create.name,
user=current_user,
course=new_course,
data=marshal(new_course, dataformat.get_course()))
return marshal(new_course, dataformat.get_course())