Index: controlies/trunk/applications/controlies/controllers/laptops.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/laptops.py	(revision 374)
+++ controlies/trunk/applications/controlies/controllers/laptops.py	(revision 375)
@@ -1,13 +1,10 @@
 # coding: utf8
 from applications.controlies.modules.Laptops import Laptops
 from applications.controlies.modules.LaptopsHistory import LaptopsHistory
-from applications.controlies.modules.SQLiteConnection import SQLiteConnection
 from applications.controlies.modules.Utils import Utils
 from applications.controlies.modules.Users import Users
 
-def index():
-    my = SQLiteConnection()
-    my.define_tables()    
+def index(): 
     return dict()
 
 ################## LAPTOPS ####################
@@ -15,22 +12,19 @@
 @service.json
 @auth.requires_login()
 def list():
-    my = SQLiteConnection()
-    l = Laptops(my,"","","")
+    l = Laptops(cdb,"","","")
     response = l.list(request.vars)
     return response
 
 @service.json
 def getLaptopData():
-    my = SQLiteConnection()
-    l = Laptops(my,request.vars['id_laptop'],"","")
+    l = Laptops(cdb,request.vars['id_laptop'],"","")
     response = l.getLaptopData()
     return dict(response=response)
 
 @service.json
 def getAllLaptopTypes():
-    my = SQLiteConnection()
-    l = Laptops(my,"","","")
+    l = Laptops(cdb,"","","")
     response = l.getAllLaptopTypes()
     return dict(response=response)
 
@@ -38,8 +32,8 @@
 @auth.requires_login()    
 def modify():
     serial = request.vars["serial_number"].strip()
-    my = SQLiteConnection()
-    l = Laptops(my,request.vars["id_laptop"],serial,request.vars["id_trademark"])
+
+    l = Laptops(cdb,request.vars["id_laptop"],serial,request.vars["id_trademark"])
     response = l.process(request.vars["action"])
     return dict(response = response)            
 
@@ -46,8 +40,7 @@
 @service.json
 @auth.requires_login()       
 def delete():
-    my = SQLiteConnection()
-    l = Laptops(my,request.vars["id_laptop"],"","")
+    l = Laptops(cdb,request.vars["id_laptop"],"","")
     response = l.delete()                         
     return dict(response=response)
 
@@ -56,8 +49,7 @@
 @service.json
 @auth.requires_login()
 def listHistory():    
-    my = SQLiteConnection()
-    l = LaptopsHistory(my,"",request.vars["id_laptop"],"","","","","","")
+    l = LaptopsHistory(cdb,"",request.vars["id_laptop"],"","","","","","")
     response = l.list(request.vars)
     return response
 
@@ -64,8 +56,7 @@
 @service.json
 @auth.requires_login()    
 def modifyHistory():
-    my = SQLiteConnection()
-    l = LaptopsHistory(my,request.vars["id_historical"],request.vars["id_laptop"],request.vars["id_state"],request.vars["id_user_type"],request.vars["nif"].strip(),request.vars["username"].strip(),request.vars["name"].strip(),request.vars["comment"])
+    l = LaptopsHistory(cdb,request.vars["id_historical"],request.vars["id_laptop"],request.vars["id_state"],request.vars["id_user_type"],request.vars["nif"].strip(),request.vars["username"].strip(),request.vars["name"].strip(),request.vars["comment"])
     response = l.process(request.vars["action"])
     return dict(response = response)   
 
@@ -72,22 +63,19 @@
 @service.json
 @auth.requires_login()       
 def deleteHistory():
-    my = SQLiteConnection()
-    l = LaptopsHistory(my,request.vars["id_historical"],"","","","","","","")
+    l = LaptopsHistory(cdb,request.vars["id_historical"],"","","","","","","")
     response = l.delete()                         
     return dict(response=response)
 
 @service.json
 def getAllStates():
-    my = SQLiteConnection()
-    l = LaptopsHistory(my,"","","","","","","","")
+    l = LaptopsHistory(cdb,"","","","","","","","")
     response = l.getAllStates()
     return dict(response=response)
 
 @service.json
 def getAllUserTypes():
-    my = SQLiteConnection()
-    l = LaptopsHistory(my,"","","","","","","","")
+    l = LaptopsHistory(cdb,"","","","","","","","")
     response = l.getAllUserTypes()
     return dict(response=response)
 
@@ -101,15 +89,13 @@
 
 @service.json
 def getDataHistory():
-    my = SQLiteConnection()
-    l = LaptopsHistory(my,request.vars["id_historical"],"","","","","","","")
+    l = LaptopsHistory(cdb,request.vars["id_historical"],"","","","","","","")
     response = l.getDataHistory()
     return dict(response=response)
 
 @service.json
 def getDataLastHistory():
-    my = SQLiteConnection()
-    l = LaptopsHistory(my,"",request.vars["id_laptop"],"","","","","","")
+    l = LaptopsHistory(cdb,"",request.vars["id_laptop"],"","","","","","")
     response = l.getLastHistory()
     return dict(response=response)
 
Index: controlies/trunk/applications/controlies/modules/SQLiteConnection.py
===================================================================
--- controlies/trunk/applications/controlies/modules/SQLiteConnection.py	(revision 374)
+++ controlies/trunk/applications/controlies/modules/SQLiteConnection.py	(revision 375)
@@ -30,7 +30,7 @@
     
     def __init__(self):
         self.db = DAL('sqlite://controlies.sqlite')
