Browse Source

Show a big list of public links on the main page

Trevor Elliott 4 years ago
parent
commit
56b170cf63
2 changed files with 21 additions and 5 deletions
  1. 7 5
      lc/app.py
  2. 14 0
      lc/model.py

+ 7 - 5
lc/app.py

@@ -16,16 +16,18 @@ app = c.app
 @endpoint("/")
 class Index(Endpoint):
     def html(self):
+
+        pg = int(flask.request.args.get("page", 1))
+        links, pages = m.Link.get_all(as_user=self.user, page=pg)
+        linklist = v.LinkList(links=links, pages=pages, tags=[])
+
         return render(
             "main",
             v.Page(
                 title="main",
                 content=render(
-                    "message",
-                    v.Message(
-                        title="Lament Configuration",
-                        message="Bookmark organizing for real pinheads.",
-                    ),
+                    "linklist",
+                    linklist
                 ),
                 user=self.user,
             ),

+ 14 - 0
lc/model.py

@@ -198,6 +198,20 @@ class Link(Model):
     def by_id(id: int) -> Optional["Link"]:
         return Link.get_or_none(id=id)
 
+    @staticmethod
+    def get_all(
+        as_user: Optional[User], page: int
+    ) -> Tuple[List["Link"], v.Pagination]:
+        links = (
+            Link.select()
+            .where((Link.user == as_user) | (Link.private == False))
+            .order_by(-Link.created)
+            .paginate(page, c.per_page)
+        )
+        link_views = [l.to_view(as_user) for l in links]
+        pagination = v.Pagination.from_total(page, Link.select().count())
+        return link_views, pagination
+
     @staticmethod
     def from_request(user: User, link: r.Link) -> "Link":
         l = Link.create(