Start to convert design tile
Getty Ritter
4 years ago
21 | 21 |
|
22 | 22 |
main = load_template('main')
|
23 | 23 |
design_page = load_template('design_page')
|
| 24 |
design_tile = load_template('design_tile')
|
24 | 25 |
|
25 | 26 |
def slugify(string):
|
26 | 27 |
def process(char):
|
|
49 | 50 |
all_categories=db.all_categories,
|
50 | 51 |
thumb=thumb,
|
51 | 52 |
five=five))
|
52 | |
|
53 | |
concat = '\n'.join
|
54 | 53 |
|
55 | 54 |
|
56 | 55 |
def snip(text):
|
|
110 | 109 |
data = db.get_all(offset=page)
|
111 | 110 |
return ('Designs',
|
112 | 111 |
render.design_list(
|
113 | |
(render.design_tile(name, pics, snip(desc), id)
|
114 | |
for name, pics, desc, cat, id in data),
|
| 112 |
(Templates.design_tile(d) for d in data),
|
115 | 113 |
page,
|
116 | 114 |
max,
|
117 | 115 |
page > min,
|
4 | 4 |
from PIL import Image
|
5 | 5 |
|
6 | 6 |
import typing
|
| 7 |
|
| 8 |
def slugify(string):
|
| 9 |
def process(char):
|
| 10 |
if char in '- \n\t\f':
|
| 11 |
return '-'
|
| 12 |
elif char.isalpha():
|
| 13 |
return char.lower()
|
| 14 |
else:
|
| 15 |
return ''
|
| 16 |
return ''.join(process(c) for c in string)[:40]
|
| 17 |
|
7 | 18 |
|
8 | 19 |
class Image(typing.NamedTuple):
|
9 | 20 |
image: str
|
|
30 | 41 |
description: PageContent
|
31 | 42 |
category: str
|
32 | 43 |
id: int
|
| 44 |
|
| 45 |
def id_str(self):
|
| 46 |
return f"{self.id:05}"
|
| 47 |
|
| 48 |
def slug(self):
|
| 49 |
return slugify(self.title)
|
| 50 |
|
| 51 |
def thumbnail(self):
|
| 52 |
if self.images:
|
| 53 |
return self.images[0].thumb()
|
33 | 54 |
|
34 | 55 |
THUMB_SIZE = (100, 100)
|
35 | 56 |
|
|
99 | 120 |
|
100 | 121 |
def get_picture(self, id):
|
101 | 122 |
try:
|
102 | |
return (self._db.where('photos', design_id=id,
|
103 | |
limit=1))[0].filename
|
| 123 |
return Image((self._db.where('photos', design_id=id,
|
| 124 |
limit=1))[0].filename)
|
104 | 125 |
except:
|
105 | 126 |
return None
|
106 | 127 |
|
|
126 | 147 |
offset=offset * self.per_page,
|
127 | 148 |
limit=pp,
|
128 | 149 |
order='id DESC'))
|
129 | |
return ((d.title,
|
130 | |
self.get_picture(d.id),
|
131 | |
d.description,
|
132 | |
self.get_category_name(d.category),
|
133 | |
d.id) for d in ds)
|
| 150 |
return (Design(title=d.title,
|
| 151 |
images=[self.get_picture(d.id)],
|
| 152 |
description=PageContent(d.description),
|
| 153 |
category=self.get_category_name(d.category),
|
| 154 |
id=d.id) for d in ds)
|
134 | 155 |
|
135 | 156 |
def get_new_charts(self, pp):
|
136 | 157 |
ds = list(self._db.select('designs',
|