def updateBoard(id,boardName): print '--in moo.createBoard' user_id = request.forms.get("id") bName=request.forms.get("boardName") print "id", user_id print "boardName", bName couch = couchdb.Server() mydb = couch['userdb'] myboardDB = couch['boards'] #doc = mydb[user_id] if user_id in mydb: if bName in myboardDB: # bname=request.PUT.get('boardName') # bdesc = request.PUT.get('boardDesc') # category = request.PUT.get('category') # boardType = request.PUT.get('isPrivate') bname = request.POST.get('name') bdesc = request.POST.get('boardDesc') category = request.POST.get('category') boardType = request.POST.get('isPrivate') print "new board name is ", bname global storage storage = Storage() boardId = storage.updateBoard(user_id,bName, bname, bdesc, category, boardType) return boardId else: return "Board not Authorized!" else: return "User not authorized"
class Business(object): def __init__(self): print 'business created' # Get storage object self.__store = Storage() def get(self, value): print 'In business.get method' try: return self.__store.get('business', 'business_id', value) except: traceback.print_exc() return 'failed' def remove(self, value): print 'In business.remove method' try: return self.__store.remove('business', 'business_id', value) except: traceback.print_exc() return 'failed' def getAll(self): print 'In business.getAll method' try: return self.__store.getAll('business') except: traceback.print_exc() return 'failed'
def deleteComment(userId,boardName,pinId): print '--in moo.deleteComment' global storage storage = Storage() bId = storage.getBoardId(boardName) couch = couchdb.Server() mydb = couch['userdb'] board = couch['boards'] pins= couch ['pinsdb'] if userId in mydb: if bId in board: if pinId in pins: # desc=request.POST.get('description') #print desc global storage storage = Storage() pinId = storage.deleteComment(userId,bId,pinId) return pinId else: return "Pin not found!" else: return "Board not Found!" else: return "User Not Authorized!"
def updatePin(userId,boardName,pinId): couch = couchdb.Server() mydb = couch['userdb'] board = couch['boards'] pin=couch['pinsdb'] global storage storage = Storage() bId = storage.getBoardId(boardName) if userId in mydb: if bId in board: if pinId in pin: pname = request.POST.get('pinName') pdesc = request.POST.get('pinDesc') image = request.POST.get('image') boardId = storage.updatePin(userId,bId, pinId,pname, pdesc,image ) return boardId else: return "Invalid Pin Id!" else: return "Invalid Board Id!" else: return "User not authorized"
def signUp(): print '---> moo.signUp' Fname = request.POST.get('fname') Lname = request.POST.get('lname') emailId = request.POST.get('emailId') password = request.POST.get('password') global storage storage = Storage() user_id = storage.insertUser(Fname, Lname, emailId, password) return user_id
def getBoardList(userId): print '--in moo.getBoardList' L = list() couch = couchdb.Server() print "id is ----",userId myUserdb = couch['userdb'] if userId in myUserdb: storage = Storage() L = storage.getBoardNames(userId) return L else: return "User Id does not exist!"
def __init__(self, base, conf_fn): self.host = socket.gethostname() self.base = base self.conf = {} # should emit a failure (file not found) message if os.path.exists(conf_fn): with open(conf_fn) as cf: for line in cf: name, var = line.partition("=")[::2] self.conf[name.strip()] = var.strip() else: raise Exception("configuration file not found.") # create storage self.__store = Storage()
def deleteBoard(userId,boardName): print '--in moo.deleteBoard' couch = couchdb.Server() mydb = couch['userdb'] myboardDB = couch['boards'] global storage storage = Storage() bId = storage.getBoardId(boardName) if userId in mydb: if bId in myboardDB: boardId = storage.deleteBoard(userId,bId) else: return "Board not Authorized!" else: return "User not authorized"
class Announcement(object): def __init__(self): print 'Announcement created' # create storag self.__store = Storage() def add(self, data): print 'In announcement.add method' try: return self.__store.add('announcement', data) except: traceback.print_exc() return 'failed' def get(self, value): print 'In announcement.get method' try: return self.__store.get('announcement', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def update(self, value, data): print 'In announcement.update method' try: return self.__store.update('announcement', '_id', ObjectId(value), data) except: traceback.print_exc() return 'failed' def remove(self, value): print 'In announcement.remove method' try: return self.__store.remove('announcement', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def getAll(self): print 'In announcement.getAll method' try: return self.__store.getAll('announcement') except: traceback.print_exc() return 'failed'
class Message(object): def __init__(self): print 'message created' # create storage self.__store = Storage() def add(self, data): print 'In message.add method' try: return self.__store.add('message', data) except: traceback.print_exc() return 'failed' def get(self, value): print 'In message.get method' try: return self.__store.get('message', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def update(self, value, data): print 'In message.update method' try: return self.__store.update('message', '_id', ObjectId(value), data) except: traceback.print_exc() return 'failed' def remove(self, value): print 'In message.remove method' try: return self.__store.remove('message', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def getAll(self): print 'In message.getAll method' try: return self.__store.getAll('message') except: traceback.print_exc() return 'failed'
def getBoardDetails(userId,boardName): print '--in moo.getBoardList' couch = couchdb.Server() myUserdb = couch['userdb'] myboardDB = couch['boards'] storage = Storage() bId = storage.getBoardId(boardName) if userId in myUserdb: if bId in myboardDB: doc = storage.viewBoard(bId) return doc else: return "Board Id does not exist" else: return "User not Authorized!"
def createBoard(userId): couch = couchdb.Server() myUserdb = couch['userdb'] print myUserdb if userId in myUserdb: bname=request.POST.get('boardName') bdesc = request.POST.get('boardDesc') category=request.POST.get('category') boardType=request.POST.get('isPrivate') global storage storage = Storage() boardId = storage.insertBoard(userId,bname,bdesc,category,boardType) return boardId else: return "User not Authorized!"
class Discussion(object): def __init__(self): print 'discussion created' # create storage self.__store = Storage() def add(self, data): print 'In discussion.add method' try: return self.__store.add('discussion', data) except: traceback.print_exc() return 'failed' def get(self, value): print 'In discussion.get method' try: return self.__store.get('discussion', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def update(self, value, data): print 'In discussion.update method' try: return self.__store.update('discussion', '_id', ObjectId(value), data) except: traceback.print_exc() return 'failed' def remove(self, value): print 'In discussion.remove method' try: return self.__store.remove('discussion', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def getAll(self): print 'In discussion.getAll method' try: return self.__store.getAll('discussion') except: traceback.print_exc() return 'failed'
def run(self): # hook up the sniffer self.sniffer = sniffer.Sniffer(self) # create object to manage database storage self.storage = Storage(self, cfg.NOW()) self.sniffer.run()
def viewAllPin(userId,boardName): print '--in moo.viewAllPins' couch = couchdb.Server() board = couch['boards'] myUserdb = couch['userdb'] global storage storage = Storage() bId = storage.getBoardId(boardName) if id in myUserdb: if bId in board: doc=storage.viewAllPins(id,bId) return doc else: return "Board Id not Found!" else: return "User Id Not Found!"
class Category(object): def __init__(self): print 'Category created' # create storage self.__store = Storage() def add(self, data): print 'In Category.add method' try: return self.__store.add('category', data) except: return 'failed' def get(self, value): print 'In Category.get method' try: return self.__store.get('category', '_id', ObjectId(value)) except: return 'failed' def update(self, value, data): print 'In Category.update method' try: return self.__store.update('category', '_id', ObjectId(value), data) except: return 'failed' def remove(self, value): print 'In Category.remove method' try: return self.__store.remove('category', '_id', ObjectId(value)) except: return 'failed' def getAll(self): print 'In Category.getAll method' try: return self.__store.getAll('category') except: return 'failed'
def createBoard(id): print '--in moo.createBoard' user_id = request.forms.get("id") print "id", user_id couch = couchdb.Server() mydb = couch['userdb'] #doc = mydb[user_id] if user_id in mydb: bname = request.POST.get('boardName') bdesc = request.POST.get('boardDesc') category = request.POST.get('category') boardType = request.POST.get('isPrivate') global storage storage = Storage() boardId = storage.insertBoard(user_id, bname, bdesc, category, boardType) return boardId else: return "User not Authorized!"
def updateBoard(userId,boardName): print '--in moo.createBoard' global storage storage = Storage() couch = couchdb.Server() mydb = couch['userdb'] myboardDB = couch['boards'] bId = storage.getBoardId(boardName) if userId in mydb: if bId in myboardDB: bname = request.POST.get('name') bdesc = request.POST.get('boardDesc') category = request.POST.get('category') boardType = request.POST.get('isPrivate') boardId = storage.updateBoard(userId,bId, bname, bdesc, category, boardType) return boardId else: return "Board not Authorized!" else: return "User not authorized"
def deleteBoard(id,boardName): print '--in moo.deleteBoard' user_id = request.forms.get("id") bName=request.forms.get("boardName") print "id", user_id print "boardName", bName couch = couchdb.Server() mydb = couch['userdb'] myboardDB = couch['boards'] #doc = mydb[user_id] if user_id in mydb: if bName in myboardDB: global storage storage = Storage() boardId = storage.deleteBoard(user_id,bName) else: return "Board not Authorized!" else: return "User not authorized"
def createPin(userId,boardName): print '--in moo.createBoard' print "id", userId couch = couchdb.Server() mydb = couch['userdb'] board = couch['boards'] global storage storage = Storage() bId = storage.getBoardId(boardName) if userId in mydb: if bId in board: pname=request.POST.get('pinName') pdesc = request.POST.get('pinDesc') image=request.POST.get('image') pinId = storage.insertPin(userId,boardName,pname,pdesc,image) return pinId else: return "Board not found!" else: return "User not Found!"
class Users(object): def __init__(self): print 'User created\n' # create storag self.__store = Storage() def addUser(self, data): print 'In User.add method' try: self.__store.add('user', data) return 'success' except: return 'failed' def getUser(self, value): print 'In User.get method' try: return self.__store.get('user', 'username', value) except: return 'failed' def getAll(self): print 'In Users.getAll method' try: return self.__store.getAll('user') except: return 'failed' def updateUser(self, value, data): print 'In User.update method' try: return self.__store.update('user', 'username', value, data) except: return 'failed' def updateUserOwnCourse(self, email, courseid): print 'In Course.updateUserOwnCourse method' try: return self.__store.addUserOwnCourse(email, courseid) except: traceback.print_exc() return 'failed' def removeUser(self, value): print 'In User.remove method' try: return self.__store.remove('user', 'email', value) except: return 'failed'
def deletePin(userId,boardName,pinId): print '--in moo.viewAllPins' global storage storage = Storage() bId = storage.getBoardId(boardName) couch = couchdb.Server() mydb = couch['userdb'] board = couch['boards'] pin = couch['pinsdb'] if userId in mydb: if bId in board: if pinId in pin: global storage storage = Storage() storage.deletePin(userId,bId,pinId) else: return "Pin not found!" else: return "Board not Found!" else: return "User Not Found!"
def viewPin(userId,boardName,pinId): print '--in moo.viewAllPins' couch = couchdb.Server() mydb = couch['userdb'] board = couch['boards'] pins = couch['pinsdb'] global storage storage = Storage() bId = storage.getBoardId(boardName) if userId in mydb: if bId in board: if pinId in pins: doc=storage.viewPin(userId,bId,pinId) return doc else: return "Pin not found!" else: return "Board not Found!" else: return "User Not Found!"
def __init__(self,base,conf_fn): self.host = socket.gethostname() self.base = base self.conf = {} # should emit a failure (file not found) message if os.path.exists(conf_fn): with open(conf_fn) as cf: for line in cf: name, var = line.partition("=")[::2] self.conf[name.strip()] = var.strip() else: raise Exception("configuration file not found.") # create storage self.__store = Storage()
def __init__(self): print 'Course created\n' # create storag self.__store = Storage()
class Course(object): def __init__(self): print 'Course created\n' # create storag self.__store = Storage() def add(self, email, data): print 'In Course.add method' try: courseid = self.__store.add('course', data) #Also update 'own' field of user collection self.__store.addUserOwnCourse(email, str(courseid)) return courseid except: traceback.print_exc() return 'failed' def get(self, value): print 'In Course.get method' try: return self.__store.get('course', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def update(self, value, data): print 'In Course.update method' try: return self.__store.update('course', '_id', ObjectId(value), data) except: traceback.print_exc() return 'failed' def remove(self, value): print 'In Course.remove method' try: return self.__store.remove('course', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def getAll(self): print 'In Course.getAll method' try: return self.__store.getAll('courseContent') except: traceback.print_exc() return 'failed' def enroll(self, email, courseid): print 'In Course.enroll method' try: return self.__store.enrollCourse(email, courseid) except: traceback.print_exc() return 'failed' def drop(self, email, courseid): print 'In Course.drop method' try: return self.__store.dropCourse(email, courseid) except: traceback.print_exc() return 'failed'
def __init__(self): print 'message created' # create storage self.__store = Storage()
def __init__(self): print 'Announcement created' # create storag self.__store = Storage()
def __init__(self): print 'Course created' # create storag self.__store = Storage()
def __init__(self): print 'quiz created' # create storage self.__store = Storage()
class Room(object): # very limited content negotiation support - our format choices # for output. This also shows _a way_ of representing enums in python json, xml, html, text = range(1,5) # # setup the configuration for our service # def __init__(self,base,conf_fn): self.host = socket.gethostname() self.base = base self.conf = {} # should emit a failure (file not found) message if os.path.exists(conf_fn): with open(conf_fn) as cf: for line in cf: name, var = line.partition("=")[::2] self.conf[name.strip()] = var.strip() else: raise Exception("configuration file not found.") # create storage self.__store = Storage() # # example: find data # def find(self,name): print '---> classroom.find:',name return self.__store.find(name) # # example: add data # def add(self,name,value): try: self.__store.insert(name,value) self.__store.names(); return 'success' except: return 'failed' # TODO success|failure # # dump the configuration in the requested format. Note placing format logic # in the functional code is not really a good idea. However, it is here to # provide an example. # # def dump_conf(self,format): if format == Room.json: return self.__conf_as_json() elif format == Room.html: return self.__conf_as_html() elif format == Room.xml: return self.__conf_as_xml() elif format == Room.text: return self.__conf_as_text() else: return self.__conf_as_text() # # output as xml is supported through other packages. If # you want to add xml support look at gnosis or lxml. # def __conf_as_json(self): return "xml is hard" # # # def __conf_as_json(self): try: all = {} all["base.dir"] = self.base all["conf"] = self.conf return json.dumps(all) except: return "error: unable to return configuration" # # # def __conf_as_text(self): try: sb = StringIO.StringIO() sb.write("Room Configuration\n") sb.write("base directory = ") sb.write(self.base) sb.write("\n\n") sb.write("configuration:\n") for key in sorted(self.conf.iterkeys()): print >>sb, "%s=%s" % (key, self.conf[key]) str = sb.getvalue() return str finally: sb.close() # return "text" # # # def __conf_as_html(self): try: sb = StringIO.StringIO() sb.write("<html><body>") sb.write("<h1>") sb.write("Room Configuration") sb.write("</h1>") sb.write("<h2>Base Directory</h2>\n") sb.write(self.base) sb.write("\n\n") sb.write("<h2>Configuration</h2>\n") sb.write("<pre>") for key in sorted(self.conf.iterkeys()): print >>sb, "%s=%s" % (key, self.conf[key]) sb.write("</pre>") sb.write("</body></html>") str = sb.getvalue() return str finally: sb.close()
def __init__(self): print 'discussion created' # create storage self.__store = Storage()
class Room(object): # very limited content negotiation support - our format choices # for output. This also shows _a way_ of representing enums in python json, xml, html, text = range(1, 5) # # setup the configuration for our service # def __init__(self, base, conf_fn): self.host = socket.gethostname() self.base = base self.conf = {} # should emit a failure (file not found) message if os.path.exists(conf_fn): with open(conf_fn) as cf: for line in cf: name, var = line.partition("=")[::2] self.conf[name.strip()] = var.strip() else: raise Exception("configuration file not found.") # create storage self.__store = Storage() # # example: find data # def find(self, name): print '---> classroom.find:', name return self.__store.find(name) # # example: add data # def add(self, name, value): try: self.__store.insert(name, value) self.__store.names() return 'success' except: return 'failed' # TODO success|failure # # dump the configuration in the requested format. Note placing format logic # in the functional code is not really a good idea. However, it is here to # provide an example. # # def dump_conf(self, format): if format == Room.json: return self.__conf_as_json() elif format == Room.html: return self.__conf_as_html() elif format == Room.xml: return self.__conf_as_xml() elif format == Room.text: return self.__conf_as_text() else: return self.__conf_as_text() # # output as xml is supported through other packages. If # you want to add xml support look at gnosis or lxml. # def __conf_as_json(self): return "xml is hard" # # # def __conf_as_json(self): try: all = {} all["base.dir"] = self.base all["conf"] = self.conf return json.dumps(all) except: return "error: unable to return configuration" # # # def __conf_as_text(self): try: sb = StringIO.StringIO() sb.write("Room Configuration\n") sb.write("base directory = ") sb.write(self.base) sb.write("\n\n") sb.write("configuration:\n") for key in sorted(self.conf.iterkeys()): print >> sb, "%s=%s" % (key, self.conf[key]) str = sb.getvalue() return str finally: sb.close() # return "text" # # # def __conf_as_html(self): try: sb = StringIO.StringIO() sb.write("<html><body>") sb.write("<h1>") sb.write("Room Configuration") sb.write("</h1>") sb.write("<h2>Base Directory</h2>\n") sb.write(self.base) sb.write("\n\n") sb.write("<h2>Configuration</h2>\n") sb.write("<pre>") for key in sorted(self.conf.iterkeys()): print >> sb, "%s=%s" % (key, self.conf[key]) sb.write("</pre>") sb.write("</body></html>") str = sb.getvalue() return str finally: sb.close()
def __init__(self): print 'User created\n' # create storag self.__store = Storage()
class Room(object): json, xml, html, text = range(1, 5) # # setup the configuration for our service # def __init__(self, base, conf_fn): self.host = socket.gethostname() self.base = base self.conf = {} # should emit a failure (file not found) message if os.path.exists(conf_fn): with open(conf_fn) as cf: for line in cf: name, var = line.partition("=")[::2] self.conf[name.strip()] = var.strip() else: raise Exception("configuration file not found.") # create storage self.__store = Storage() # # example: find data # def find(self, name): print '---> classroom.find:', name return self.__store.find(name) # # example: add data # def add(self, name, value): try: self.__store.insert(name, value) self.__store.names() return 'success' except: return 'failed' #----------------------------------------------------------------------------------------- # #--------registration data----------------Manushi Doshi # def addUser(self, name, username, password): print "In Classroom" try: self.__store.register(name, username, password) return "Registration successful" except: return 'error: Registration Failed' # #-----------login data-----------------Manushi Doshi # def login(self, username, password): try: doc_id = self.__store.login(username, password) return "Login Successful for " + doc_id except: return 'error: Login failed' # #-----------UserInfo data-----------------Dhrumit Sheth # def getUserInfo(self, user_id): try: return self.__store.getUserInfo(user_id) except: return "error: User Info retrieval failed" # #--------create board data-----------------Darshit Kuwadia # def addBoard(self, user_id, board_id, board_name): try: self.__store.addBoard(user_id, board_id, board_name) return "New Board Created" except: return 'error: Board creation failed' # #--------- add Pin data-----------------Rajvi Shah # def addPin(self, user_id, pin_name, pin_path): try: self.__store.addPin(user_id, pin_name, pin_path) return "Pin Created" except: return 'error: Pin Creation failed' # #------------ attach pin data-----------------Rajvi Shah # def attachPin(self, user_id, board_id, pin_id): try: self.__store.attachPin(user_id, board_id, pin_id) return 'Pin attached to the board' except: return 'error: Attachment failed' # #-------------- get all boards data-----------------Darshit Kuwadia # def getAllBoards(self): try: return self.__store.getAllBoards() except: print "error: Get All boards failed" # #-------------- get all Pins data-----------------Rajvi Shah # def getAllPins(self): try: return self.__store.getAllPins() except: print "error: Get All pins failed" # #-------------- get board by ID data-----------------Darshit Kuwadia # def getBoard(self, board_id): try: return self.__store.getBoard(board_id) except: print "error: GetBoard failed" # #-------------- get Pin by ID data----------------Kavish Parikh # def getPin(self, pin_id): try: return self.__store.getPin(pin_id) except: print "error: Get Pin failed" # #-------------- delete board data-----------------Dhrumit Sheth # def deleteBoard(self, user_Id, board_Id): try: return self.__store.deleteBoard(user_Id, board_Id) except: return 'error: Board deletion failed' # #-------------- addComment data-----------------Kavish Parikh # def addComment(self, user_id, pin_id, comment): try: return self.__store.addComment(user_id, pin_id, comment) except: print "error:Comment not added" def dump_conf(self, format): if format == Room.json: return self.__conf_as_json() elif format == Room.html: return self.__conf_as_html() elif format == Room.xml: return self.__conf_as_xml() elif format == Room.text: return self.__conf_as_text() else: return self.__conf_as_text() # # output as xml is supported through other packages. If # you want to add xml support look at gnosis or lxml. # def __conf_as_json(self): return "xml is hard" # # # def __conf_as_json(self): try: all = {} all["base.dir"] = self.base all["conf"] = self.conf return json.dumps(all) except: return "error: unable to return configuration" # # # def __conf_as_text(self): try: sb = StringIO.StringIO() sb.write("Room Configuration\n") sb.write("base directory = ") sb.write(self.base) sb.write("\n\n") sb.write("configuration:\n") for key in sorted(self.conf.iterkeys()): print >> sb, "%s=%s" % (key, self.conf[key]) str = sb.getvalue() return str finally: sb.close() # return "text" # # # def __conf_as_html(self): try: sb = StringIO.StringIO() sb.write("<html><body>") sb.write("<h1>") sb.write("Rooms Configuration") sb.write("</h1>") sb.write("<h2>Base Directory</h2>\n") sb.write(self.base) sb.write("\n\n") sb.write("<h2>Configuration</h2>\n") sb.write("<pre>") for key in sorted(self.conf.iterkeys()): print >> sb, "%s=%s" % (key, self.conf[key]) sb.write("</pre>") sb.write("</body></html>") str = sb.getvalue() return str finally: sb.close()
def setup(): global storageobj, sessionobj, recoObj storageobj = Storage() recoObj = RecoEngine() connection = Connection('localhost', 27017) sessionobj = Session(connection.doccdb)
def __init__(self): self.db = Storage().db
def __init__(self): print 'Category created' # create storage self.__store = Storage()
class Course(object): def __init__(self): print 'Course created' # create storag self.__store = Storage() def add(self, email, data): print 'In Course.add method' try: courseid = self.__store.add('course', data) #Also update 'own' field of user collection self.__store.addUserOwnCourse(email, str(courseid)) return courseid except: traceback.print_exc() return 'failed' def get(self, value): print 'In Course.get method' try: return self.__store.get('course', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def update(self, value, data): print 'In Course.update method' try: return self.__store.update('course', '_id', ObjectId(value), data) except: traceback.print_exc() return 'failed' def remove(self, value): print 'In Course.remove method' try: return self.__store.remove('course', '_id', ObjectId(value)) except: traceback.print_exc() return 'failed' def getAll(self): print 'In Course.getAll method' try: return self.__store.getAll('course') except: traceback.print_exc() return 'failed' def enroll(self, email, courseid): print 'In Course.enroll method' try: return self.__store.enrollCourse(email, courseid) except: traceback.print_exc() return 'failed' def drop(self, email, courseid): print 'In Course.drop method' try: return self.__store.dropCourse(email, courseid) except: traceback.print_exc() return 'failed'
def __init__(self): print 'User created' # create storag self.__store = Storage()
class Room(object): # very limited content negotiation support - our format choices # for output. This also shows _a way_ of representing enums in python json, xml, html, text = range(1,5) # # setup the configuration for our service # def __init__(self,base,conf_fn): self.host = socket.gethostname() self.base = base self.conf = {} # should emit a failure (file not found) message if os.path.exists(conf_fn): with open(conf_fn) as cf: for line in cf: name, var = line.partition("=")[::2] self.conf[name.strip()] = var.strip() else: raise Exception("configuration file not found.") # create storage self.__store = Storage() # # example: find data # def find(self,name): print '---> classroom.find:',name return self.__store.find(name) # # example: add data # def add(self,name,value): try: self.__store.insert(name,value) self.__store.names(); return 'success' except: return 'failed' def checkLogin(self,data): try: print("Inclassromm :::::::::::::"); self.__store.names(); return(self.__store.checkLogin(data)) except: return 'failed' #Sud start def userAdd(self,userJson): try: print("Inclassromm :::::::::::::"); self.__store.names(); return(self.__store.createUser(userJson)) except: return 'failed' def updateUser(self,userJson,email): try: print("Inclassromm of update user:::::::::::::"); self.__store.names(); return(self.__store.updateUser(userJson,email)) except: return 'failed' def updateEnrolled(self,enrolledCourseData): try: return(self.__store.updateEnrolled(enrolledCourseData)) except: return 'failed' def ownedCourselist(self,email): try: return(self.__store.ownedCourselist(email)) except: return 'failed' def deleteCourse(self,courseJson,cid): try: return(self.__store.deleteCourse(courseJson,cid)) except: return 'failed' def deleteOwnedCourse(self,courseJson,cid): try: return(self.__store.deleteOwnedCourse(courseJson,cid)) except: return 'failed' def deleteEnrolledCourse(self,courseJson,cid): try: return(self.__store.deleteEnrolledCourse(courseJson,cid)) except: return 'failed' def dropEnrolled(self,droppedCourseData): try: return(self.__store.dropEnrolled(droppedCourseData)) except: return 'failed' def updateCourse(self,courseJson,cid): try: print("entered class room of updaate course :::::::::::::::"); return(self.__store.updateCourse(courseJson,cid)) except: return 'failed' def updateOwned(self,email,ownedCourse): try: print("Inclassromm of update enrolled:::::::::::::"); self.__store.names(); return(self.__store.updateOwned(email,ownedCourse)) except: return 'failed' def updateQuiz(self,email,ownedQuiz): try: print("Inclassromm of update enrolled:::::::::::::"); self.__store.names(); return(self.__store.updateQuiz(email,ownedQuiz)) except: return 'failed' def announcementcollectionAdd(self,userJson): try: print("Inclassromm :::::::::::::"); self.__store.names(); return(self.__store.createannouncementcollection(userJson)) except: return 'failed' def discussioncollectionAdd(self,userJson): try: print("Inclassromm :::::::::::::"); self.__store.names(); return(self.__store.creatediscussioncollection(userJson)) except: return 'failed' def getdis(self,cid): try: return(self.__store.getdis(cid)) except: return 'failed' def creatediscussionlist(self): try: print("Inclassromm :::::::::::::"); print "inside classroommmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" self.__store.names(); return(self.__store.creatediscussionlist()) except: return 'failed' def createannouncementlist(self): try: self.__store.names(); return(self.__store.createannouncementlist()) except: return 'failed' def getann(self,cid): try: return(self.__store.getann(cid)) except: return 'failed' def getUser(self,email): try: print("Inclassromm :::::::::::::"); self.__store.names(); return(self.__store.getUser(email)) except: return 'failed' def courseAdd(self,courseJson): try: return(self.__store.createCourse(courseJson)) except: return 'failed' def courselist(self): try: print("Inclassromm :::::::::::::"); self.__store.names(); return(self.__store.courselist()) except: return 'failed' def getCourse(self,cid): try: return(self.__store.getCourse(cid)) except: return 'failed' def listCategory(self): try: print("Inclassromm :::::::::::::"); self.__store.names(); return(self.__store.listCategory()) except: return 'failed' def getCategory(self,cid): try: print("Inclassromm :::::::::::::"); self.__store.names(); return(self.__store.getCategory(cid)) except: return 'failed' def createCatagory(self,userJson): try: print("Inclassromm :::::::::::::"); self.__store.names(); return(self.__store.createCatagory(userJson)) except: return 'failed' def enrolledCourselist(self,email): try: return(self.__store.enrolledCourselist(email)) except: return 'failed' #Sud ends # TODO success|failure # # dump the configuration in the requested format. Note placing format logic # in the functional code is not really a good idea. However, it is here to # provide an example. # # def dump_conf(self,format): if format == Room.json: return self.__conf_as_json() elif format == Room.html: return self.__conf_as_html() elif format == Room.xml: return self.__conf_as_xml() elif format == Room.text: return self.__conf_as_text() else: return self.__conf_as_text() # # output as xml is supported through other packages. If # you want to add xml support look at gnosis or lxml. # def __conf_as_json(self): return "xml is hard" # # # def __conf_as_json(self): try: all = {} all["base.dir"] = self.base all["conf"] = self.conf return json.dumps(all) except: return "error: unable to return configuration" # # # def __conf_as_text(self): try: sb = StringIO.StringIO() sb.write("Room Configuration\n") sb.write("base directory = ") sb.write(self.base) sb.write("\n\n") sb.write("configuration:\n") for key in sorted(self.conf.iterkeys()): print >>sb, "%s=%s" % (key, self.conf[key]) str = sb.getvalue() return str finally: sb.close() # return "text" # # # def __conf_as_html(self): try: sb = StringIO.StringIO() sb.write("<html><body>") sb.write("<h1>") sb.write("Room Configuration") sb.write("</h1>") sb.write("<h2>Base Directory</h2>\n") sb.write(self.base) sb.write("\n\n") sb.write("<h2>Configuration</h2>\n") sb.write("<pre>") for key in sorted(self.conf.iterkeys()): print >>sb, "%s=%s" % (key, self.conf[key]) sb.write("</pre>") sb.write("</body></html>") str = sb.getvalue() return str finally: sb.close()
# # start the server # import sys from bottle import run from moo import setup from data.storage import Storage if len(sys.argv) > 2: base = sys.argv[1] conf_fn = sys.argv[2] setup(base,conf_fn) db=Storage() db.start_server() run(host='localhost', port=8000) else: print "usage:", sys.argv[0],"[base_dir] [conf file]"
import json import os import time import socket from data.storage import Storage from data.models import User, Board, Pin # bottle framework from bottle import request, response, route, error, static_file # moo from classroom import Room # virtual classroom implementation room = None # Global Database variable global db db = Storage() # def setup(base, conf_fn): print '\n**** service initialization ****\n' global room room = Room(base, conf_fn) @error(404) def error404(error): """ This method returns 'Nothing here, sorry' when there is any error in the URL """ return 'Nothing here, sorry'
def __init__(self): print 'Professor created\n' # create storag self.__store = Storage()