Browse Source

Automatic formatting commit: 2020-04-06T22:25:18.566727

Getty Ritter 1 year ago
parent
commit
87ae1fe74a
3 changed files with 14 additions and 7 deletions
  1. 4 0
      lc/config.py
  2. 7 2
      lc/model.py
  3. 3 5
      lc/routes.py

+ 4 - 0
lc/config.py

@@ -7,10 +7,14 @@ DB = playhouse.sqlite_ext.SqliteExtDatabase(None)
 PER_PAGE = 50
 
 if sys.stderr.isatty():
+
     def log(msg, *args, **kwargs):
         sys.stderr.write(msg.format(*args, **kwargs))
         sys.stderr.write("\n")
+
+
 else:
+
     def log(msg, *args, **kwargs):
         sys.stderr.write("\x1b[31m")
         sys.stderr.write(msg.format(*args, **kwargs))

+ 7 - 2
lc/model.py

@@ -34,7 +34,7 @@ class User(Model):
         return Link.select().where(Link.user == self).paginate(page, c.PER_PAGE)
 
     def get_tag(self, tag_name: str) -> "Tag":
-        return Tag.get((Tag.user==self) & (Tag.name==tag_name))
+        return Tag.get((Tag.user == self) & (Tag.name == tag_name))
 
 
 class Link(Model):
@@ -86,7 +86,12 @@ class Tag(Model):
         return f"/u/{self.user.name}/t/{self.name}"
 
     def get_links(self, page: int) -> typing.List[Link]:
-        return [ ht.link for ht in HasTag.select().where((HasTag.tag == self)).paginate(page, c.PER_PAGE) ]
+        return [
+            ht.link
+            for ht in HasTag.select()
+            .where((HasTag.tag == self))
+            .paginate(page, c.PER_PAGE)
+        ]
 
     @staticmethod
     def get_or_create_tag(user: User, tag_name: str):

+ 3 - 5
lc/routes.py

@@ -33,7 +33,7 @@ def create_user():
 @app.route("/u/<string:user>", methods=["GET", "POST"])
 def get_user(user):
     u = m.User.by_slug(user)
-    pg = int(flask.request.args.get('page', 0))
+    pg = int(flask.request.args.get("page", 0))
     links = u.get_links(page=pg)
     return render(
         "main", title=f"user {u.name}", content=render("linklist", links=links),
@@ -53,9 +53,7 @@ def link(user):
 @app.route("/u/<string:user>/t/<path:tag>")
 def get_tagged_links(user, tag):
     u = m.User.by_slug(user)
-    pg = int(flask.request.args.get('page', 0))
+    pg = int(flask.request.args.get("page", 0))
     t = u.get_tag(tag)
     links = t.get_links(page=pg)
-    return render(
-        "main", title=f"tag {tag}", content=render("linklist", links=links),
-    )
+    return render("main", title=f"tag {tag}", content=render("linklist", links=links),)