gdritter repos frony-ritter-designs / 57b026c
Change some things from typed tuples to dataclasses Getty Ritter 4 years ago
2 changed file(s) with 13 addition(s) and 18 deletion(s). Collapse all Expand all
3333 text_list = load_template("text_list")
3434
3535 edit_design_list = load_template("edit_design_list")
36
37
38 def thumb(img):
39 return img.thumb()
40
41
42 def five(n):
43 return "{0:05}".format(n)
4436
4537
4638 db = storage.DB()
5042 markdown=markdown.markdown,
5143 slugify=storage.slugify,
5244 all_categories=db.all_categories,
53 thumb=thumb,
54 five=five,
5545 ),
5646 )
5747
1 from dataclasses import dataclass
12 import markdown
23 import os
34 import web
4041 else:
4142 return self.source[:256] + "..."
4243
43
44 class PageRef(typing.NamedTuple):
44 @dataclass
45 class PageRef:
4546 page: int
4647
4748 def __iter__(self):
4849 return [self]
4950
50
51 class Design(typing.NamedTuple):
51 @dataclass
52 class Design:
5253 title: str
5354 images: typing.List[Image]
5455 description: PageContent
8990 ]
9091
9192
92 class Paginated(typing.NamedTuple):
93 @dataclass
94 class Paginated:
9395 next_page: typing.Optional[dict]
9496 prev_page: typing.Optional[dict]
9597 last_page: int
110112 )
111113
112114
113 class Tag(typing.NamedTuple):
115 @dataclass
116 class Tag:
114117 tag: str
115118 count: int
116119
118121 return " ".join(w.capitalize() for w in self.tag.split())
119122
120123
121 class Link(typing.NamedTuple):
124 @dataclass
125 class Link:
122126 url: str
123127 name: str
124128
132136 return cls(name=f"{nicename} ({t.n})", url=f"/tag/{t.tag_name}")
133137
134138
135 class LinkList(typing.NamedTuple):
139 @dataclass
140 class LinkList:
136141 elements: typing.List[Link]
137142
138143