| 46 | 46 |
return [self]
|
| 47 | 47 |
|
| 48 | 48 |
|
| 49 | |
class Rendered(typing.NamedTuple):
|
| 50 | |
rendered: str
|
| 51 | |
|
| 52 | |
|
| 53 | 49 |
class Design(typing.NamedTuple):
|
| 54 | 50 |
title: str
|
| 55 | 51 |
images: typing.List[Image]
|
|
| 66 | 62 |
def thumbnail(self):
|
| 67 | 63 |
if self.images:
|
| 68 | 64 |
return self.images[0].thumb()
|
| 65 |
|
| 66 |
@classmethod
|
| 67 |
def list(cls, query_results) -> typing.List['Design']:
|
| 68 |
return [
|
| 69 |
cls(
|
| 70 |
title=d.title,
|
| 71 |
images=[Image(d.image)],
|
| 72 |
description=d.description,
|
| 73 |
category=d.cat_name,
|
| 74 |
id=d.id,
|
| 75 |
) for d in query_results]
|
| 69 | 76 |
|
| 70 | 77 |
|
| 71 | 78 |
class Paginated(typing.NamedTuple):
|
|
| 201 | 208 |
category=self.get_category_name(d.category),
|
| 202 | 209 |
id=d.id) for d in ds)
|
| 203 | 210 |
|
| 204 | |
def get_new_charts(self, pp):
|
| 205 | |
ds = list(self._db.select('designs',
|
| 206 | |
where='category = 8',
|
| 207 | |
limit=pp,
|
| 208 | |
order='id DESC'))
|
| 209 | |
return ((d.title,
|
| 210 | |
self.get_picture(d.id),
|
| 211 | |
d.description,
|
| 212 | |
self.get_category_name(d.category),
|
| 213 | |
d.id) for d in ds)
|
| 214 | |
|
| 215 | 211 |
def get_designs_by_category(self, cat, offset=0):
|
| 216 | |
cat = self.get_category_id(cat)
|
| 217 | |
ds = self._db.where('designs',
|
| 218 | |
category=cat,
|
| 219 | |
offset=offset * self.per_page,
|
| 220 | |
limit=self.per_page,
|
| 221 | |
order='id DESC')
|
| 222 | |
return ((d.title,
|
| 223 | |
self.get_picture(d.id),
|
| 224 | |
d.description,
|
| 225 | |
cat,
|
| 226 | |
d.id) for d in ds)
|
| 212 |
ds = self._db.query(
|
| 213 |
'''select d.title, d.description, d.id, c.name as cat_name,
|
| 214 |
(select filename from photos where photos.design_id = d.id limit 1) as image
|
| 215 |
from designs d, categories c
|
| 216 |
where d.category = c.id
|
| 217 |
and c.name = $cat
|
| 218 |
order by d.id desc
|
| 219 |
limit $per_page offset $offset''',
|
| 220 |
vars={"cat": cat, "per_page": PER_PAGE, "offset": offset},
|
| 221 |
)
|
| 222 |
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})
|
| 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(
|
|
| 247 | 247 |
and tags.tag_name = $tag
|
| 248 | 248 |
and designs.id = tags.design_id''',
|
| 249 | 249 |
vars=dict(tag=tag, cat=cat))
|
| 250 | |
contents = [
|
| 251 | |
Design(
|
| 252 | |
title=d.title,
|
| 253 | |
images=[Image(d.image)],
|
| 254 | |
description=d.description,
|
| 255 | |
category=d.cat_name,
|
| 256 | |
id=d.id)
|
| 257 | |
for d in ds]
|
| 258 | |
return Paginated.paginate(offset, total[0].c, contents)
|
| 250 |
return Paginated.paginate(offset, total[0].c, Design.list(ds))
|
| 259 | 251 |
|
| 260 | 252 |
def new_design(self):
|
| 261 | 253 |
new_id = self._db.query(
|