Browse Source

Automatic formatting commit: 2020-04-12T23:35:07.207321

Getty Ritter 4 years ago
parent
commit
c8feadce8d
4 changed files with 70 additions and 52 deletions
  1. 56 46
      lc/app.py
  2. 1 5
      lc/model.py
  3. 12 1
      lc/view.py
  4. 1 0
      lc/web.py

+ 56 - 46
lc/app.py

@@ -16,14 +16,20 @@ app = c.app
 @endpoint("/")
 class Index(Endpoint):
     def html(self):
-        return render("main", v.Page(
-            title="main",
-            content=render("message", v.Message(
-                title="Lament Configuration",
-                message="Bookmark organizing for real pinheads.",
-            )),
-            user=self.user,
-        ))
+        return render(
+            "main",
+            v.Page(
+                title="main",
+                content=render(
+                    "message",
+                    v.Message(
+                        title="Lament Configuration",
+                        message="Bookmark organizing for real pinheads.",
+                    ),
+                ),
+                user=self.user,
+            ),
+        )
 
 
 @endpoint("/auth")
@@ -37,11 +43,9 @@ class Auth(Endpoint):
 @endpoint("/login")
 class Login(Endpoint):
     def html(self):
-        return render("main", v.Page(
-            title="login",
-            content=render("login"),
-            user=self.user,
-        ))
+        return render(
+            "main", v.Page(title="login", content=render("login"), user=self.user,)
+        )
 
 
 @endpoint("/logout")
@@ -67,11 +71,10 @@ class CreateUser(Endpoint):
         if not token:
             raise e.LCRedirect("/")
 
-        return render("main", v.Page(
-            title="add user",
-            user=self.user,
-            content=render("add_user"),
-        ))
+        return render(
+            "main",
+            v.Page(title="add user", user=self.user, content=render("add_user"),),
+        )
 
     def api_post(self):
         token = flask.request.args["token"]
@@ -87,11 +90,14 @@ class GetUser(Endpoint):
         u = m.User.by_slug(slug)
         pg = int(flask.request.args.get("page", 1))
         links, pages = u.get_links(as_user=self.user, page=pg)
-        return render("main", v.Page(
-            title=f"user {u.name}",
-            content=render("linklist", v.LinkList(links=links, pages=pages)),
-            user=self.user,
-        ))
+        return render(
+            "main",
+            v.Page(
+                title=f"user {u.name}",
+                content=render("linklist", v.LinkList(links=links, pages=pages)),
+                user=self.user,
+            ),
+        )
 
     def api_get(self, slug: str):
         return m.User.by_slug(slug).to_dict()
@@ -101,11 +107,14 @@ class GetUser(Endpoint):
 class UserConfig(Endpoint):
     def html(self, user: str):
         u = self.require_authentication(user)
-        return render("main", v.Page(
-            title="configuration",
-            content=render("config", u.get_config()),
-            user=self.user,
-        ))
+        return render(
+            "main",
+            v.Page(
+                title="configuration",
+                content=render("config", u.get_config()),
+                user=self.user,
+            ),
+        )
 
 
 @endpoint("/u/<string:user>/invite")
@@ -119,11 +128,9 @@ class CreateInvite(Endpoint):
 @endpoint("/u/<string:user>/l")
 class CreateLink(Endpoint):
     def html(self, user: str):
-        return render("main", v.Page(
-            title="login",
-            content=render("add_link"),
-            user=self.user,
-        ))
+        return render(
+            "main", v.Page(title="login", content=render("add_link"), user=self.user,)
+        )
 
     def api_post(self, user: str):
         u = self.require_authentication(user)
@@ -146,11 +153,14 @@ class GetLink(Endpoint):
 
     def html(self, user: str, link: str):
         l = m.User.by_slug(user).get_link(int(link))
-        return render("main", v.Page(
-            title=f"link {l.name}",
-            content=render("linklist", v.LinkList([l])),
-            user=self.user,
-        ))
+        return render(
+            "main",
+            v.Page(
+                title=f"link {l.name}",
+                content=render("linklist", v.LinkList([l])),
+                user=self.user,
+            ),
+        )
 
 
 @endpoint("/u/<string:slug>/l/<string:link>/edit")
@@ -170,11 +180,11 @@ class GetTaggedLinks(Endpoint):
         pg = int(flask.request.args.get("page", 0))
         t = u.get_tag(tag)
         links, pages = t.get_links(as_user=self.user, page=pg)
-        return render("main", v.Page(
-            title=f"tag {tag}",
-            content=render("linklist", v.LinkList(
-                links=links,
-                pages=pages,
-            )),
-            user=self.user,
-        ))
+        return render(
+            "main",
+            v.Page(
+                title=f"tag {tag}",
+                content=render("linklist", v.LinkList(links=links, pages=pages,)),
+                user=self.user,
+            ),
+        )

+ 1 - 5
lc/model.py

@@ -19,7 +19,6 @@ class Model(peewee.Model):
         return playhouse.shortcuts.model_to_dict(self)
 
 
-
 class User(Model):
     """
     A user! you know tf this is about
@@ -104,10 +103,7 @@ class User(Model):
                 for ui in UserInvite.select().where(UserInvite.created_by == self)
             ]
             admin_pane = v.AdminPane(invites=user_invites)
-        return v.Config(
-            username=self.name,
-            admin_pane=admin_pane,
-        )
+        return v.Config(username=self.name, admin_pane=admin_pane,)
 
 
 class Link(Model):

+ 12 - 1
lc/view.py

@@ -4,7 +4,10 @@ from typing import Any, Optional, List
 
 import lc.config as c
 
-class View: pass
+
+class View:
+    pass
+
 
 @dataclass
 class Pagination(View):
@@ -25,26 +28,31 @@ class Pagination(View):
     def from_total(cls, current, total) -> "Pagination":
         return cls(current=current, last=((total - 1) // c.per_page) + 1,)
 
+
 @dataclass
 class UserInvite(View):
     claimed: bool
     claimant: str
     token: str
 
+
 @dataclass
 class AdminPane(View):
     invites: List[UserInvite]
 
+
 @dataclass
 class Config(View):
     username: str
     admin_pane: Optional[AdminPane]
 
+
 @dataclass
 class Tag(View):
     url: str
     name: str
 
+
 @dataclass
 class Link(View):
     id: int
@@ -57,16 +65,19 @@ class Link(View):
     is_mine: bool
     link_url: str
 
+
 @dataclass
 class LinkList(View):
     links: List[Any]
     pages: Optional[Pagination] = None
 
+
 @dataclass
 class Message(View):
     title: str
     message: str
 
+
 @dataclass
 class Page(View):
     title: str

+ 1 - 0
lc/web.py

@@ -166,6 +166,7 @@ def endpoint(route: str):
 
 LOADER = pystache.loader.Loader(extension="mustache", search_dirs=["templates"])
 
+
 def render(name: str, data: Optional[v.View] = None) -> str:
     """Load and use a Mustache template from the project root"""
     template = LOADER.load_name(name)