Browse Source

Add list of tags to basic view

Getty Ritter 4 years ago
parent
commit
2cb453e844
5 changed files with 30 additions and 5 deletions
  1. 3 1
      lc/app.py
  2. 5 0
      lc/model.py
  3. 10 0
      lc/static/main.css
  4. 1 0
      lc/view.py
  5. 11 4
      templates/linklist.mustache

+ 3 - 1
lc/app.py

@@ -89,12 +89,14 @@ class GetUser(Endpoint):
     def html(self, slug: str):
         u = m.User.by_slug(slug)
         pg = int(flask.request.args.get("page", 1))
+        tags = u.get_tags()
         links, pages = u.get_links(as_user=self.user, page=pg)
+        linklist = v.LinkList(links=links, pages=pages, tags=tags)
         return render(
             "main",
             v.Page(
                 title=f"user {u.name}",
-                content=render("linklist", v.LinkList(links=links, pages=pages)),
+                content=render("linklist", linklist),
                 user=self.user,
             ),
         )

+ 5 - 0
lc/model.py

@@ -148,6 +148,11 @@ class User(Model):
                 for t in l["tags"].split():
                     HasTag.get_or_create(link=ln, tag=tags[t])
 
+    def get_tags(self) -> List[v.Tag]:
+        return sorted(
+            (t.to_view() for t in self.tags), # type: ignore
+            key=lambda t: t.name,
+        )
 
 class Link(Model):
     """

+ 10 - 0
lc/static/main.css

@@ -198,3 +198,13 @@ form > div {
 .error p {
     margin-left: 2em;
 }
+
+.columns {
+    display: grid;
+    grid-template-columns: 60% 40%;
+}
+
+.tags {
+    padding: 2em;
+    word-spacing: 1em;
+}

+ 1 - 0
lc/view.py

@@ -78,6 +78,7 @@ class Link(View):
 @dataclass
 class LinkList(View):
     links: List[Any]
+    tags: List[Tag]
     pages: Optional[Pagination] = None
 
 

+ 11 - 4
templates/linklist.mustache

@@ -1,7 +1,14 @@
-<div class="linklist">
-  {{#links}}
-    {{>link}}
-  {{/links}}
+<div class="columns">
+  <div class="linklist">
+    {{#links}}
+      {{>link}}
+    {{/links}}
+  </div>
+  <div class="tags">
+    {{#tags}}
+      <a href="{{url}}">{{name}}</a>
+    {{/tags}}
+  </div>
 </div>
 {{#pages}}
   <div class="pagination">