gdritter repos frony-ritter-designs / 39d45fa
A nicer tag interface Getty Ritter 3 years ago
7 changed file(s) with 35 addition(s) and 43 deletion(s). Collapse all Expand all
175175 {
176176 "id": design.visible_id,
177177 "title": design.title,
178 "tags": " ".join(t.tag_name for t in design.tags),
178 "tags": design.tags,
179 "all_tags": model.Tag.select(model.Tag.tag_name)
180 .distinct()
181 .order_by(model.Tag.tag_name),
179182 "categories": design.category_list(),
180183 "description": design.description,
181184 "photos": ({"image": d} for d in design.photos),
288291 def do_edit_page(slug):
289292 text = flask.request.form.get("text", "")
290293 title = flask.request.form.get("title", slug.capitalize())
291 model.Page.update(title=title, text=text).where(model.Page.name==slug).execute()
294 model.Page.update(title=title, text=text).where(model.Page.name == slug).execute()
292295 return flask.redirect(f"/edit/pages/{slug}")
293296
294297
11 import woofmark from 'woofmark';
22 import megamark from 'megamark';
3 import Tagify from '@yaireo/tagify';
34
45 window.onload = () => {
6 let input = document.querySelector('.tag_input');
7 if (input) {
8 let tags = new Tagify(input);
9 }
10
511 let woof = woofmark(document.getElementById("editor"), {
612 parseMarkdown: megamark,
713 html: false,
55
66 db = peewee.SqliteDatabase("new.db")
77 PER_PAGE = 16
8
89
910 def slugify(string):
1011 def process(char):
2930
3031 @classmethod
3132 def all(klass):
32 elements = ({"url": f"/category/{c.name}", "name": c.nicename} for c in klass.select())
33 elements = (
34 {"url": f"/category/{c.name}", "name": c.nicename} for c in klass.select()
35 )
3336 return {"elements": elements}
3437
3538
4346 return markdown.markdown(self.description)
4447
4548 def id_str(self):
46 return f'{self.visible_id:05}'
49 return f"{self.visible_id:05}"
4750
4851 def slug(self):
4952 return slugify(self.title)
5760
5861 def category_list(self):
5962 categories = Category.select()
60 return [
61 {"name": c.name, "selected": c == self.category}
62 for c in categories
63 ]
63 return [{"name": c.name, "selected": c == self.category} for c in categories]
6464
6565 def to_json(self):
6666 return {
8686 @classmethod
8787 def get_all(klass, page=0):
8888 designs = klass.select().paginate(page, PER_PAGE)
89 return Paginated.paginate(
90 page,
91 klass.select().count(),
92 designs,
93 )
89 return Paginated.paginate(page, klass.select().count(), designs,)
9490
9591 @classmethod
9692 def get_where(klass, *, tag=None, category=None, page=0):
10197 query = query.switch(klass).join(Category).where(Category.name == category)
10298 query = query.group_by(klass).order_by(klass.id)
10399 designs = query.paginate(page, PER_PAGE)
104 return Paginated.paginate(
105 page,
106 query.count(),
107 designs,
108 )
100 return Paginated.paginate(page, query.count(), designs,)
109101
110102
111103 class Photo(Model):
131123
132124 @classmethod
133125 def all(klass):
134 elements = ({"url": f"/tag/{t.tag_name}", "name": t.tag_name} for t in klass.select(klass.tag_name).distinct().order_by(klass.tag_name))
126 elements = (
127 {"url": f"/tag/{t.tag_name}", "name": t.tag_name}
128 for t in klass.select(klass.tag_name).distinct().order_by(klass.tag_name)
129 )
135130 return {"elements": elements}
136
137131
138132
139133 class PageRef(typing.NamedTuple):
171165 # prev_page: typing.Optional[dict]
172166 # last_page: int
173167 # contents: typing.List[Design]
174
66 "author": "Getty Ritter <gettylefou@gmail.com>",
77 "license": "MIT",
88 "dependencies": {
9 "@yaireo/tagify": "^4.0.5",
910 "cash-dom": "^8.1.0",
1011 "easymde": "^2.12.1",
1112 "megamark": "^3.3.0",
12 "tagify": "^0.1.1",
1313 "woofmark": "^4.2.6"
1414 },
1515 "scripts": {
1919 <div class="edittile taglist">
2020 <label>Tags</label><br>
2121 <div class="tags">
22 <input type="text" name="tags"/>
22 <input class="tag_input" type="text" name="tags"
23 value="{{#tags}}{{tag_name}},{{/tags}}"
24 data-whitelist="{{#all_tags}}{{tag_name}},{{/all_tags}}"
25 />
2326 </div>
2427 </div>
2528 <div class="edittile">
1414 <meta http-equiv="Content-Type" contents="application/xhtml+xml; charset=utf-8;" />
1515 <meta name="description" content="Cross-Stitch Patterns and Other Crafts from Frony Ritter Designs" />
1616 <link rel="stylesheet" type="text/css" href="/static/standard.css" />
17 <link rel="stylesheet" type="text/css" href="/static/tagify.css" />
1718 <title>Frony Ritter Designs &ndash; {{title}}</title>
1819 </head>
1920 <body>
7980 <div style="clear: both;"></div>
8081 </div>
8182 <div class="nav bottom">
82 <span class="text"> &copy;2020 Frony Ritter Designs</span> <a href="/about/">About</a> <a href="/contact/">Contact</a>
83 <span class="text"> &copy;2021 Frony Ritter Designs</span> <a href="/about/">About</a> <a href="/contact/">Contact</a>
8384 </div>
8485 </div>
8586 </body>
976976 resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
977977 integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
978978
979 "@yaireo/tagify@^4.0.5":
980 version "4.0.5"
981 resolved "https://registry.yarnpkg.com/@yaireo/tagify/-/tagify-4.0.5.tgz#476bbbeaa08d53f6cc469b6309ea1540dbdad2a8"
982 integrity sha512-HCIn2bCQ114SBDHafUR+jDutKFDbxDIjlWygg3eQBVpmJIcavKdYX6MdW5Jeh0QEcuDP4Ihby9QnZVNbv3z43Q==
983
979984 acorn@^6.4.1:
980985 version "6.4.1"
981986 resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.1.tgz#531e58ba3f51b9dacb9a6646ca4debf5b14ca474"
29852990 dependencies:
29862991 wrappy "1"
29872992
2988 optimist@~0.3:
2989 version "0.3.7"
2990 resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.3.7.tgz#c90941ad59e4273328923074d2cf2e7cbc6ec0d9"
2991 integrity sha1-yQlBrVnkJzMokjB00s8ufLxuwNk=
2992 dependencies:
2993 wordwrap "~0.0.2"
2994
29952993 os-browserify@^0.3.0:
29962994 version "0.3.0"
29972995 resolved "https://registry.yarnpkg.com/os-browserify/-/os-browserify-0.3.0.tgz#854373c7f5c2315914fc9bfc6bd8238fdda1ec27"
37343732 integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==
37353733 dependencies:
37363734 has-flag "^3.0.0"
3737
3738 tagify@^0.1.1:
3739 version "0.1.1"
3740 resolved "https://registry.yarnpkg.com/tagify/-/tagify-0.1.1.tgz#bcd42738a27fc0915e2dd070137859541861a4bc"
3741 integrity sha1-vNQnOKJ/wJFeLdBwE3hZVBhhpLw=
3742 dependencies:
3743 optimist "~0.3"
37443735
37453736 tapable@^1.0.0, tapable@^1.1.3:
37463737 version "1.1.3"
40574048 local-storage "1.4.2"
40584049 seleccion "2.0.0"
40594050
4060 wordwrap@~0.0.2:
4061 version "0.0.3"
4062 resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"
4063 integrity sha1-o9XabNXAvAAI03I0u68b7WMFkQc=
4064
40654051 worker-farm@^1.7.0:
40664052 version "1.7.0"
40674053 resolved "https://registry.yarnpkg.com/worker-farm/-/worker-farm-1.7.0.tgz#26a94c5391bbca926152002f69b84a4bf772e5a8"