| 21 | 21 |
image: str
|
| 22 | 22 |
|
| 23 | 23 |
def thumb(self):
|
| 24 |
print(self.image)
|
| 24 | 25 |
return self.image[:-4] + '_thumb' + self.image[-4:]
|
| 25 | 26 |
|
| 26 | 27 |
|
|
| 37 | 38 |
else:
|
| 38 | 39 |
return self.source[:256] + '...'
|
| 39 | 40 |
|
| 41 |
class PageRef(typing.NamedTuple):
|
| 42 |
page: int
|
| 43 |
|
| 44 |
class Rendered(typing.NamedTuple):
|
| 45 |
rendered: str
|
| 40 | 46 |
|
| 41 | 47 |
class Design(typing.NamedTuple):
|
| 42 | 48 |
title: str
|
|
| 55 | 61 |
if self.images:
|
| 56 | 62 |
return self.images[0].thumb()
|
| 57 | 63 |
|
| 64 |
class Paginated(typing.NamedTuple):
|
| 65 |
next_page: typing.Optional[PageRef]
|
| 66 |
prev_page: typing.Optional[PageRef]
|
| 67 |
last_page: int
|
| 68 |
contents: typing.List[Design]
|
| 69 |
|
| 58 | 70 |
class Tag(typing.NamedTuple):
|
| 59 | 71 |
tag: str
|
| 60 | 72 |
count: int
|
|
| 68 | 80 |
class DB:
|
| 69 | 81 |
|
| 70 | 82 |
def __init__(self, per_page=16):
|
| 71 | |
self._db = web.database(dbn='sqlite',
|
| 72 | |
db='frony.db')
|
| 83 |
self._db = web.database(dbn='sqlite', db='frony.db')
|
| 73 | 84 |
self.per_page = per_page
|
| 74 | 85 |
self.categories = {}
|
| 75 | 86 |
self.photo_num = self.get_max_photo_num() + 1
|
|
| 189 | 200 |
d.id) for d in ds)
|
| 190 | 201 |
|
| 191 | 202 |
def get_designs_by_category_and_tag(self, cat, tag, offset=0):
|
| 192 | |
cid = self.get_category_id(cat)
|
| 193 | 203 |
ds = self._db.query(
|
| 194 | |
'''select * from designs, tags
|
| 195 | |
where tags.tag_name = $tag
|
| 196 | |
and category=$cat
|
| 197 | |
and designs.id = tags.design_id
|
| 198 | |
order by designs.id desc
|
| 204 |
'''select d.title, d.description, d.id, c.name as cat_name,
|
| 205 |
(select filename from photos where photos.design_id = d.id limit 1) as image
|
| 206 |
from designs d, tags t, categories c
|
| 207 |
where t.tag_name = $tag
|
| 208 |
and d.category=c.id
|
| 209 |
and c.name = $cat
|
| 210 |
and d.id = t.design_id
|
| 211 |
order by d.id desc
|
| 199 | 212 |
limit $per_page offset $offset''',
|
| 200 | 213 |
vars=dict(tag=tag,
|
| 201 | |
cat=cid,
|
| 214 |
cat=cat,
|
| 202 | 215 |
offset=offset * self.per_page,
|
| 203 | 216 |
per_page=self.per_page))
|
| 204 | 217 |
|
| 205 | |
return ((d.title,
|
| 206 | |
self.get_picture(d.design_id),
|
| 207 | |
d.description,
|
| 208 | |
cat,
|
| 209 | |
d.design_id) for d in ds)
|
| 218 |
last_page=0
|
| 219 |
return Paginated(
|
| 220 |
next_page=None,
|
| 221 |
prev_page=None,
|
| 222 |
last_page=last_page,
|
| 223 |
contents=[
|
| 224 |
Design(
|
| 225 |
title=d.title,
|
| 226 |
images=[Image(d.image)],
|
| 227 |
description=d.description,
|
| 228 |
category=d.cat_name,
|
| 229 |
id=d.id)
|
| 230 |
for d in ds],
|
| 231 |
)
|
| 210 | 232 |
|
| 211 | 233 |
def new_design(self):
|
| 212 | 234 |
new_id = self._db.query(
|