-
+        
     def define_tables(self):
         self.db.define_table('laptops', 
                         Field('id_laptop','integer'),
Index: controlies/trunk/applications/controlies/modules/Laptops.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Laptops.py	(revision 374)
+++ controlies/trunk/applications/controlies/modules/Laptops.py	(revision 375)
@@ -29,8 +29,8 @@
     def __init__(self):
         pass
     
-    def __init__(self,SQLite,id_laptop,serial_number,id_trademark):
-        self.SQLite = SQLite
+    def __init__(self,DB,id_laptop,serial_number,id_trademark):
+        self.DB = DB
         self.id_laptop = id_laptop        
         self.serial_number = serial_number
         self.id_trademark = id_trademark        
@@ -75,8 +75,6 @@
         
             
     def list(self,args):
-        db = self.SQLite.getDB()
-        import pdb
 
         sql = "SELECT l.id_laptop, lt.trademark, lt.model, l.serial_number, lh.username, s.state"
         sql = sql+" FROM laptops l"
@@ -118,7 +116,7 @@
         sql = sql + " GROUP BY l.id_laptop"
         sql = sql + " ORDER BY "+args['sidx']+" "+args['sord']+", lh.datetime desc"
 
-        result = db.executesql(sql)
+        result = self.DB.executesql(sql)
 
         rows = []
         for reg in result:
@@ -156,10 +154,7 @@
 
 
     def add(self):
-        sql = "INSERT INTO laptops (id_laptop, serial_number, id_trademark) "
-        sql = sql + "VALUES(null,'"+self.serial_number+"','"+self.id_trademark+"')"
-        db = self.SQLite.getDB()
-        result = db.executesql(sql)
+        self.DB.laptops.insert(serial_number=self.serial_number,id_trademark=self.id_trademark)
         
         return "OK"
             
@@ -167,9 +162,7 @@
     def modify(self):
         sql = "UPDATE laptops SET serial_number='"+self.serial_number+"', id_trademark='"+self.id_trademark+"' "
         sql = sql + "WHERE id_laptop='"+str(self.id_laptop)+"'"
-
-        db = self.SQLite.getDB()
-        result = db.executesql(sql)
+        result = self.DB.executesql(sql)
                     
         return "OK"
 
@@ -176,9 +169,7 @@
 
     def delete(self):
         sql = "DELETE FROM laptops WHERE id_laptop='"+str(self.id_laptop)+"'"
-
-        db = self.SQLite.getDB()
-        result = db.executesql(sql)
+        result = self.DB.executesql(sql)
             
         return "OK"
 
@@ -186,10 +177,8 @@
     def existsSerialNumber(self,serial_number):
         
         sql = "SELECT p.id_laptop FROM laptops p WHERE p.serial_number='"+serial_number+"'"
+        result = self.DB.executesql(sql)
 
-        db = self.SQLite.getDB()
-        result = db.executesql(sql)
-
         if len(result) > 0:
             return str(result[0][0])
         
@@ -200,8 +189,7 @@
         sql="SELECT l.id_laptop, l.serial_number, l.id_trademark, lt.trademark, lt.model "
         sql=sql+"FROM laptops l, laptops_trademarks lt WHERE l.id_trademark=lt.id_trademark AND l.id_laptop='"+str(self.id_laptop)+"'"
 
-        db = self.SQLite.getDB()
-        result = db.executesql(sql)
+        result = self.DB.executesql(sql)
 
         dataLaptop = {
             "id_laptop":str(result[0][0]),
@@ -213,8 +201,7 @@
 
     def getAllLaptopTypes(self):
         sql="SELECT id_trademark, trademark, model FROM laptops_trademarks ORDER BY trademark"
-        db = self.SQLite.getDB()
-        result = db.executesql(sql)
+        result = self.DB.executesql(sql)
 
         data=[]
         for r in result:
@@ -227,7 +214,6 @@
 
     def getMaxId(self):
         sql="SELECT max(id_laptop) AS max FROM laptops"
-        db = self.SQLite.getDB()
-        result = db.executesql(sql)
+        result = self.DB.executesql(sql)
 
         return str(result[0][0])
\ No newline at end of file
Index: controlies/trunk/applications/controlies/models/controliesDB.py
===================================================================
--- controlies/trunk/applications/controlies/models/controliesDB.py	(nonexistent)
+++ controlies/trunk/applications/controlies/models/controliesDB.py	(revision 375)
@@ -0,0 +1,58 @@
+cdb = DAL('sqlite://controlies.sqlite')
+cdb.define_table('laptops', 
+                        Field('id_laptop','integer'),
+                        Field('serial_number','string'),
+                        Field('id_trademark','integer'),
+                        primarykey=['id_laptop'])
+
+cdb.define_table('laptops_trademarks', 
+                        Field('id_trademark','integer'),
+                        Field('trademark','string'),
+                        Field('model','string'),
+                        primarykey=['id_trademark'])
+
+cdb.define_table('users_types', 
+                        Field('id_user_type','integer'),
+                        Field('user_type','string'),
+                        primarykey=['id_user_type'])
+
+try:
+    cdb.users_types.insert(id_user_type='1',user_type='Profesor')
+except:
+    pass
+
+try:
+    cdb.users_types.insert(id_user_type='2',user_type='Alumno')
+except:
+    pass
+
+cdb.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('nif','string'),
+                        Field('comment','string'),
+                        Field('id_state','integer'),
+                        primarykey=['id_historical'])
+
+cdb.define_table('states', 
+                        Field('id_state','integer'),
+                        Field('state','string'),                        
+                        primarykey=['id_state'])
+try:
+    cdb.states.insert(id_state='1',state='Sin asignar')
+except:
+    pass
+
+try:
+    cdb.states.insert(id_state='2',state='Asignado')
+except:
+    pass
+
+try:
+    cdb.states.insert(id_state='3',state='En reparación')
+except:
+    pass
\ No newline at end of file
