def index(): data = db.getAll(cur) produtoList = map_produto(data) return jsonify(produtoList)
def ShowAllTasks(id, subject_name): try: showAllTasks = db.getAll(id, subject_name) return(showAllTasks) except Exception as error: print(error) raise AppExceptions.Cant_Get_Subject("AppExceptions.Cant_Get_Subject")
def do_GET(self): # Look for main page if self.path == "/": self.path = "/index.html" if self.path == "/products": #send response code: self.send_response(200) #send headers: self.send_header("Content-type:", "application/json") # send a blank line to end headers: self.wfile.write("\n") #send response: json.dump(db.getAll(), self.wfile) if re.match(r'\/product\/\d+', self.path): # match "/product/{ID}" #send response code: self.send_response(200) #send headers: self.send_header("Content-type:", "application/json") # send a blank line to end headers: self.wfile.write("\n") #send response: json.dump( db.getOne(re.search(r'[^/]*$', self.path).group(0)), self.wfile) # regex to get everything after the last slash try: #Check the file extension required and #set the right mime type sendReply = False if self.path.endswith(".html"): mimetype = 'text/html' sendReply = True if self.path.endswith(".woff"): mimetype = 'font/opentype' sendReply = True if self.path.endswith(".ttf"): mimetype = 'font/opentype' sendReply = True if self.path.endswith(".js"): mimetype = 'application/javascript' sendReply = True if self.path.endswith(".css"): mimetype = 'text/css' sendReply = True if sendReply == True: #Open the static file requested and send it f = open(curdir + sep + self.path) self.send_response(200) self.send_header('Content-type', mimetype) self.end_headers() self.wfile.write(f.read()) f.close() return except IOError: self.send_error(404, 'File Not Found: %s' % self.path)
def do_GET(self) : # Look for main page if self.path=="/": self.path="/index.html" if self.path == "/products" : #send response code: self.send_response(200) #send headers: self.send_header("Content-type:", "application/json") # send a blank line to end headers: self.wfile.write("\n") #send response: json.dump(db.getAll(), self.wfile) if re.match(r'\/product\/\d+', self.path): # match "/product/{ID}" #send response code: self.send_response(200) #send headers: self.send_header("Content-type:", "application/json") # send a blank line to end headers: self.wfile.write("\n") #send response: json.dump(db.getOne(re.search(r'[^/]*$', self.path).group(0)), self.wfile) # regex to get everything after the last slash try: #Check the file extension required and #set the right mime type sendReply = False if self.path.endswith(".html"): mimetype='text/html' sendReply = True if self.path.endswith(".woff"): mimetype='font/opentype' sendReply = True if self.path.endswith(".ttf"): mimetype='font/opentype' sendReply = True if self.path.endswith(".js"): mimetype='application/javascript' sendReply = True if self.path.endswith(".css"): mimetype='text/css' sendReply = True if sendReply == True: #Open the static file requested and send it f = open(curdir + sep + self.path) self.send_response(200) self.send_header('Content-type',mimetype) self.end_headers() self.wfile.write(f.read()) f.close() return except IOError: self.send_error(404,'File Not Found: %s' % self.path)
def deleteProduto(id): cur = conn.cursor() if db.delete(id, cur): db.applyCommit(conn) return jsonify(db.getAll(cur)) return jsonify({"message": "Nenhum dado foi excluido"})
def GET(self): """ Get DB as JSON """ if not CheckAuth(web.ctx.env.get('HTTP_AUTHORIZATION')): raise web.seeother('/login') return allPods = db.getAll() jsonDecoded = [] for items in allPods: jsonDecoded.append(list(items)) jsonDecoded[-1][2] = json.loads(items[2]) allPodsJSON = json.dumps(jsonDecoded) return allPodsJSON
def GET(self): """ Get DB as JSON """ if not CheckAuth(web.ctx.env.get('HTTP_AUTHORIZATION')): raise web.seeother('/login') return allPods=db.getAll() jsonDecoded = [] for items in allPods: jsonDecoded.append(list(items)) jsonDecoded[-1][2] = json.loads(items[2]) allPodsJSON=json.dumps(jsonDecoded) return allPodsJSON
def test_saveAndRetrieve(): conn = db.connect(":memory:") with conn: # test saving of galleries for testCase in testCases: db.saveGallery(conn, testCase.get("url"), testCase.get("totalImages")) # test retrieval for (testCase, record) in zip(testCases, db.getAll(conn)): assert testCase.get("url") == record[1] assert testCase.get("totalImages") == record[2]
def postProduto(): dados = request.get_json(force=True) if dados['descricao'] != '': cur = conn.cursor() if db.create(dados, cur): db.applyCommit(conn) return jsonify(db.getAll(cur)), 201 #end if #end if return jsonify({"message": "Erro. Operação inválida."})
def GET(self): """ Get DB as JSON """ if not CheckAuth(web.ctx.env.get('HTTP_AUTHORIZATION')): raise web.seeother('/login') return allPods=db.getAll() allPodsJSON=DB_JSON_TOP for pod in allPods: allPodsJSON+='["'+str(pod[0])+'", "'+str(pod[1])+'", "'+str(pod[2])+'", "'+str(pod[3]) +'"],' if len(allPods) >= 1: allPodsJSON=allPodsJSON[:-1] allPodsJSON+=DB_JSON_BOTTOM return allPodsJSON
def getAll(): if current_user.is_authenticated: return connection.getAll() else: return "please login"
def getAllEventRouter(): return str(getAll())
import db conn = db.getConnection() cursor = conn.cursor() data = db.getAll(cursor) print(data[0]) db.closeConnection(conn)
def getAllPolls(): polls = getAll() return json.dumps([serializePoll(x) for x in polls], default=json_util.default)
def get_all_tasks(): return db.getAll()