本文整理匯總了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