本文整理汇总了Python中course.Course.getById方法的典型用法代码示例。如果您正苦于以下问题:Python Course.getById方法的具体用法?Python Course.getById怎么用?Python Course.getById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course.Course
的用法示例。
在下文中一共展示了Course.getById方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: User
# 需要导入模块: from course import Course [as 别名]
# 或者: from course.Course import getById [as 别名]
class User(object):
db = None
'''
classdocs
'''
#constructor
def __init__(self):
self.connection = Connection('localhost', 27017)
self.db = self.connection.MOOC
self.db_users = self.db['usercollection']
self.course = Course()
def reset(self):
self.db_users.remove()
# get user by email
def getByEmail(self, email):
info = self.db_users.find_one({'email' : email})
return info
#create user
def create(self, info):
try:
data = {}
data['email'] = info['email']
data['own'] = []
data['enrolled'] = []
data['quizzes'] = []
return self.db_users.save(data)
except ValidationError as ve:
print str(ve)
return False
#update user
def update(self, email, info):
try:
if info.has_key('email'):
del info['email']
data={}
data = info #TODO
self.db_users.update({'email' : email}, {"$set" : data})
except ValidationError as ve:
print str(ve)
return False
return True
def updateOwnedCourse(self, email, courseId):
self.db_users.update({'email' : email}, {"$addToSet" :{'own' : str(courseId)}})
#delete user
def delete(self, email):
return self.db_users.remove({'email' : email})
#enroll user
def enroll(self, email, courseId):
#check if course is available
course = self.course.getById(courseId)
if not course:
return None #course not available
#add new course
self.db_users.update({'email' : email}, {"$addToSet" :{'enrolled' : courseId}})
return True
#enroll user
def drop(self, email, courseId):
#add new course
self.db_users.update({'email' : email}, {"$pull" :{'enrolled' : courseId}})
return True