This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller_form.py
176 lines (165 loc) · 4.46 KB
/
controller_form.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- coding: utf-8 -*-
import sqlite3
import controller
from PySide.QtCore import QDir, QFileInfo
from PySide.QtGui import QGraphicsPixmapItem, QPixmap, QImage
def add_animal(common,cientific,data,id_type):
"""
Agrega un nuevo animal a la base de datos
"""
success = False
con = controller.connect()
c = con.cursor()
values = [common,cientific,data,id_type]
query = """INSERT INTO animal (nombre_comun, nombre_cientifico, datos, fk_id_tipo) VALUES(?,?,?,?)"""
try:
result = c.execute(query, values)
success = True
con.commit()
except sqlite3.Error as e:
success = False
print "Error: ", e.args[0]
con.close()
return success
def get_id_type(tipo):
"""
Obtiene el id del tipo
"""
con = controller.connect()
c = con.cursor()
query = """SELECT id_tipo FROM tipo WHERE nombre=?"""
c.execute(query, [tipo])
id_tipo = c.fetchone()
result = id_tipo[0]
con.close()
return result
def get_id_animal(animal):
"""
Obtiene el id del animal
"""
con = controller.connect()
c = con.cursor()
query = """SELECT id_animal FROM animal WHERE nombre_comun=?"""
c.execute(query, [animal])
id_animal = c.fetchone()
result = id_animal[0]
con.close()
return result
def add_image_dir(animal,path):
"""
Agrega la imagen a la base de datos
"""
con = controller.connect()
c = con.cursor()
pos = 0
name = ""
while path[pos] != ".":
name = name + path[pos]
pos += 1
format = ""
while pos <= len(path)-1:
format = format + path[pos]
pos += 1
query = """INSERT INTO imagen (ubicacion,formato,fk_id_animal) VALUES(?,?,?)"""
c.execute(query,[name,format,animal])
con.commit()
con.close
def get_image_pix(id_animal):
"""
Carga la imagen ya almacenada en la base de datos
"""
con = controller.connect()
c = con.cursor()
query = """SELECT ubicacion, formato FROM imagen WHERE fk_id_animal=?"""
c.execute(query,[id_animal])
result = c.fetchone()
if result:
path = result[0]
format = result[1]
image = QDir.currentPath()+"/images/"+path+format
pixMap = QPixmap(image)
return pixMap
def get_root_image(path):
"""
Carga la imagen desde la ruta solicitada sin almacenarla en la base de datos
"""
pixMap = QPixmap(path)
return pixMap
def get_image(id_animal):
"""
Obtiene la imagen de un animal especifico
"""
con = controller.connect()
c = con.cursor()
query = """SELECT ubicacion, formato FROM imagen WHERE fk_id_animal=?"""
c.execute(query,[id_animal])
image = c.fetchone()
return image
def edit_animal(id_animal,common,cientific,data,id_type):
"""
Actualiza el animal en la base de datos
"""
success = False
con = controller.connect()
c = con.cursor()
values = [common,cientific,data,id_type,id_animal]
query = """UPDATE animal SET nombre_comun=?, nombre_cientifico =?,
datos=?, fk_id_tipo=? WHERE id_animal=?"""
try:
result = c.execute(query, values)
success = True
con.commit()
except sqlite3.Error as e:
success = False
print "Error: ", e.args[0]
con.close()
return success
def del_image(path):
"""
Borra la imagen de un animal
"""
success = False
con = controller.connect()
c = con.cursor()
pos = 0
name = ""
if path != "":
while path[pos] != ".":
name = name + path[pos]
pos += 1
query = """DELETE FROM imagen WHERE ubicacion=?"""
try:
c.execute(query,[name])
con.commit()
success = True
except sqlite3.Error as e:
success = False
print "Error:", e.args[0]
con.close()
return success
else:
return success
def no_image():
"""
Si no existe imagen carga una por defecto
"""
path = QDir.currentPath() + "/images/noimage.jpg"
pixMap = QPixmap(path)
return pixMap
def search_image(id_animal, Ifile):
"""
Busca imagen de un animal
"""
success = False
con = controller.connect()
c = con.cursor()
query = """SELECT ubicacion, formato FROM imagen WHERE fk_id_animal =?"""
c.execute(query,[id_animal])
result = c.fetchone()
try:
if not result:
success = True
except:
print "asdfasdf"
success = False
return success