本文整理汇总了Python中db_class.Connection类的典型用法代码示例。如果您正苦于以下问题:Python Connection类的具体用法?Python Connection怎么用?Python Connection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: entry
def entry(self, username=None, password=None):
"""A new User with username and password try login
Parameters:
username: a not null email address or
a possibly-null-not string uniquely
identifying the specified user
password: a not null key the specified user
Return:
True: wheather username exits and return a
JSON Object with user map from database
False: wheather username NOT exits and return
None Object
"""
self.username= username #user name to entry
self.password= password #password to entry
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "Query by user "+self.username+" with pass "+self.password+" "
if username == "admin":
self.response= _cnx.single_query("SELECT * FROM usuarios,roles where usuario='"+self.username+"' and contraseniausuario='"+self.password+"' and idrol=roldeusuario limit 1")
else:
self.response= _cnx.single_query("SELECT * FROM usuarios,roles,sucursal where usuario='"+self.username+"' and contraseniausuario='"+self.password+"' and idrol=roldeusuario and roles.codigosucursal = sucursal.codigosucursal limit 1")
if (self.response is not None and len(self.response) > 0):
if self.debug: print "User "+self.username+" FOUND"
return True,self.response[0] #return pair True, JSON
else:
if self.debug: print "User "+self.username+" NO FOUND"
return False,None #return Flase, None
示例2: update_user
def update_user(self,identifier=None,full_name = None, last_name = None, username = None, password = None,
email = None, state = None, phone = None, type_user = None,address=None,description=None):
"""Saves new user to database. returns None on
'user with that username already exists'
Parameters:
full_name: Name user
last_name: Last name user
username: username by ces
password: key user
email: email user
state: state of user - ENABLE - DISABLE
date_user: date of creation
phone: phone user
type_user: rol user - ADMIN - GUESS ---
Return:
True: wheather insert a new User is insert database
False: wheather no insert in database
"""
if self.debug: print "Connect to database"
_cnx= Connection()
try:
if not self.get_by_identifier(identifier)[0]:
return False,"El nombre de usuario <b>"+username+"</b> no existe no se puede actualizar, comuniquese con el administrador"
if password:
self.response= _cnx.no_single_query("UPDATE usuarios SET nombrecompletousuario='"+full_name+"',apellidosusuario ='"+last_name+"',usuario='"+username+"',contraseniausuario='"+password+"',correousuario='"+email+"',estadousuario='"+state+"',telefonousuario='"+phone+"',roldeusuario='"+type_user+"',direccionusuario='"+address+"',descripcionusuario='"+description+"' where idusuario= '"+identifier+"' ")
else:
self.response= _cnx.no_single_query("UPDATE usuarios SET nombrecompletousuario='"+full_name+"',apellidosusuario ='"+last_name+"',usuario='"+username+"',correousuario='"+email+"',estadousuario='"+state+"',telefonousuario='"+phone+"',roldeusuario='"+type_user+"',direccionusuario='"+address+"',descripcionusuario='"+description+"' where idusuario= '"+identifier+"' ")
_cnx.commit()
if self.debug: print "Insert (OK!)"
return True,"El usuario <b>"+full_name+"</b>, con nombre de usuario <b>"+username+"</b> ha sido actualizado <br> <a href='/edituser'>Ver lista</a>"
except:
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
if self.debug: print "NO Insert Error %s" % (exceptionValue)
return False, "%s" % (exceptionValue)
示例3: save_user
def save_user(self,full_name = None, last_name = None, username = None, password = None,
email = None, state = None, phone = None, type_user = None,subsidiary = None,address=None,description=None):
"""Saves new user to database. returns None on
'user with that username already exists'
Parameters:
full_name: Name user
last_name: Last name user
username: username by ces
password: key user
email: email user
state: state of user - ENABLE - DISABLE
date_user: date of creation
phone: phone user
type_user: rol user - ADMIN - GUESS ---
Return:
True: wheather insert a new User is insert database
False: wheather no insert in database
"""
if self.debug: print "Connect to database"
_cnx= Connection()
try:
if self.get_by_username(username)[0]:
raise Exception("El nombre de usuario <b>"+username+"</b> ya existe")
self.response= _cnx.no_single_query("INSERT INTO usuarios (nombrecompletousuario,apellidosusuario,usuario,contraseniausuario,correousuario,estadousuario,telefonousuario,roldeusuario,codigosucursal,direccionusuario,descripcionusuario) "+
"VALUES ('"+full_name+"','"+last_name+"','"+username+"','"+password+"','"+email+"','"+state+"','"+phone+"',(select idrol from roles where roles.nombrerol='"+type_user+"' and codigosucursal= '"+subsidiary+"'),'"+subsidiary+"','"+address+"','"+description+"')")
_cnx.commit()
if self.debug: print "Insert (OK!)"
return True,"El usuario <b>"+full_name+"</b>, con nombre de usuario <b>"+username+"</b> ha sido creado"
except:
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
if self.debug: print "NO Insert Error %s" % (exceptionValue)
return False, "%s" % (exceptionValue)
示例4: save_order
def save_order(self,cedulacliente=None, responsable=None, estado=None, entrega=None, observaciones=None,
totalapagar=None, formadepago=None, recepcion=None, numeroorden=None, placa=None, numero_importacion=None,
marca=None, linea=None, modelo=None, clase_de_vehiculo=None, tipo_carroceria=None, combustible=None,
color=None, cilindraje=None, capacidad=None, sucursal=None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
try:
if self.seek_NumOrder(numeroorden)[0]:
raise Exception("La Orden de Servicio "+numeroorden+"ya existe")
self.response= _cnx.no_single_query("INSERT INTO ordendetrabajo("+
"cedulacliente, responsable, estado, observaciones, "+
"totalapagar, formadepago, recepcion, numeroorden, placa, numero_importacion, "+
"marca, linea, modelo, clase_de_vehiculo, tipo_carroceria, combustible, "+
"color, cilindraje, capacidad,codigosucursal)"+
"VALUES ('"+cedulacliente+"', '"+responsable+"', '"+estado+"', '"+observaciones+"', "+
"'"+totalapagar+"', '"+formadepago+"', '"+recepcion+"', '"+numeroorden+"', '"+placa+"', '"+numero_importacion+"', "+
"'"+marca+"', '"+linea+"', '"+modelo+"', '"+clase_de_vehiculo+"', '"+tipo_carroceria+"', '"+combustible+"', "+
"'"+color+"', '"+cilindraje+"', '"+capacidad+"', '"+str(sucursal)+"');")
_cnx.commit()
if self.debug: print "Insert (OK!)"
return True, "La orden <b>'"+numeroorden+"'</b> ha sido <b>Guardada</b> con exito <br/> <b><a href='/setorderservice'>Ver lista</a></b> "
except:
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
if self.debug: print "NO Insert Error %s" % (exceptionValue)
return False, "%s" % (exceptionValue)
示例5: all_users
def all_users(self,subsidiary=None):
"""
All user in database system
Parameters:
None
Return:
True: wheather exits users and return a
JSON Object with user map from database
False: wheather NOT exits user and return
None Object
"""
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "query all users"
self.response= _cnx.single_query("SELECT * FROM usuarios where codigosucursal "+subsidiary+" ")
if (self.response is not None and len(self.response) > 0):
if self.debug: print len(self.response),"user found"
#Si no es nulo y la longitud de la consulta es mayor que 1
return True,self.response
else:
if self.debug: print "NOT found users"
#return Flase, None
return False,None
示例6: all_offerspublic
def all_offerspublic(self,subsidiary=None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "query all offers"
self.response= _cnx.single_query("SELECT * FROM ofertas WHERE estado ='PUBLICA' AND codigosucursal "+subsidiary+" ORDER BY codigooferta DESC")
if (self.response is not None and len(self.response) > 0):
if self.debug: print len(self.response),"ofertas encontradas"
return True,self.response
else:
if self.debug: print "No hay ofertas"
return False,None
示例7: seek_offerbyuid
def seek_offerbyuid(self,uuid=None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "query offer uuid= "+uuid+""
self.response= _cnx.single_query("SELECT * FROM ofertas WHERE uuid = '"+uuid+"' ")
if (self.response is not None and len(self.response) > 0):
if self.debug: print len(self.response),"offers found --"
return True,self.response
else:
if self.debug: print "No offers found"
return False,None
示例8: seek_quotation
def seek_quotation(self,numerocotizacion=None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "query "+numerocotizacion+" quotations"
self.response= _cnx.single_query("SELECT * FROM cotizacion where numerocotizacion = '"+numerocotizacion+"' ")
if (self.response is not None and len(self.response) > 0):
if self.debug: print len(self.response),"quotation found"
return True,self.response
else:
if self.debug: print "NOT found quotations"
return False,None
示例9: exist_offerbyId
def exist_offerbyId(self,codigooferta):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "query all offers"
self.response= _cnx.single_query("SELECT * FROM ofertas WHERE codigooferta='"+codigooferta+"'")
if (self.response is not None and len(self.response) > 0):
if self.debug: print len(self.response),"ofertas encontradas"
return True
else:
if self.debug: print "No hay ofertas"
return False
示例10: exist_offer
def exist_offer(self,codigovehiculo=None,codigorepuesto=None,tipooferta=None,valoroferta=None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "Buscando ofertas"
self.response= _cnx.single_query("SELECT * FROM ofertas WHERE tipooferta='"+tipooferta+"' AND codigovehiculo='"+codigovehiculo+"' AND codigorepuesto ='"+codigorepuesto+"' AND valoroferta ='"+valoroferta+"'" )
if (self.response is not None and len(self.response) > 0):
if self.debug: print len(self.response),"ofertas encontradas"
return True
else:
if self.debug: print "No hay ofertas"
return False
示例11: update_style
def update_style(self,codigosucursal =None,theme= None, size = None, font=None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
try:
self.response= _cnx.no_single_query("UPDATE sucursal set configuracion = '{\"tema\":\""+theme+"\",\"tamanio\":\""+size+"\",\"fuente\":\""+font+"\"}' where codigosucursal = '"+str(codigosucursal)+"' ")
_cnx.commit()
if self.debug: print "Update (OK!)"
return True,"Todo a ido de maravilla, tu pagina se va actulizar para que veas los cambios."
except:
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
if self.debug: print "No update %s" % (exceptionValue)
return False, " %s" % (exceptionValue)
示例12: all_sales
def all_sales(self,codigo_sucursal=None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "query all sales"
self.response = _cnx.single_query("SELECT * FROM venta,cliente where venta.codigosucursal "+codigo_sucursal+" and venta.codigocliente = cliente.codigocliente")
if (self.response is not None and len(self.response) > 0):
if self.debug: print len(self.response),"sales found"
return True,self.response
else:
if self.debug: print "NOT found sales"
#return Flase, None
return False,None
示例13: delete_inventory
def delete_inventory(self,codigo_inventario =None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
try:
if self.debug: print "try delete inventory "+str(codigo_inventario)+" "
self.response= _cnx.no_single_query("DELETE from inventario where codigo_inventario='"+str(codigo_inventario)+"'")
_cnx.commit()
if self.debug: print "DELETED (OK!)"
return True,"El inventario ha sido actualizado."
except:
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
if self.debug: print "No update %s" % (exceptionValue)
示例14: all_quotations
def all_quotations(self,codigo_sucursal=None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "query all articles"
self.response = _cnx.single_query("SELECT * FROM cotizacion where codigosucursal "+codigo_sucursal+" ")
if (self.response is not None and len(self.response) > 0):
if self.debug: print len(self.response),"articles found"
return True,self.response
else:
if self.debug: print "NOT found articles"
#return Flase, None
return False,None
示例15: seek_inventory_bySubsidiary
def seek_inventory_bySubsidiary(self,codigo_sucursal=None):
"""
"""
if self.debug: print "Connect to database"
_cnx= Connection()
if self.debug: print "query "+str(codigo_sucursal)+" inventory"
self.response= _cnx.single_query("SELECT * FROM inventario where codigo_sucursal = '"+str(codigo_sucursal)+"' ")
if (self.response is not None and len(self.response) > 0):
if self.debug: print len(self.response),"inventory found"
#Si no es nulo y la longitud de la consulta es mayor que 1
return True,self.response
else:
if self.debug: print "NOT found inventory"
#return Flase, None
return False,None