本文整理匯總了Python中models.Course.get_by_id方法的典型用法代碼示例。如果您正苦於以下問題:Python Course.get_by_id方法的具體用法?Python Course.get_by_id怎麽用?Python Course.get_by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Course
的用法示例。
在下文中一共展示了Course.get_by_id方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: myget
# 需要導入模塊: from models import Course [as 別名]
# 或者: from models.Course import get_by_id [as 別名]
def myget(self, course_id):
course = Course.get_by_id(int(course_id))
if course is None:
return self.error(404)
if not self.user.has_permission(course):
self.redirect(LIST_COURSES_URL)
return {'course': course}
示例2: join_course
# 需要導入模塊: from models import Course [as 別名]
# 或者: from models.Course import get_by_id [as 別名]
def join_course(self, course_id, code=None):
from models import Course, UserCourse # do this because users.py & courses.py import each other
if code is not None:
course = Course.all().filter('code =', code).get()
elif course_id is not None:
course = Course.get_by_id(course_id)
else:
return ''
if course is None:
return 'Invalid code'
if UserCourse.all().filter('user =', self).filter('course =', course).get():
return 'You are already in the course'
if course.teacher.key().id() == self.key().id():
return 'You teach that course'
UserCourse(user=self, course=course).put()
return course