-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathImage.py
More file actions
57 lines (49 loc) · 1.56 KB
/
Image.py
File metadata and controls
57 lines (49 loc) · 1.56 KB
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
from flask import g
import json
class Image:
@staticmethod
def newFromId(id, includeImage=False):
try:
cursor = g.db.cursor()
if(includeImage):
cursor.execute(
"SELECT id, set_id, image FROM images "
"WHERE id = %s", (id)
)
else:
cursor.execute(
"SELECT id, set_id, '' as image FROM images "
"WHERE id = %s", (id)
)
(id, set_id, image) = cursor.fetchone()
return Image(id, set_id, image)
except:
return Image()
def __init__(self, id=None, set_id=None, image=None):
self.id = id
self.set_id = set_id
self.image = image
def toJSON(self):
return json.dumps(self.__dict__)
def create(self):
cursor = g.db.cursor()
cursor.execute(
"INSERT INTO images (set_id, image) "
"VALUES (%s, %s)", (self.set_id, self.image)
)
self.id = cursor.lastrowid
def update(self):
cursor = g.db.cursor()
cursor.execute(
"UPDATE images SET "
"set_id = %s, "
"image = %s, "
"WHERE id = %s", (self.set_id, self.image, self.id)
)
def delete(self):
cursor = g.db.cursor()
cursor.execute(
"DELETE FROM images "
"WHERE id = %s", (self.id)
)
self.id = None