7 | 7 |
|
8 | 8 |
PER_PAGE = 16
|
9 | 9 |
|
| 10 |
|
10 | 11 |
def slugify(string):
|
11 | 12 |
def process(char):
|
12 | |
if char in '- \n\t\f':
|
13 | |
return '-'
|
| 13 |
if char in "- \n\t\f":
|
| 14 |
return "-"
|
14 | 15 |
elif char.isalpha():
|
15 | 16 |
return char.lower()
|
16 | 17 |
else:
|
17 | |
return ''
|
18 | |
return ''.join(process(c) for c in string)[:40]
|
| 18 |
return ""
|
| 19 |
|
| 20 |
return "".join(process(c) for c in string)[:40]
|
19 | 21 |
|
20 | 22 |
|
21 | 23 |
class Image(typing.NamedTuple):
|
22 | 24 |
image: str
|
23 | 25 |
|
24 | 26 |
def thumb(self):
|
25 | |
return self.image[:-4] + '_thumb' + self.image[-4:]
|
| 27 |
return self.image[:-4] + "_thumb" + self.image[-4:]
|
26 | 28 |
|
27 | 29 |
|
28 | 30 |
class PageContent:
|
|
36 | 38 |
if len(self.source) < 256:
|
37 | 39 |
return self.source
|
38 | 40 |
else:
|
39 | |
return self.source[:256] + '...'
|
| 41 |
return self.source[:256] + "..."
|
40 | 42 |
|
41 | 43 |
|
42 | 44 |
class PageRef(typing.NamedTuple):
|
|
64 | 66 |
return self.images[0].thumb()
|
65 | 67 |
|
66 | 68 |
@classmethod
|
67 | |
def list(cls, query_results) -> typing.List['Design']:
|
| 69 |
def list(cls, query_results) -> typing.List["Design"]:
|
68 | 70 |
return [
|
69 | 71 |
cls(
|
70 | 72 |
title=d.title,
|
|
72 | 74 |
description=d.description,
|
73 | 75 |
category=d.cat_name,
|
74 | 76 |
id=d.id,
|
75 | |
) for d in query_results]
|
| 77 |
)
|
| 78 |
for d in query_results
|
| 79 |
]
|
76 | 80 |
|
77 | 81 |
|
78 | 82 |
class Paginated(typing.NamedTuple):
|
|
83 | 87 |
|
84 | 88 |
@classmethod
|
85 | 89 |
def paginate(
|
86 | |
cls,
|
87 | |
offset: int,
|
88 | |
total: int,
|
89 | |
contents: typing.List[Design],
|
90 | |
) -> 'Paginated':
|
| 90 |
cls, offset: int, total: int, contents: typing.List[Design],
|
| 91 |
) -> "Paginated":
|
91 | 92 |
last_page = total // PER_PAGE
|
92 | |
next_page = PageRef(page=offset+1) if offset < last_page else None
|
93 | |
prev_page = PageRef(page=offset-1) if offset > 0 else None
|
| 93 |
next_page = PageRef(page=offset + 1) if offset < last_page else None
|
| 94 |
prev_page = PageRef(page=offset - 1) if offset > 0 else None
|
94 | 95 |
return cls(
|
95 | 96 |
next_page=next_page,
|
96 | 97 |
prev_page=prev_page,
|
|
104 | 105 |
count: int
|
105 | 106 |
|
106 | 107 |
def pretty(self):
|
107 | |
return ' '.join(w.capitalize() for w in self.tag.split())
|
| 108 |
return " ".join(w.capitalize() for w in self.tag.split())
|
108 | 109 |
|
109 | 110 |
|
110 | 111 |
THUMB_SIZE = (100, 100)
|
111 | 112 |
|
112 | 113 |
|
113 | 114 |
class DB:
|
114 | |
|
115 | 115 |
def __init__(self, per_page=16):
|
116 | |
self._db = web.database(dbn='sqlite', db='frony.db')
|
| 116 |
self._db = web.database(dbn="sqlite", db="frony.db")
|
117 | 117 |
self.per_page = PER_PAGE
|
118 | 118 |
self.categories = {}
|
119 | 119 |
self.photo_num = self.get_max_photo_num() + 1
|
120 | 120 |
|
121 | 121 |
def get_max_photo_num(self):
|
122 | 122 |
n = 0
|
123 | |
for file in os.listdir(os.path.join('static', 'photos')):
|
| 123 |
for file in os.listdir(os.path.join("static", "photos")):
|
124 | 124 |
try:
|
125 | 125 |
n = max(int(file[:5]), n)
|
126 | 126 |
except:
|
|
128 | 128 |
return n
|
129 | 129 |
|
130 | 130 |
def get_category_id(self, nm):
|
131 | |
id = list(self._db.where('categories', name=nm))
|
| 131 |
id = list(self._db.where("categories", name=nm))
|
132 | 132 |
return id and id[0].id
|
133 | 133 |
|
134 | 134 |
def all_categories(self):
|
135 | |
categories = self._db.select('categories')
|
| 135 |
categories = self._db.select("categories")
|
136 | 136 |
return [(c.name, c.id, c.nicename) for c in categories]
|
137 | 137 |
|
138 | 138 |
def get_category_name(self, id):
|
139 | 139 |
if id in self.categories:
|
140 | 140 |
return self.categories[id]
|
141 | 141 |
else:
|
142 | |
nm = list(self._db.where('categories', id=id))
|
| 142 |
nm = list(self._db.where("categories", id=id))
|
143 | 143 |
if nm:
|
144 | 144 |
self.categories[id] = nm[0].name
|
145 | |
return nm and nm[0].name or 'unknown'
|
| 145 |
return nm and nm[0].name or "unknown"
|
146 | 146 |
|
147 | 147 |
def get_design(self, id):
|
148 | |
d = list(self._db.where('designs', id=id))
|
| 148 |
d = list(self._db.where("designs", id=id))
|
149 | 149 |
if not d:
|
150 | 150 |
return None
|
151 | 151 |
else:
|
152 | 152 |
d = d[0]
|
153 | |
return Design(title=d.title,
|
154 | |
images=self.get_all_photos_for_design(d.id),
|
155 | |
description=PageContent(d.description),
|
156 | |
category=self.get_category_name(d.category),
|
157 | |
id=d.id)
|
| 153 |
return Design(
|
| 154 |
title=d.title,
|
| 155 |
images=self.get_all_photos_for_design(d.id),
|
| 156 |
description=PageContent(d.description),
|
| 157 |
category=self.get_category_name(d.category),
|
| 158 |
id=d.id,
|
| 159 |
)
|
158 | 160 |
|
159 | 161 |
def put_design(self, id, title, description, category):
|
160 | |
description = description.replace('\r\n', '\n')
|
| 162 |
description = description.replace("\r\n", "\n")
|
161 | 163 |
self._db.update(
|
162 | |
'designs',
|
163 | |
where='id = $id',
|
| 164 |
"designs",
|
| 165 |
where="id = $id",
|
164 | 166 |
vars=dict(id=id),
|
165 | 167 |
title=title,
|
166 | 168 |
description=description,
|
167 | |
category=category
|
| 169 |
category=category,
|
168 | 170 |
)
|
169 | 171 |
|
170 | 172 |
def get_photo_by_id(self, id):
|
171 | 173 |
try:
|
172 | |
return self._db.where('photos', id=id)[0].filename
|
| 174 |
return self._db.where("photos", id=id)[0].filename
|
173 | 175 |
except:
|
174 | 176 |
return None
|
175 | 177 |
|
176 | 178 |
def get_picture(self, id):
|
177 | 179 |
try:
|
178 | |
return Image((self._db.where('photos', design_id=id,
|
179 | |
limit=1))[0].filename)
|
| 180 |
return Image((self._db.where("photos", design_id=id, limit=1))[0].filename)
|
180 | 181 |
except:
|
181 | 182 |
return None
|
182 | 183 |
|
|
184 | 185 |
if not pp:
|
185 | 186 |
pp = self.per_page
|
186 | 187 |
return [
|
187 | |
Image(l) for l
|
188 | |
in self._db.select('photos',
|
189 | |
offset=offset * pp,
|
190 | |
limit=pp,
|
191 | |
order='id DESC')
|
| 188 |
Image(l)
|
| 189 |
for l in self._db.select(
|
| 190 |
"photos", offset=offset * pp, limit=pp, order="id DESC"
|
| 191 |
)
|
192 | 192 |
]
|
193 | 193 |
|
194 | 194 |
def get_all_photos_for_design(self, id):
|
195 | |
return list(Image(d.filename) for d in self._db.where('photos',
|
196 | |
design_id=id))
|
| 195 |
return list(Image(d.filename) for d in self._db.where("photos", design_id=id))
|
197 | 196 |
|
198 | 197 |
def get_all(self, offset=0):
|
199 | 198 |
ds = self._db.query(
|
200 | |
'''select d.title, d.description, d.id, c.name as cat_name,
|
| 199 |
"""select d.title, d.description, d.id, c.name as cat_name,
|
201 | 200 |
(select filename from photos where photos.design_id = d.id limit 1) as image
|
202 | 201 |
from designs d, categories c
|
203 | 202 |
where d.category = c.id
|
204 | 203 |
order by d.id desc
|
205 | |
limit $per_page offset $offset''',
|
| 204 |
limit $per_page offset $offset""",
|
206 | 205 |
vars={"per_page": PER_PAGE, "offset": offset},
|
207 | 206 |
)
|
208 | |
total = self._db.query('select count(*) as c from designs')
|
| 207 |
total = self._db.query("select count(*) as c from designs")
|
209 | 208 |
return Paginated.paginate(offset, total[0].c, Design.list(ds))
|
210 | 209 |
|
211 | 210 |
def get_designs_by_category(self, cat, offset=0):
|
212 | 211 |
ds = self._db.query(
|
213 | |
'''select d.title, d.description, d.id, c.name as cat_name,
|
| 212 |
"""select d.title, d.description, d.id, c.name as cat_name,
|
214 | 213 |
(select filename from photos where photos.design_id = d.id limit 1) as image
|
215 | 214 |
from designs d, categories c
|
216 | 215 |
where d.category = c.id
|
217 | 216 |
and c.name = $cat
|
218 | 217 |
order by d.id desc
|
219 | |
limit $per_page offset $offset''',
|
| 218 |
limit $per_page offset $offset""",
|
220 | 219 |
vars={"cat": cat, "per_page": PER_PAGE, "offset": offset},
|
221 | 220 |
)
|
222 | 221 |
total = self._db.query(
|
223 | |
'''select count(*) as c from designs d, categories c
|
224 | |
where d.category = c.id and c.name = $cat''',
|
225 | |
vars={"cat": cat})
|
| 222 |
"""select count(*) as c from designs d, categories c
|
| 223 |
where d.category = c.id and c.name = $cat""",
|
| 224 |
vars={"cat": cat},
|
| 225 |
)
|
226 | 226 |
return Paginated.paginate(offset, total[0].c, Design.list(ds))
|
227 | 227 |
|
228 | 228 |
def get_designs_by_category_and_tag(self, cat, tag, offset=0):
|
229 | 229 |
ds = self._db.query(
|
230 | |
'''select d.title, d.description, d.id, c.name as cat_name,
|
| 230 |
"""select d.title, d.description, d.id, c.name as cat_name,
|
231 | 231 |
(select filename from photos where photos.design_id = d.id limit 1) as image
|
232 | 232 |
from designs d, tags t, categories c
|
233 | 233 |
where t.tag_name = $tag
|
|
235 | 235 |
and c.name = $cat
|
236 | 236 |
and d.id = t.design_id
|
237 | 237 |
order by d.id desc
|
238 | |
limit $per_page offset $offset''',
|
239 | |
vars=dict(tag=tag,
|
240 | |
cat=cat,
|
241 | |
offset=offset * self.per_page,
|
242 | |
per_page=self.per_page))
|
| 238 |
limit $per_page offset $offset""",
|
| 239 |
vars=dict(
|
| 240 |
tag=tag, cat=cat, offset=offset * self.per_page, per_page=self.per_page
|
| 241 |
),
|
| 242 |
)
|
243 | 243 |
total = self._db.query(
|
244 | |
'''select count(*) as c from designs, tags, categories
|
| 244 |
"""select count(*) as c from designs, tags, categories
|
245 | 245 |
where designs.category = categories.id
|
246 | 246 |
and categories.name = $cat
|
247 | 247 |
and tags.tag_name = $tag
|
248 | |
and designs.id = tags.design_id''',
|
249 | |
vars=dict(tag=tag, cat=cat))
|
| 248 |
and designs.id = tags.design_id""",
|
| 249 |
vars=dict(tag=tag, cat=cat),
|
| 250 |
)
|
250 | 251 |
return Paginated.paginate(offset, total[0].c, Design.list(ds))
|
251 | 252 |
|
252 | 253 |
def new_design(self):
|
253 | |
new_id = self._db.query(
|
254 | |
'select max(id) as n from designs')[0].n + 1
|
| 254 |
new_id = self._db.query("select max(id) as n from designs")[0].n + 1
|
255 | 255 |
self._db.insert(
|
256 | |
'designs',
|
257 | |
id=new_id,
|
258 | |
title='New Design',
|
259 | |
description='',
|
260 | |
category=0)
|
| 256 |
"designs", id=new_id, title="New Design", description="", category=0
|
| 257 |
)
|
261 | 258 |
return new_id
|
262 | 259 |
|
263 | 260 |
def delete_design(self, id):
|
264 | |
self._db.delete(
|
265 | |
'designs',
|
266 | |
where='id = $id',
|
267 | |
vars=dict(id=id))
|
| 261 |
self._db.delete("designs", where="id = $id", vars=dict(id=id))
|
268 | 262 |
|
269 | 263 |
def add_file(self, file):
|
270 | |
new_id = (self._db.query('select max(id) as n from files')[0].n + 1)
|
| 264 |
new_id = self._db.query("select max(id) as n from files")[0].n + 1
|
271 | 265 |
extn = file.filename.split()[-1]
|
272 | |
name = '{0:05}.{1}'.format(new_id, extn)
|
273 | |
path = '/' + os.path.join('srv', 'http', 'frd',
|
274 | |
'static', 'files', name)
|
| 266 |
name = "{0:05}.{1}".format(new_id, extn)
|
| 267 |
path = "/" + os.path.join("srv", "http", "frd", "static", "files", name)
|
275 | 268 |
self.file_num = self.get_max_file_num() + 1
|
276 | |
with open(path, 'rb') as f:
|
| 269 |
with open(path, "rb") as f:
|
277 | 270 |
f.write(file.file)
|
278 | 271 |
return new_id
|
279 | 272 |
|
280 | 273 |
def all_files(self):
|
281 | |
return list(self._db.where(''))
|
| 274 |
return list(self._db.where(""))
|
282 | 275 |
|
283 | 276 |
def add_photo(self, file, d_id):
|
284 | 277 |
self.photo_num = self.get_max_photo_num() + 1
|
285 | |
new_id = (self._db.query(
|
286 | |
'select max(id) as n from photos')[0].n + 1)
|
| 278 |
new_id = self._db.query("select max(id) as n from photos")[0].n + 1
|
287 | 279 |
new_num = self.photo_num
|
288 | 280 |
self.photo_num += 1
|
289 | 281 |
extension = file.filename[-3:]
|
290 | |
name = '{0:05}.{1}'.format(new_num, extension)
|
291 | |
thumb = '{0:05}_thumb.{1}'.format(new_num, extension)
|
| 282 |
name = "{0:05}.{1}".format(new_num, extension)
|
| 283 |
thumb = "{0:05}_thumb.{1}".format(new_num, extension)
|
292 | 284 |
img = Image.open(file.file)
|
293 | 285 |
img.thumbnail((400, 400), Image.ANTIALIAS)
|
294 | |
img.save('/' + os.path.join('srv', 'http',
|
295 | |
'frd', 'static', 'photos', name))
|
| 286 |
img.save("/" + os.path.join("srv", "http", "frd", "static", "photos", name))
|
296 | 287 |
img.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
|
297 | |
img.save(os.path.join('static', 'photos', thumb))
|
298 | |
self._db.insert(
|
299 | |
'photos',
|
300 | |
id=new_id,
|
301 | |
filename=name,
|
302 | |
design_id=d_id)
|
| 288 |
img.save(os.path.join("static", "photos", thumb))
|
| 289 |
self._db.insert("photos", id=new_id, filename=name, design_id=d_id)
|
303 | 290 |
return new_id
|
304 | 291 |
|
305 | 292 |
def delete_photo(self, photo_name):
|
306 | 293 |
self._db.delete(
|
307 | |
'photos',
|
308 | |
where='filename = $filename',
|
309 | |
vars=dict(filename=photo_name))
|
| 294 |
"photos", where="filename = $filename", vars=dict(filename=photo_name)
|
| 295 |
)
|
310 | 296 |
|
311 | 297 |
def max_photo_page_ranges(self):
|
312 | |
num_designs = self._db.query(
|
313 | |
'select count(*) as n from photos')[0].n
|
| 298 |
num_designs = self._db.query("select count(*) as n from photos")[0].n
|
314 | 299 |
return (0, (num_designs // self.per_page))
|
315 | 300 |
|
316 | 301 |
def max_page_ranges(self):
|
317 | |
num_designs = self._db.query(
|
318 | |
'select count(*) as n from designs')[0].n
|
| 302 |
num_designs = self._db.query("select count(*) as n from designs")[0].n
|
319 | 303 |
return (0, (num_designs // self.per_page))
|
320 | 304 |
|
321 | 305 |
def max_page_range_for_category(self, cat):
|
322 | 306 |
cat_id = self.get_category_id(cat)
|
323 | 307 |
num_designs = self._db.query(
|
324 | |
'select count(*) as n from designs where category = $cat',
|
325 | |
vars=dict(cat=cat_id))[0].n
|
| 308 |
"select count(*) as n from designs where category = $cat",
|
| 309 |
vars=dict(cat=cat_id),
|
| 310 |
)[0].n
|
326 | 311 |
return (0, 1 + (num_designs // self.per_page))
|
327 | 312 |
|
328 | 313 |
def get_all_tags(self):
|
329 | 314 |
return [
|
330 | |
Tag(t.tag_name, t.n) for t in
|
331 | |
self._db.query('select t.tag_name, count(*) as n '
|
332 | |
'from designs d, tags t '
|
333 | |
'where d.id = t.design_id '
|
334 | |
'group by t.tag_name')
|
| 315 |
Tag(t.tag_name, t.n)
|
| 316 |
for t in self._db.query(
|
| 317 |
"select t.tag_name, count(*) as n "
|
| 318 |
"from designs d, tags t "
|
| 319 |
"where d.id = t.design_id "
|
| 320 |
"group by t.tag_name"
|
| 321 |
)
|
335 | 322 |
]
|
336 | 323 |
|
337 | 324 |
def get_designs_by_tag(self, tag, offset=0):
|
338 | 325 |
ds = self._db.query(
|
339 | |
'''select * from designs, tags
|
| 326 |
"""select * from designs, tags
|
340 | 327 |
where tags.tag_name = $tag
|
341 | 328 |
and designs.id = tags.design_id
|
342 | 329 |
order by designs.id desc
|
343 | |
limit $per_page offset $offset''',
|
344 | |
vars=dict(tag=tag,
|
345 | |
offset=offset * self.per_page,
|
346 | |
per_page=self.per_page))
|
347 | |
|
348 | |
return ((d.title,
|
349 | |
self.get_picture(d.design_id),
|
350 | |
d.description,
|
351 | |
self.get_category_name(d.category),
|
352 | |
d.design_id) for d in ds)
|
| 330 |
limit $per_page offset $offset""",
|
| 331 |
vars=dict(tag=tag, offset=offset * self.per_page, per_page=self.per_page),
|
| 332 |
)
|
| 333 |
|
| 334 |
return (
|
| 335 |
(
|
| 336 |
d.title,
|
| 337 |
self.get_picture(d.design_id),
|
| 338 |
d.description,
|
| 339 |
self.get_category_name(d.category),
|
| 340 |
d.design_id,
|
| 341 |
)
|
| 342 |
for d in ds
|
| 343 |
)
|
353 | 344 |
|
354 | 345 |
def get_tags_for_design(self, design_id):
|
355 | 346 |
return [
|
356 | |
t.tag_name for t in
|
357 | |
self._db.select(
|
358 | |
'tags',
|
359 | |
what='tag_name',
|
360 | |
where='design_id = $d_id',
|
361 | |
vars=dict(d_id=design_id))]
|
| 347 |
t.tag_name
|
| 348 |
for t in self._db.select(
|
| 349 |
"tags",
|
| 350 |
what="tag_name",
|
| 351 |
where="design_id = $d_id",
|
| 352 |
vars=dict(d_id=design_id),
|
| 353 |
)
|
| 354 |
]
|
362 | 355 |
|
363 | 356 |
def process_tag_list(self, design_id, tag_string):
|
364 | 357 |
new_tag_id = (
|
365 | |
lambda: (self._db.query(
|
366 | |
'select max(id) as n from tags')[0].n or 0) + 1)
|
| 358 |
lambda: (self._db.query("select max(id) as n from tags")[0].n or 0) + 1
|
| 359 |
)
|
367 | 360 |
tag_list = tag_string.lower().split()
|
368 | |
self._db.delete(
|
369 | |
'tags', where='design_id = $d_id',
|
370 | |
vars=dict(d_id=design_id))
|
| 361 |
self._db.delete("tags", where="design_id = $d_id", vars=dict(d_id=design_id))
|
371 | 362 |
for t in tag_list:
|
372 | |
self._db.insert(
|
373 | |
'tags',
|
374 | |
id=new_tag_id(),
|
375 | |
tag_name=t,
|
376 | |
design_id=design_id)
|
| 363 |
self._db.insert("tags", id=new_tag_id(), tag_name=t, design_id=design_id)
|
377 | 364 |
|
378 | 365 |
def max_page_range_for_tag(self, tag):
|
379 | 366 |
num_designs = self._db.query(
|
380 | |
'select count(*) as n from tags where tag_name = $t',
|
381 | |
vars=dict(t=tag))[0].n
|
| 367 |
"select count(*) as n from tags where tag_name = $t", vars=dict(t=tag)
|
| 368 |
)[0].n
|
382 | 369 |
return (0, (num_designs // self.per_page))
|
383 | 370 |
|
384 | 371 |
def num_for_tag(self, tag):
|
385 | 372 |
return self._db.query(
|
386 | |
'select count(*) as n from tags where tag_name = $t',
|
387 | |
vars={'t': tag})[0].n
|
| 373 |
"select count(*) as n from tags where tag_name = $t", vars={"t": tag}
|
| 374 |
)[0].n
|
388 | 375 |
|
389 | 376 |
def get_about_text(self):
|
390 | |
return self._db.where('pages', name='about')[0].text
|
| 377 |
return self._db.where("pages", name="about")[0].text
|
391 | 378 |
|
392 | 379 |
def set_about_text(self, text):
|
393 | |
self._db.update('pages', where='name = \'about\'',
|
394 | |
text=text)
|
| 380 |
self._db.update("pages", where="name = 'about'", text=text)
|
395 | 381 |
|
396 | 382 |
def get_page_list(self):
|
397 | |
return self._db.query('select * from pages')
|
| 383 |
return self._db.query("select * from pages")
|
398 | 384 |
|
399 | 385 |
def add_page(self, name, title):
|
400 | |
self._db.insert('pages', name=name, title=title, text='')
|
| 386 |
self._db.insert("pages", name=name, title=title, text="")
|
401 | 387 |
|
402 | 388 |
def get_page(self, name):
|
403 | |
pg = list(self._db.where('pages', name=name))
|
| 389 |
pg = list(self._db.where("pages", name=name))
|
404 | 390 |
if pg:
|
405 | 391 |
return pg[0]
|
406 | 392 |
else:
|
407 | |
raise Exception('No page named {0}'.format(name))
|
| 393 |
raise Exception("No page named {0}".format(name))
|
408 | 394 |
|
409 | 395 |
def set_page(self, name, title, text):
|
410 | |
self._db.update('pages',
|
411 | |
where='name = $name',
|
412 | |
title=title,
|
413 | |
text=text,
|
414 | |
vars={'name': name})
|
| 396 |
self._db.update(
|
| 397 |
"pages", where="name = $name", title=title, text=text, vars={"name": name}
|
| 398 |
)
|
415 | 399 |
|
416 | 400 |
def get_clacker(self, new_visitor=None):
|
417 | 401 |
if new_visitor is not None:
|
418 | 402 |
exists = self._db.query(
|
419 | |
'select count(*) as n from visits where visitor = $v',
|
420 | |
vars={'v': new_visitor})[0].n
|
| 403 |
"select count(*) as n from visits where visitor = $v",
|
| 404 |
vars={"v": new_visitor},
|
| 405 |
)[0].n
|
421 | 406 |
else:
|
422 | 407 |
exists = 1
|
423 | |
total = self._db.query('select count(*) as n from visits')[0].n
|
| 408 |
total = self._db.query("select count(*) as n from visits")[0].n
|
424 | 409 |
if exists == 0 and new_visitor:
|
425 | |
self._db.insert('visits',
|
426 | |
visitor=new_visitor)
|
| 410 |
self._db.insert("visits", visitor=new_visitor)
|
427 | 411 |
return total + 1
|
428 | 412 |
else:
|
429 | 413 |
return total
|