Change some things from typed tuples to dataclasses
Getty Ritter
5 years ago
| 33 | 33 | text_list = load_template("text_list") |
| 34 | 34 | |
| 35 | 35 | 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) | |
| 44 | 36 | |
| 45 | 37 | |
| 46 | 38 | db = storage.DB() |
| 50 | 42 | markdown=markdown.markdown, |
| 51 | 43 | slugify=storage.slugify, |
| 52 | 44 | all_categories=db.all_categories, |
| 53 | thumb=thumb, | |
| 54 | five=five, | |
| 55 | 45 | ), |
| 56 | 46 | ) |
| 57 | 47 | |
| 1 | from dataclasses import dataclass | |
| 1 | 2 | import markdown |
| 2 | 3 | import os |
| 3 | 4 | import web |
| 40 | 41 | else: |
| 41 | 42 | return self.source[:256] + "..." |
| 42 | 43 | |
| 43 | ||
| 44 | class PageRef(typing.NamedTuple): | |
| 44 | @dataclass | |
| 45 | class PageRef: | |
| 45 | 46 | page: int |
| 46 | 47 | |
| 47 | 48 | def __iter__(self): |
| 48 | 49 | return [self] |
| 49 | 50 | |
| 50 | ||
| 51 | class Design(typing.NamedTuple): | |
| 51 | @dataclass | |
| 52 | class Design: | |
| 52 | 53 | title: str |
| 53 | 54 | images: typing.List[Image] |
| 54 | 55 | description: PageContent |
| 89 | 90 | ] |
| 90 | 91 | |
| 91 | 92 | |
| 92 | class Paginated(typing.NamedTuple): | |
| 93 | @dataclass | |
| 94 | class Paginated: | |
| 93 | 95 | next_page: typing.Optional[dict] |
| 94 | 96 | prev_page: typing.Optional[dict] |
| 95 | 97 | last_page: int |
| 110 | 112 | ) |
| 111 | 113 | |
| 112 | 114 | |
| 113 | class Tag(typing.NamedTuple): | |
| 115 | @dataclass | |
| 116 | class Tag: | |
| 114 | 117 | tag: str |
| 115 | 118 | count: int |
| 116 | 119 | |
| 118 | 121 | return " ".join(w.capitalize() for w in self.tag.split()) |
| 119 | 122 | |
| 120 | 123 | |
| 121 | class Link(typing.NamedTuple): | |
| 124 | @dataclass | |
| 125 | class Link: | |
| 122 | 126 | url: str |
| 123 | 127 | name: str |
| 124 | 128 | |
| 132 | 136 | return cls(name=f"{nicename} ({t.n})", url=f"/tag/{t.tag_name}") |
| 133 | 137 | |
| 134 | 138 | |
| 135 | class LinkList(typing.NamedTuple): | |
| 139 | @dataclass | |
| 140 | class LinkList: | |
| 136 | 141 | elements: typing.List[Link] |
| 137 | 142 | |
| 138 | 143 | |