28 | 28 |
|
29 | 29 |
main = load_template("main")
|
30 | 30 |
design_page = load_template("design_page")
|
31 | |
design_tile = load_template("design_tile")
|
32 | 31 |
design_list = load_template("design_list")
|
33 | 32 |
text_list = load_template("text_list")
|
34 | |
|
35 | |
|
36 | |
def slugify(string):
|
37 | |
def process(char):
|
38 | |
if char in "- \n\t\f":
|
39 | |
return "-"
|
40 | |
elif char.isalpha():
|
41 | |
return char.lower()
|
42 | |
else:
|
43 | |
return ""
|
44 | |
|
45 | |
return "".join(process(c) for c in string)[:40]
|
46 | 33 |
|
47 | 34 |
|
48 | 35 |
def thumb(img):
|
|
58 | 45 |
"old_templates/",
|
59 | 46 |
globals=dict(
|
60 | 47 |
markdown=markdown.markdown,
|
61 | |
slugify=slugify,
|
| 48 |
slugify=storage.slugify,
|
62 | 49 |
all_categories=db.all_categories,
|
63 | 50 |
thumb=thumb,
|
64 | 51 |
five=five,
|
|
66 | 53 |
)
|
67 | 54 |
|
68 | 55 |
|
69 | |
def snip(text):
|
70 | |
if len(text) < 256:
|
71 | |
return text
|
72 | |
else:
|
73 | |
return text[:256] + "..."
|
74 | |
|
75 | |
|
76 | 56 |
def main(func):
|
77 | 57 |
def new_func(*args, **kwargs):
|
78 | 58 |
title, content = func(*args, **kwargs)
|
|
91 | 71 |
|
92 | 72 |
@app.route("/design/<id>/<slug>/")
|
93 | 73 |
@main
|
94 | |
def get_design(id, slug=None):
|
| 74 |
def get_design(id, _slug=None):
|
95 | 75 |
design = db.get_design(int(id))
|
96 | 76 |
return "Designs", Templates.design_page(design)
|
97 | 77 |
|
|
122 | 102 |
def get_all_designs():
|
123 | 103 |
page = int(flask.request.args.get("page") or 0)
|
124 | 104 |
data = db.get_all(page)
|
125 | |
return ("Designs", Templates.design_list(data))
|
| 105 |
return "Designs", Templates.design_list(data)
|
126 | 106 |
|
127 | 107 |
|
128 | 108 |
@app.route("/category/")
|
|
137 | 117 |
def get_category(cat):
|
138 | 118 |
page = int(flask.request.args.get("page") or 0)
|
139 | 119 |
data = db.get_designs_by_category(cat, page)
|
140 | |
return (cat.capitalize(), Templates.design_list(data))
|
| 120 |
return cat.capitalize(), Templates.design_list(data)
|
141 | 121 |
|
142 | 122 |
|
143 | 123 |
@app.route("/category/<cat>/tag/<tag>/")
|
|
145 | 125 |
def get_category_with_tag(cat, tag):
|
146 | 126 |
page = int(flask.request.args.get("page") or 0)
|
147 | 127 |
data = db.get_designs_by_category_and_tag(cat, tag, page)
|
148 | |
return (cat.capitalize(), Templates.design_list(data))
|
| 128 |
return cat.capitalize(), Templates.design_list(data)
|
149 | 129 |
|
150 | 130 |
|
151 | 131 |
@app.route("/tag/")
|
152 | 132 |
@main
|
153 | 133 |
def get_all_tags():
|
154 | |
tags = ((t.tag, t.pretty(), t.count) for t in sorted(db.get_all_tags()))
|
155 | |
return "All Tags", render.select_tag(tags)
|
| 134 |
tags = db.get_all_tags()
|
| 135 |
return "All Tags", Templates.text_list(tags)
|
156 | 136 |
|
157 | 137 |
|
158 | 138 |
@app.route("/tag/<tag>/")
|
|
161 | 141 |
page = int(flask.request.args.get("page") or 0)
|
162 | 142 |
data = db.get_designs_by_tag(tag, page)
|
163 | 143 |
pretty_tag = " ".join(w.capitalize() for w in tag.split("_"))
|
164 | |
return (pretty_tag, Templates.design_list(data))
|
| 144 |
return pretty_tag, Templates.design_list(data)
|
165 | 145 |
|
166 | 146 |
|
167 | 147 |
@app.route("/<name>/")
|
168 | 148 |
@main
|
169 | 149 |
def get_page(name):
|
170 | 150 |
page = db.get_page(name)
|
171 | |
return (page.title, markdown.markdown(page.text))
|
| 151 |
return page.title, markdown.markdown(page.text)
|
172 | 152 |
|
173 | 153 |
|
174 | 154 |
# class admin:
|