Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 349

Añadido por Manu Mora Gordillo hace casi 13 años

Sustituimos MySQL por SQLite

Ver diferencias:

controlies/trunk/applications/controlies/controllers/laptops.py
# coding: utf8
from applications.controlies.modules.Laptops import Laptops
from applications.controlies.modules.MySQLConnection import MySQLConnection
from applications.controlies.modules.SQLiteConnection import SQLiteConnection
from applications.controlies.modules.Utils import Utils
def index():
......
@service.json
@auth.requires_login()
def list():
my = MySQLConnection()
my = SQLiteConnection()
l = Laptops(my,"","","")
response = l.list(request.vars)
return response
@service.json
def getLaptopData():
my = MySQLConnection()
my = SQLiteConnection()
l = Laptops(my,request.vars['id_portatil'],"","")
response = l.getLaptopData()
return dict(response=response)
@service.json
def getAllLaptopTypes():
my = MySQLConnection()
my = SQLiteConnection()
l = Laptops(my,"","","")
response = l.getAllLaptopTypes()
return dict(response=response)
......
@service.json
@auth.requires_login()
def delete():
my = MySQLConnection()
my = SQLiteConnection()
l = Laptops(my,request.vars["id_portatil"],"","")
response = l.delete()
return dict(response=response)
......
@service.json
@auth.requires_login()
def modify():
my = MySQLConnection()
my = SQLiteConnection()
l = Laptops(my,request.vars["id_portatil"],request.vars["numero_serie"],request.vars["marca_modelo"])
response = l.process(request.vars["action"])
return dict(response = response)
controlies/trunk/applications/controlies/modules/MySQLConnection.py
##############################################################################
# -*- coding: utf-8 -*-
# Project: ControlIES
# Module: MySQLConnection.py
# Purpose: Connection with mysql-server
# Language: Python 2.5
# Date: 23-May-2012.
# Ver: 23-May-2012.
# Authores: Manuel Mora Gordillo
# Francisco Damian Mendez Palma
# Copyright: 2012 - Manuel Mora Gordillo <manuito @no-spam@ gmail.com>
# 2012 - Francisco Damian Mendez Palma <fmendezpalma @no-spam@ gmail.com>
#
# ControlIES is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# ControlIES is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with ControlAula. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import MySQLdb
class MySQLConnection(object):
def __init__(self):
self.host = "172.23.36.3"
self.user = "controlies"
self.passwd = "controlies"
self.database = "controlies"
def execute(self,sql):
db = MySQLdb.connect(host=self.host,user=self.user, passwd=self.passwd,db=self.database)
cursor=db.cursor()
cursor.execute(sql)
result = cursor.fetchall()
cursor.close()
db.close()
return result
controlies/trunk/applications/controlies/modules/SQLiteConnection.py
##############################################################################
# -*- coding: utf-8 -*-
# Project: ControlIES
# Module: SQLiteConnection.py
# Purpose: Connection with sqlite
# Language: Python 2.5
# Date: 23-May-2012.
# Ver: 23-May-2012.
# Authores: Manuel Mora Gordillo
# Francisco Damian Mendez Palma
# Copyright: 2012 - Manuel Mora Gordillo <manuito @no-spam@ gmail.com>
# 2012 - Francisco Damian Mendez Palma <fmendezpalma @no-spam@ gmail.com>
#
# ControlIES is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# ControlIES is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with ControlAula. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from gluon.sql import *
class SQLiteConnection(object):
def __init__(self):
self.db = DAL('sqlite://controlies.sqlite')
self.define_tables()
def define_tables(self):
self.db.define_table('laptops',
Field('id_laptop','integer'),
Field('serial_number','string'),
Field('id_trademark','integer'),
primarykey=['id_laptop'])
self.db.define_table('laptops_trademarks',
Field('id_trademark','integer'),
Field('trademark','string'),
Field('model','string'),
primarykey=['id_trademark'])
self.db.define_table('users_types',
Field('id_user_type','integer'),
Field('user_type','string'),
primarykey=['id_user_type'])
self.db.define_table('laptops_historical',
Field('id_historical','integer'),
Field('id_laptop','integer'),
Field('datetime','datetime'),
Field('username','string'),
Field('name','string'),
Field('id_user_type','integer'),
Field('comment','string'),
Field('id_state','integer'),
primarykey=['id_historical','id_laptop'])
self.db.define_table('states',
Field('id_state','integer'),
Field('state','string'),
primarykey=['id_state'])
def getDB(self):
return self.db
def select(self,table,data):
self.db.table.insert(data)
def insert(self,table,data):
self.db.table.insert(data)
def execute(self,sql):
"""db = MySQLdb.connect(host=self.host,user=self.user, passwd=self.passwd,db=self.database)
cursor=db.cursor()
cursor.execute(sql)
result = cursor.fetchall()
cursor.close()
db.close()
return result"""
controlies/trunk/applications/controlies/modules/Laptops.py
def __init__(self):
pass
def __init__(self,MySQL,id_portatil,numero_serie,id_marca_modelo):
self.MySQL = MySQL
def __init__(self,SQLite,id_portatil,numero_serie,id_marca_modelo):
self.SQLite = SQLite
self.id_portatil = id_portatil
self.numero_serie = numero_serie
self.id_marca_modelo = id_marca_modelo
......
return { "page":page, "total":totalPages, "records":len(rows), "rows":rows[start:finish] }
def add(self):
sql = "INSERT INTO portatiles (id_portatil, numero_serie, id_marca_modelo) "
def add(self):
"""sql = "INSERT INTO portatiles (id_portatil, numero_serie, id_marca_modelo) "
sql = sql + "VALUES(null,'"+self.numero_serie+"','"+self.id_marca_modelo+"')"
result = self.MySQL.execute(sql)
result = self.MySQL.execute(sql)"""
data = { 'id_laptop':'1', 'serial_number':self.numero_serie, 'id_trademark':self.id_marca_modelo }
self.SQLite.insert(laptops,data)
return "OK"
def modify(self):
"""def modify(self):
sql = "UPDATE portatiles SET numero_serie='"+self.numero_serie+"', id_marca_modelo='"+self.id_marca_modelo+"' "
sql = sql + "WHERE id_portatil='"+str(self.id_portatil)+"'"
result = self.MySQL.execute(sql)
result = self.SQLite.execute(sql)
return "OK"
def delete(self):
sql = "DELETE FROM portatiles WHERE id_portatil='"+str(self.id_portatil)+"'"
result = self.MySQL.execute(sql)
result = self.SQLite.execute(sql)
return "OK"
......
"marca_modelo":r[1]+" / "+r[2]
}
data.append(dataType)
return data
return data"""

Exportar a: Unified diff