#13 Add filtering and UI elements for private links

Обединени
getty обедини 1 ревизии от getty/moltarx/private-links във getty/master преди 4 години
променени са 4 файла, в които са добавени 11 реда и са изтрити 7 реда
  1. 2 2
      lc/app.py
  2. 4 4
      lc/model.py
  3. 4 0
      lc/static/main.css
  4. 1 1
      templates/link.mustache

+ 2 - 2
lc/app.py

@@ -89,7 +89,7 @@ class GetUser(Endpoint):
     def html(self, slug: str):
         u = m.User.by_slug(slug)
         pg = int(flask.request.args.get("page", 1))
-        links, pages = u.get_links(page=pg)
+        links, pages = u.get_links(as_user=self.user, page=pg)
         return render(
             "main",
             title=f"user {u.name}",
@@ -155,7 +155,7 @@ class GetTaggedLinks(Endpoint):
         u = m.User.by_slug(user)
         pg = int(flask.request.args.get("page", 0))
         t = u.get_tag(tag)
-        links, pages = t.get_links(page=pg)
+        links, pages = t.get_links(as_user=self.user, page=pg)
         return render(
             "main",
             title=f"tag {tag}",

+ 4 - 4
lc/model.py

@@ -91,10 +91,10 @@ class User(Model):
     def base_url(self) -> str:
         return f"/u/{self.name}"
 
-    def get_links(self, page: int) -> Tuple[List["Link"], Pagination]:
+    def get_links(self, as_user: r.User, page: int) -> Tuple[List["Link"], Pagination]:
         links = (
             Link.select()
-            .where(Link.user == self)
+            .where((Link.user == self) & ((self == as_user) | (Link.private == False)))
             .order_by(-Link.created)
             .paginate(page, c.per_page)
         )
@@ -176,12 +176,12 @@ class Tag(Model):
     def url(self) -> str:
         return f"/u/{self.user.name}/t/{self.name}"
 
-    def get_links(self, page: int) -> Tuple[List[Link], Pagination]:
+    def get_links(self, as_user: r.User, page: int) -> Tuple[List[Link], Pagination]:
         links = [
             ht.link
             for ht in HasTag.select()
             .join(Link)
-            .where((HasTag.tag == self))
+            .where((HasTag.tag == self) & ((HasTag.link.user == as_user) | (HasTag.link.private == False)))
             .order_by(-Link.created)
             .paginate(page, c.per_page)
         ]

+ 4 - 0
lc/static/main.css

@@ -26,6 +26,10 @@ body {
     text-decoration: none;
 }
 
+.private {
+    background-color: #ddd;
+}
+
 .link {
     padding: 0.4em 1em;
 }

+ 1 - 1
templates/link.mustache

@@ -1,4 +1,4 @@
-<div class="link">
+<div class="link{{#private}} private{{/private}}">
   <div class="text"><a href="{{url}}">{{name}}</a></div>
   <div class="url"><a href="{{url}}">{{url}}</a></div>
   <div class="taglist">{{#tags}}