autopep8
Getty Ritter
4 years ago
11 | 11 | |
12 | 12 | app = flask.Flask(__name__) |
13 | 13 | |
14 | ||
14 | 15 | class Templates: |
15 | 16 | renderer = pystache.Renderer() |
16 | 17 | |
22 | 23 | main = load_template('main') |
23 | 24 | design_page = load_template('design_page') |
24 | 25 | design_tile = load_template('design_tile') |
26 | ||
25 | 27 | |
26 | 28 | def slugify(string): |
27 | 29 | def process(char): |
116 | 118 | page < max)) |
117 | 119 | |
118 | 120 | |
119 | ||
120 | 121 | @app.route('/category/') |
121 | 122 | @main |
122 | 123 | def get_all_categories(): |
123 | 124 | categories = db.all_categories() |
124 | 125 | return 'Category', render.select_category(categories) |
126 | ||
125 | 127 | |
126 | 128 | @app.route('/category/<cat>/') |
127 | 129 | @main |
138 | 140 | page > min, |
139 | 141 | page < (max - 1))) |
140 | 142 | |
143 | ||
141 | 144 | @app.route('/category/<cat>/tag/<tag>/') |
142 | 145 | @main |
143 | 146 | def get_category_with_tag(cat, tag): |
157 | 160 | @app.route('/tag/') |
158 | 161 | @main |
159 | 162 | def get_all_tags(): |
160 | pretty = lambda t: ' '.join(w.capitalize() | |
161 | for w in t.split('_')) | |
163 | def pretty(t): return ' '.join(w.capitalize() | |
164 | for w in t.split('_')) | |
162 | 165 | tags = ( |
163 | 166 | (t, pretty(t), db.num_for_tag(t)) |
164 | 167 | for t in sorted(db.get_all_tags())) |
165 | 168 | return 'All Tags', render.select_tag(tags) |
169 | ||
166 | 170 | |
167 | 171 | @app.route('/tag/<tag>/') |
168 | 172 | @main |
4 | 4 | from PIL import Image |
5 | 5 | |
6 | 6 | import typing |
7 | ||
7 | 8 | |
8 | 9 | def slugify(string): |
9 | 10 | def process(char): |
22 | 23 | def thumb(self): |
23 | 24 | return self.image[:-4] + '_thumb' + self.image[-4:] |
24 | 25 | |
26 | ||
25 | 27 | class PageContent: |
26 | 28 | def __init__(self, source): |
27 | 29 | self.source = source |
34 | 36 | return self.source |
35 | 37 | else: |
36 | 38 | return self.source[:256] + '...' |
39 | ||
37 | 40 | |
38 | 41 | class Design(typing.NamedTuple): |
39 | 42 | title: str |
52 | 55 | if self.images: |
53 | 56 | return self.images[0].thumb() |
54 | 57 | |
58 | ||
55 | 59 | THUMB_SIZE = (100, 100) |
60 | ||
56 | 61 | |
57 | 62 | class DB: |
58 | 63 |