def buildfilepath(appid, breadid=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); assert config['app_conf']['permanent_store']; filepath = os.path.join(config['app_conf']['permanent_store'], buildfilename(appid, breadid)); return filepath;
def index(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); h.logm("INF",5,"params "+ str(request.params)); self.buildInformation(); return render('/admingroup.mako');
def groupDelete(self, id=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method != 'DELETE': h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/group action does only allow DELETE request method"); if not id: h.logm("ERR",5,"EXCEPTION, parameter missing" + request.method); return self.jsonErrorResponse(407, "adm/group/id, missing parameter id"); groupid = str(id); h.logm("DBG",5,"request w/ groupid=" + groupid); db = self._py_object.app_globals.db; group = None; try: group = db.groups.find_one({'_id': ObjectId(groupid)}); except: return self.jsonErrorResponse(404, "Invalid Mongo DB Group Id {'_id' : " + groupid + '}'); else: if not group: return self.jsonErrorResponse(404, "Invalid group id " + groupid); h.logm("INF",5,"found group: " + str(group)); db.groups.remove({'_id': ObjectId(groupid)}); responseDict = { "oid" : str(group['_id']) }; return self.jsonResponse(responseDict);
def index(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) h.logm("INF", 5, "params " + str(request.params)) self.buildInformation() return render('/admingroup.mako')
def removeUser(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) h.logm("DBG", 5, "params " + str(request.params)) db = self._py_object.app_globals.db userid = 0 for (k, v) in request.params.iteritems(): if v == '-': userid = k break db.groups.update({}, {"$pull": { "users": (ObjectId(userid)) }}) user = db.users.find_one({'_id': ObjectId(userid)}) db.users.remove({'_id': ObjectId(userid)}) session[ 'message_admingroup'] = 'Congratulations: REMOVED user [' + user[ 'name'] + ']!' session.save() self.buildInformation() return render('/admingroup.mako')
def userDelete(self, id=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method != 'DELETE': h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/user action does only allow DELETE request method"); if not id: h.logm("ERR",5,"EXCEPTION, parameter missing" + request.method); return self.jsonErrorResponse(407, "adm/user/id, missing parameter id"); userid = str(id); h.logm("DBG",5,"request w/ userid=" + userid); db = self._py_object.app_globals.db; user = None; try: user = db.users.find_one({'_id': ObjectId(userid)}); except: return self.jsonErrorResponse(404, "Invalid Mongo DB User Id {'_id' : " + userid + '}'); else: if not user: return self.jsonErrorResponse(404, "Invalid user id " + userid); h.logm("INF",5,"found user: "******"$pull" : {"users" : (ObjectId(userid))}}); db.users.remove({'_id': ObjectId(userid)}); responseDict = { "oid" : str(user['_id']) }; return self.jsonResponse(responseDict);
def getIconFileIOS4(dirApp, zfile, path, plist): h.logm("DBG", 5, "ACTION " + h.getcalled()) if not 'CFCommodityIconFiles' in plist: h.logm("ERR", 5, "no CFCommodityIconFiles in plist") return None commodityIconFiles = plist['CFCommodityIconFiles'] for commodityIconName in commodityIconFiles: iconapp = dirApp + commodityIconName if iconapp in zfile.namelist(): zfile.extract(iconapp, path=path) commodityIconFile = os.path.join(path, dirApp, commodityIconName) if os.path.exists(commodityIconFile): break else: h.logm( "ERR", 5, "commodityIconFile " + commodityIconFile + " does not exist in BREAD") commodityIconFile = None if not commodityIconFile: h.logm("ERR", 5, "commodityIconFile does not exist in BREAD") else: h.logm("INF", 5, "commodityIconFile in BREAD!, using " + commodityIconFile) return commodityIconFile
def createdir(groupid): h.logm("DBG",5,"ACTION "+ h.getcalled()); assert config['app_conf']['permanent_store']; dirpath = os.path.join(config['app_conf']['permanent_store'], groupid); if not os.path.exists(filepath): os.mkdir(dirpath); return dirpath;
def getIconFileIOS4(dirApp, zfile, path, plist): h.logm("DBG",5,"ACTION "+ h.getcalled()); if not 'CFCommodityIconFiles' in plist: h.logm("ERR",5,"no CFCommodityIconFiles in plist"); return None; commodityIconFiles = plist['CFCommodityIconFiles']; for commodityIconName in commodityIconFiles: iconapp = dirApp + commodityIconName if iconapp in zfile.namelist(): zfile.extract(iconapp, path=path); commodityIconFile = os.path.join(path, dirApp, commodityIconName); if os.path.exists(commodityIconFile): break; else: h.logm("ERR",5,"commodityIconFile "+ commodityIconFile + " does not exist in BREAD"); commodityIconFile = None; if not commodityIconFile: h.logm("ERR",5,"commodityIconFile does not exist in BREAD"); else: h.logm("INF",5,"commodityIconFile in BREAD!, using " + commodityIconFile); return commodityIconFile;
def groupApplication(self, id, id2): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method == 'POST': return self.groupAddApplication(id,id2); elif request.method == 'DELETE': return self.groupDeleteApplication(id,id2); else: return self.jsonErrorResponse(500, "adm/groupApplication/{id}/{id2} action only allows POST/DELETE request method. Request: " + request.method);
def application(self, id=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method == 'GET': return self.applicationGet(id); elif request.method == 'DELETE': return self.applicationDelete(id); else: h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/application action only allows GET/DELETE request method");
def buildfilename(appid, breadid=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); if breadid: filename = appid + "_" + breadid; else: filename = appid; return filename;
def index(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); db = self._py_object.app_globals.db; c.users = db.users.find(); c.message = ''; c.email = ''; c.logged = True; return render('/signup.mako')
def getfilepath(appid, breadid=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); filepath = buildfilepath(appid, breadid); if not os.path.exists(filepath): h.logm("DBG",5, 'file ' + filepath + ' does not exist'); return None; return filepath;
def getfileUsingResponse(appid, breadid, response): h.logm("DBG",5,"ACTION "+ h.getcalled()); filename = getfilepath(appid, breadid); with open(filename, 'rb') as fileptr: shutil.copyfileobj(fileptr, response) h.logm("INF",5, 'filename %s' % filename); fileptr.close()
def index(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) db = self._py_object.app_globals.db c.users = db.users.find() c.message = '' c.email = '' c.logged = True return render('/signup.mako')
def groupApplication(self, id, id2): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method == 'POST': return self.groupAddApplication(id, id2) elif request.method == 'DELETE': return self.groupDeleteApplication(id, id2) else: return self.jsonErrorResponse( 500, "adm/groupApplication/{id}/{id2} action only allows POST/DELETE request method. Request: " + request.method)
def group(self, id=None, action2=None, id2=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method == 'POST': return self.groupPost(); elif request.method == 'PUT': return self.groupPut(id); elif request.method == 'DELETE': return self.groupDelete(id); else: h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/group action does only allow POST/PUT/DELETE request methods");
def application(self, id=None): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method == 'GET': return self.applicationGet(id) elif request.method == 'DELETE': return self.applicationDelete(id) else: h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/application action only allows GET/DELETE request method")
def users(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method != 'GET': h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/users does only allow GET request method"); db = self._py_object.app_globals.db; users = db.users.find(); responseArray = []; for user in users: responseArray.append(User(user).encode()); return self.jsonResponse(responseArray);
def createfile(filepointer, appid, breadid = None): h.logm("DBG",5,"ACTION "+ h.getcalled()); filepath = buildfilepath(appid, breadid); h.logm("DBG",5,"filepath "+ filepath); permanent_file = open(filepath, 'wb'); filepointer.file.seek(0); shutil.copyfileobj(filepointer.file, permanent_file); filepointer.file.close(); permanent_file.close(); return (filepath, os.path.getsize(filepath));
def applications(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method != 'GET': h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/applications does only allow GET request method"); db = self._py_object.app_globals.db; applications = db.applications.find(); responseArray = []; for application in applications: responseArray.append(Application(application).encodeWithBreadEntries()); return self.jsonResponse(responseArray);
def createGroup(self): db = self._py_object.app_globals.db schema = Validator.CreateGroupValidator() try: form_result = schema.to_python(request.params) h.logm("DBG", 5, "f r " + str(request.params)) except formencode.Invalid, error: h.logm("ERR", 5, "f r " + str(request.params)) c.message = h.literal(htmlfill.escapenl_formatter(error)) session['message'] = c.message session.save()
def createGroup(self): db = self._py_object.app_globals.db; schema = Validator.CreateGroupValidator(); try: form_result = schema.to_python(request.params); h.logm("DBG",5,"f r "+ str(request.params)); except formencode.Invalid, error: h.logm("ERR",5,"f r "+ str(request.params)); c.message = h.literal(htmlfill.escapenl_formatter(error)); session['message'] = c.message; session.save();
def groups(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method != 'GET': h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/groups does only allow GET request method"); db = self._py_object.app_globals.db; groups = db.groups.find(); responseArray = []; for group in groups: responseArray.append(Group(group).encode()); return self.jsonResponse(responseArray);
def removeGroup(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) params = request.params h.logm("DBG", 5, "params " + str(params)) schema = Validator.FormRemoveGroupValidator() try: form_result = schema.to_python(request.params) except formencode.Invalid, error: c.message = h.literal(htmlfill.escapenl_formatter(error)) session['message'] = c.message session.save()
def removeGroup(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); params = request.params; h.logm("DBG",5,"params "+ str(params)); schema = Validator.FormRemoveGroupValidator(); try: form_result = schema.to_python(request.params); except formencode.Invalid, error: c.message = h.literal(htmlfill.escapenl_formatter(error)); session['message'] = c.message; session.save();
def users(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method != 'GET': h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/users does only allow GET request method") db = self._py_object.app_globals.db users = db.users.find() responseArray = [] for user in users: responseArray.append(User(user).encode()) return self.jsonResponse(responseArray)
def groups(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method != 'GET': h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/groups does only allow GET request method") db = self._py_object.app_globals.db groups = db.groups.find() responseArray = [] for group in groups: responseArray.append(Group(group).encode()) return self.jsonResponse(responseArray)
def group(self, id=None, action2=None, id2=None): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method == 'POST': return self.groupPost() elif request.method == 'PUT': return self.groupPut(id) elif request.method == 'DELETE': return self.groupDelete(id) else: h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/group action does only allow POST/PUT/DELETE request methods" )
def applications(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method != 'GET': h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/applications does only allow GET request method") db = self._py_object.app_globals.db applications = db.applications.find() responseArray = [] for application in applications: responseArray.append( Application(application).encodeWithBreadEntries()) return self.jsonResponse(responseArray)
def applicationDelete(self, id=None): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method != 'DELETE': h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/application action does only allow DELETE request method") if not id: h.logm("ERR", 5, "EXCEPTION, parameter missing" + request.method) return self.jsonErrorResponse( 407, "adm/application/id, missing parameter id") applicationid = str(id) h.logm("DBG", 5, "request w/ applicationid=" + applicationid) db = self._py_object.app_globals.db application = None try: application = db.applications.find_one( {'_id': ObjectId(applicationid)}) except: return self.jsonErrorResponse( 404, "Invalid Mongo DB Application Id {'_id' : " + applicationid + '}') else: if not application: return self.jsonErrorResponse( 404, "Invalid application id " + applicationid) h.logm("INF", 5, "found application: " + str(application)) if 'breadEntries' in application: for breadEntry in application['breadEntries']: sfh.deletebread(str(applicationid), str(breadEntry['id'])) db.groups.update( {}, {"$pull": { "applications": (ObjectId(applicationid)) }}) db.applications.remove({'_id': ObjectId(applicationid)}) responseDict = { "oid": str(application['_id']) } return self.jsonResponse(responseDict)
def addUserToGroup(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) schema = Validator.FormAddUserValidator() try: form_result = schema.to_python(request.params) h.logm("DBG", 5, "f r " + str(request.params)) h.logm("DBG", 5, "TRY") except formencode.Invalid, error: h.logm("DBG", 5, "EXCEPT") h.logm("ERR", 5, "f r " + str(request.params)) c.message = h.literal(htmlfill.escapenl_formatter(error)) session['message'] = c.message session.save()
def addUserToGroup(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); schema = Validator.FormAddUserValidator(); try: form_result = schema.to_python(request.params); h.logm("DBG",5,"f r "+ str(request.params)); h.logm("DBG",5,"TRY"); except formencode.Invalid, error: h.logm("DBG",5,"EXCEPT"); h.logm("ERR",5,"f r "+ str(request.params)); c.message = h.literal(htmlfill.escapenl_formatter(error)); session['message'] = c.message; session.save();
def createfilename(filename, appid, breadid = None): h.logm("DBG",5,"ACTION "+ h.getcalled()); filepath = buildfilepath(appid, breadid); size = os.path.getsize(filename) permanent_file = open(filepath, 'wb'); fileptr = open(filename, 'rb'); if not fileptr: h.logm("DBG",5, 'cannot read file'); return None; shutil.copyfileobj(fileptr, permanent_file); fileptr.close() permanent_file.close() return (filepath, size);
def getIconFile(dirApp, zfile, path, plist): h.logm("DBG",5,"ACTION "+ h.getcalled()); iconFile = getIconFileIOS4(dirApp, zfile, path, plist); if iconFile: return iconFile; iconFile = getIconFileIOS3(dirApp, zfile, path, plist); if iconFile: return iconFile; iconFile = getIconFileIOS5(dirApp, zfile, path, plist); if iconFile: return iconFile; h.logm("ERR",5,"no IconFile in bread"); return None;
def getIconFile(dirApp, zfile, path, plist): h.logm("DBG", 5, "ACTION " + h.getcalled()) iconFile = getIconFileIOS4(dirApp, zfile, path, plist) if iconFile: return iconFile iconFile = getIconFileIOS3(dirApp, zfile, path, plist) if iconFile: return iconFile iconFile = getIconFileIOS5(dirApp, zfile, path, plist) if iconFile: return iconFile h.logm("ERR", 5, "no IconFile in bread") return None
def getIconFileIOS5(dirApp, zfile, path, plist): h.logm("DBG", 5, "ACTION " + h.getcalled()) if not 'CFCommodityIcons' in plist: h.logm("ERR", 5, "no CFCommodityIcons in plist") return None commodityIconFileDict = plist['CFCommodityIcons'] if 'CFCommodityPrimaryIcon' in commodityIconFileDict: commodityIconName = commodityIconFileDict['CFCommodityPrimaryIcon'] iconapp = dirApp + commodityIconName if iconapp in zfile.namelist(): zfile.extract(iconapp, path=path) commodityIconFile = os.path.join(path, dirApp, commodityIconName) if os.path.exists(commodityIconFile): return commodityIconFile else: commodityIconFile = None else: h.logm("ERR", 5, "no CFCommodityPrimaryIcon in plist") if 'UINewsstandIcon' in commodityIconFileDict: commodityIconName = commodityIconFileDict['UINewsstandIcon'] iconapp = dirApp + commodityIconName if iconapp in zfile.namelist(): zfile.extract(iconapp, path=path) commodityIconFile = os.path.join(path, commodityIconName) if os.path.exists(commodityIconFile): return commodityIconFile else: commodityIconFile = None else: h.logm("ERR", 5, "no UINewsstandIcon in plist") if not commodityIconFile: h.logm( "ERR", 5, "commodityIconFile (IOS5)" + commodityIconFile + " does not exist in BREAD") return None
def getIconFileIOS5(dirApp, zfile, path, plist): h.logm("DBG",5,"ACTION "+ h.getcalled()); if not 'CFCommodityIcons' in plist: h.logm("ERR",5,"no CFCommodityIcons in plist"); return None; commodityIconFileDict = plist['CFCommodityIcons']; if 'CFCommodityPrimaryIcon' in commodityIconFileDict: commodityIconName = commodityIconFileDict['CFCommodityPrimaryIcon'] iconapp = dirApp + commodityIconName if iconapp in zfile.namelist(): zfile.extract(iconapp, path=path); commodityIconFile = os.path.join(path, dirApp, commodityIconName); if os.path.exists(commodityIconFile): return commodityIconFile; else: commodityIconFile = None; else: h.logm("ERR",5,"no CFCommodityPrimaryIcon in plist"); if 'UINewsstandIcon' in commodityIconFileDict: commodityIconName = commodityIconFileDict['UINewsstandIcon'] iconapp = dirApp + commodityIconName if iconapp in zfile.namelist(): zfile.extract(iconapp, path=path); commodityIconFile = os.path.join(path, commodityIconName); if os.path.exists(commodityIconFile): return commodityIconFile; else: commodityIconFile = None; else: h.logm("ERR",5,"no UINewsstandIcon in plist"); if not commodityIconFile: h.logm("ERR",5,"commodityIconFile (IOS5)"+ commodityIconFile + " does not exist in BREAD"); return None;
def getIconFileIOS3(dirApp, zfile, path, plist): h.logm("DBG",5,"ACTION "+ h.getcalled()); if not 'CFCommodityIconFile' in plist: return None; commodityIconName = plist['CFCommodityIconFile']; iconapp = dirApp + commodityIconName if iconapp in zfile.namelist(): zfile.extract(iconapp, path=path); commodityIconFile = os.path.join(path, dirApp, commodityIconName); if os.path.exists(commodityIconFile): return commodityIconFile; h.logm("ERR",5,"commodityIconFile (IOS3)"+ commodityIconFile + " does not exist in BREAD"); return None;
def getIconFileIOS3(dirApp, zfile, path, plist): h.logm("DBG", 5, "ACTION " + h.getcalled()) if not 'CFCommodityIconFile' in plist: return None commodityIconName = plist['CFCommodityIconFile'] iconapp = dirApp + commodityIconName if iconapp in zfile.namelist(): zfile.extract(iconapp, path=path) commodityIconFile = os.path.join(path, dirApp, commodityIconName) if os.path.exists(commodityIconFile): return commodityIconFile h.logm( "ERR", 5, "commodityIconFile (IOS3)" + commodityIconFile + " does not exist in BREAD") return None
def applicationGet(self, id=None): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method != 'GET': h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/applications does only allow GET request method") if not id: h.logm("ERR", 5, "EXCEPTION, parameter missing" + request.method) return self.jsonErrorResponse( 407, "adm/application/id missing parameter id") applicationid = str(id) db = self._py_object.app_globals.db try: application = db.applications.find_one( {'_id': ObjectId(applicationid)}) except: return self.jsonErrorResponse( 404, "Invalid Mongo DB Application Id {'_id' : " + applicationid + '}') else: if not application: return self.jsonErrorResponse( 404, "Invalid application id " + applicationid) return self.jsonResponse( Application(application).encodeWithBreadEntries())
def userDelete(self, id=None): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method != 'DELETE': h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/user action does only allow DELETE request method") if not id: h.logm("ERR", 5, "EXCEPTION, parameter missing" + request.method) return self.jsonErrorResponse(407, "adm/user/id, missing parameter id") userid = str(id) h.logm("DBG", 5, "request w/ userid=" + userid) db = self._py_object.app_globals.db user = None try: user = db.users.find_one({'_id': ObjectId(userid)}) except: return self.jsonErrorResponse( 404, "Invalid Mongo DB User Id {'_id' : " + userid + '}') else: if not user: return self.jsonErrorResponse(404, "Invalid user id " + userid) h.logm("INF", 5, "found user: "******"$pull": { "users": (ObjectId(userid)) }}) db.users.remove({'_id': ObjectId(userid)}) responseDict = { "oid": str(user['_id']) } return self.jsonResponse(responseDict)
def groupDelete(self, id=None): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method != 'DELETE': h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/group action does only allow DELETE request method") if not id: h.logm("ERR", 5, "EXCEPTION, parameter missing" + request.method) return self.jsonErrorResponse( 407, "adm/group/id, missing parameter id") groupid = str(id) h.logm("DBG", 5, "request w/ groupid=" + groupid) db = self._py_object.app_globals.db group = None try: group = db.groups.find_one({'_id': ObjectId(groupid)}) except: return self.jsonErrorResponse( 404, "Invalid Mongo DB Group Id {'_id' : " + groupid + '}') else: if not group: return self.jsonErrorResponse(404, "Invalid group id " + groupid) h.logm("INF", 5, "found group: " + str(group)) db.groups.remove({'_id': ObjectId(groupid)}) responseDict = { "oid": str(group['_id']) } return self.jsonResponse(responseDict)
def applicationDelete(self, id=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method != 'DELETE': h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/application action does only allow DELETE request method"); if not id: h.logm("ERR",5,"EXCEPTION, parameter missing" + request.method); return self.jsonErrorResponse(407, "adm/application/id, missing parameter id"); applicationid = str(id); h.logm("DBG",5,"request w/ applicationid=" + applicationid); db = self._py_object.app_globals.db; application = None; try: application = db.applications.find_one({'_id': ObjectId(applicationid)}); except: return self.jsonErrorResponse(404, "Invalid Mongo DB Application Id {'_id' : " + applicationid + '}'); else: if not application: return self.jsonErrorResponse(404, "Invalid application id " + applicationid); h.logm("INF",5,"found application: " + str(application)); if 'breadEntries' in application: for breadEntry in application['breadEntries']: sfh.deletebread(str(applicationid), str(breadEntry['id'])); db.groups.update({}, {"$pull" : {"applications" : (ObjectId(applicationid))}}); db.applications.remove({'_id': ObjectId(applicationid)}); responseDict = { "oid" : str(application['_id']) }; return self.jsonResponse(responseDict);
def removeUser(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); h.logm("DBG",5,"params "+ str(request.params)); db = self._py_object.app_globals.db; userid = 0; for (k, v) in request.params.iteritems(): if v == '-': userid = k; break; db.groups.update({}, {"$pull" : {"users" : (ObjectId(userid))}}); user = db.users.find_one({'_id': ObjectId(userid)}); db.users.remove({'_id': ObjectId(userid)}); session['message_admingroup'] = 'Congratulations: REMOVED user [' + user['name'] + ']!'; session.save(); self.buildInformation(); return render('/admingroup.mako');
def getfile_(appid, breadid=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); filename = getfilepath(appid, breadid); h.logm("INF",5, 'filename %s' % filename); headers = [('Content-Disposition', 'attachment; filename=\"' + filename + '\"'), ('Content-Type', 'application/octet-stream'), ('Content-Length', str(os.path.getsize(filename)))]; h.logm("INF",5, 'headers ' + str(headers)); # return FileApp(filename, headers=headers); return FileApp(filename, headers=headers)
def submit(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) db = self._py_object.app_globals.db c.users = db.users.find() c.email = '' c.logged = True c.message = '' schema = SignupValidator() try: form_result = schema.to_python(request.params) h.logm("DBG", 5, "f r " + str(request.params)) except formencode.Invalid, error: h.logm("ERR", 5, "f r " + str(request.params)) c.message = h.literal(htmlfill.escapenl_formatter(error)) return render('/signup.mako')
def getfile(appid, breadid=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); filename = getfilepath(appid, breadid); content_type = mimetypes.guess_type(filename); fileptr = open(filename, 'rb'); if not fileptr: h.logm("DBG",5, 'cannot read file'); return None; data = fileptr.read() h.logm("INF",5, 'filename %s data len %d' % (filename, len(data))); fileptr.close() return data;
def submit(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); db = self._py_object.app_globals.db; c.users = db.users.find(); c.email = ''; c.logged = True; c.message = ''; schema = SignupValidator(); try: form_result = schema.to_python(request.params); h.logm("DBG",5,"f r "+ str(request.params)); except formencode.Invalid, error: h.logm("ERR",5,"f r "+ str(request.params)); c.message = h.literal(htmlfill.escapenl_formatter(error)); return render('/signup.mako');
def applicationGet(self, id=None): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method != 'GET': h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/applications does only allow GET request method"); if not id: h.logm("ERR",5,"EXCEPTION, parameter missing" + request.method); return self.jsonErrorResponse(407, "adm/application/id missing parameter id"); applicationid = str(id); db = self._py_object.app_globals.db; try: application = db.applications.find_one({'_id': ObjectId(applicationid)}); except: return self.jsonErrorResponse(404, "Invalid Mongo DB Application Id {'_id' : " + applicationid + '}'); else: if not application: return self.jsonErrorResponse(404, "Invalid application id " + applicationid); return self.jsonResponse(Application(application).encodeWithBreadEntries());