def GetAllCellars(): conn = BaseModel().connection cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) query = '''select * from "Cellar"''' try: cur.execute(query) cellar = cur.fetchall() data_rtn = [] for c in cellar: cellar = Cellar() cellar.id = c['id'] cellar.name = c['name'] cellar.description = c['description'] cellar.city = c["city_id"] cellar.for_sale = c["for_sale"] data_rtn.append(cellar.Print()) return data_rtn except Exception, e: print "Get all cellars {}".format(str(e))
def load_model(hps, model_path): session = tf.Session() model = BaseModel(hps) saver = tf.train.Saver() saver.restore(session, save_path=model_path) # x ** 2 < 50 return model, session
def CellarExists(cellar_name): bm = BaseModel() cur = bm.connection.cursor(cursor_factory=psycopg2.extras.DictCursor) query = '''select * from "Cellar" where name = %(name)s limit 1''' parametros = {"name": cellar_name} cur.execute(query, parametros) if cur.rowcount > 0: return True else: return False
def get_single_post(self, post_id): con = init_db() cur = con.cursor() if BaseModel().check_exist('posts', 'post_id', post_id) == False: return 404 query = "SELECT title, description, created_by, created_on FROM posts WHERE post_id={}".format( post_id) cur.execute(query) data = cur.fetchall()[0] res = [] posts = dict(title=data[0], description=data[1], created_by=int(data[2]), created_on=str(data[3])) res.append(posts) return res
def save(self): post = { "title": self.title, "description": self.description, "created_by": self.created_by } con = init_db() cur = con.cursor() if BaseModel().check_exist('posts', 'title', self.title) == True: return "post already exists" query = """ INSERT INTO posts (title, description, created_by) VALUES \ ( %(title)s, %(description)s, %(created_by)s) RETURNING post_id """ cur.execute(query, post) post_id = cur.fetchone()[0] con.commit() cur.close() return post_id
def save(self): user = { "name": self.name, "username": self.username, "email": self.email, "password": self.password } con = init_db() cur = con.cursor() if BaseModel().check_exist('users', 'email', self.email) == True: return "user already exists" query = """ INSERT INTO users (name, username, email, password) VALUES \ ( %(name)s, %(username)s, %(email)s, %(password)s) RETURNING user_id """ cur.execute(query, user) user_id = cur.fetchone()[0] con.commit() con.close() return user_id
def CellarExists(cellar_name): # data = db.cellar.find({"name" : cellar_name }) # if data.count() >= 1: # return True # return False bm = BaseModel() cur = bm.connection.cursor(cursor_factory=psycopg2.extras.DictCursor) query = '''select * from "Cellar" where name = %(name)s limit 1''' parametros = {"name": cellar_name} cur.execute(query, parametros) cellar = cur.fetchone() if cellar: return True else: return False
from bson import json_util from basemodel import BaseModel, db from salesman import Salesman from cellar import Cellar from product import Product from kardex import Kardex from brand import Brand from category import Category #################################### ########## basemodel.py ############ #################################### print "testing basemodel.py" base_model = BaseModel() base_model.identifier = "" ## remove empty print "error : {}".format(base_model.Remove()) ## adding item print "adding: " base_model.identifier = db.base_testing.save({"_id": "un_id"}) val_1 = db.base_testing.find().count() message = base_model.Remove() val_2 = db.base_testing.find().count() status = "fail" if val_1 == 1 and val_2 == 0: