-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
203 lines (157 loc) · 3.94 KB
/
models.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
"""SQLAlchemy models for pixly app"""
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.exc import IntegrityError
db = SQLAlchemy()
def connect_db(app):
"""Connect this database to provided Flask app.
You should call this in your Flask app.
"""
app.app_context().push()
db.app = app
db.init_app(app)
class Photo(db.Model):
"""Photo in the database."""
__tablename__ = "photos_metadata"
# Note to selves: this is how we link our model to the database table!
id = db.Column(
db.Integer,
primary_key=True,
)
filename = db.Column(
db.String(150),
nullable=True,
unique=True,
)
make = db.Column(
db.String(60),
nullable=True,
)
model = db.Column(
db.String(60),
nullable=True,
)
orientation_rotation = db.Column(
db.String(30),
nullable=True,
)
software = db.Column(
db.String(30),
nullable=True,
)
date_and_time = db.Column(
db.String(30),
nullable=True,
)
ycbcr_positioning = db.Column(
db.String(30),
nullable=True,
)
x_resolution = db.Column(
db.String(30),
nullable=True,
)
y_resolution = db.Column(
db.String(30),
nullable=True,
)
resolution_unit = db.Column(
db.String(25),
nullable=True,
)
exposure_time = db.Column(
db.String(15),
nullable=True,
)
f_number = db.Column(
db.String(10),
nullable=True,
)
exposure_program = db.Column(
db.String(30),
nullable=True,
)
exif_version = db.Column(
db.String(30),
nullable=True,
)
date_and_time_original = db.Column(
db.String(30),
nullable=True,
)
date_and_time_digitized = db.Column(
db.String(30),
nullable=True,
)
components_configuration = db.Column(
db.String(25),
nullable=True,
)
exposure_bias = db.Column(
db.String(30),
nullable=True,
)
metering_mode = db.Column(
db.String(50),
nullable=True,
)
flash = db.Column(
db.String(100),
nullable=True,
)
focal_length = db.Column(
db.String(10),
nullable=True,
)
maker_note = db.Column(
db.String(100),
nullable=True,
)
flashpix_version = db.Column(
db.String(35),
nullable=True,
)
color_space = db.Column(
db.String(50),
nullable=True,
)
interoperability_index = db.Column(
db.String(10),
nullable=True,
)
interoperability_version = db.Column(
db.String(50),
nullable=True,
)
alt_tag = db.Column(
db.String(400),
nullable=False
)
def __repr__(self):
return f"<{self.__class__.__name__} self.filename={self.filename}>"
@classmethod
def submit_photo(self, metadata_tags):
"""
INPUTS: submit_photo takes its instance and it takes metadata_tags,
a dictionary with information on a photo's metadata.
metadata_tags example:
{
filename: "Kodak_CX7530.jpg",
make: "EASTMAN KODAK COMPANY",
model: "KODAK CX7530 ZOOM DIGITAL CAMERA",
...
}
FUNCTION: generates a new instance of Photo class using metadata_tags.
Adds photo instance to database.
OUTPUT: new_photo, the generated instance of the photograph.
"""
print('This is metadata_tags: ', metadata_tags)
print('Before new photo')
try:
new_photo = Photo(**metadata_tags)
print('After new photo: ', new_photo)
print('new_photo.make: ', new_photo.make)
except IntegrityError:
print('error occurred', IntegrityError)
db.session.add(new_photo)
db.session.commit()
return new_photo