gdritter repos frony-ritter-designs / 8cabf56
Start to convert design tile Getty Ritter 4 years ago
2 changed file(s) with 30 addition(s) and 11 deletion(s). Collapse all Expand all
2121
2222 main = load_template('main')
2323 design_page = load_template('design_page')
24 design_tile = load_template('design_tile')
2425
2526 def slugify(string):
2627 def process(char):
4950 all_categories=db.all_categories,
5051 thumb=thumb,
5152 five=five))
52
53 concat = '\n'.join
5453
5554
5655 def snip(text):
110109 data = db.get_all(offset=page)
111110 return ('Designs',
112111 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),
115113 page,
116114 max,
117115 page > min,
44 from PIL import Image
55
66 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
718
819 class Image(typing.NamedTuple):
920 image: str
3041 description: PageContent
3142 category: str
3243 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()
3354
3455 THUMB_SIZE = (100, 100)
3556
99120
100121 def get_picture(self, id):
101122 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)
104125 except:
105126 return None
106127
126147 offset=offset * self.per_page,
127148 limit=pp,
128149 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)
134155
135156 def get_new_charts(self, pp):
136157 ds = list(self._db.select('designs',