Getty Ritter 2 years ago
parent
commit
2c6ccc93a6
4 changed files with 14 additions and 17 deletions
  1. 9 11
      lc/model.py
  2. 1 4
      scripts/populate.py
  3. 1 1
      stubs/peewee.py
  4. 3 1
      tasks.py

+ 9 - 11
lc/model.py

@@ -35,10 +35,7 @@ class Pagination:
 
     @classmethod
     def from_total(cls, current, total) -> "Pagination":
-        return cls(
-            current=current,
-            last=((total-1)//c.PER_PAGE)+1,
-        )
+        return cls(current=current, last=((total - 1) // c.PER_PAGE) + 1,)
 
 
 # TODO: figure out authorization for users (oauth? passwd?)
@@ -71,10 +68,7 @@ class User(Model):
         u = User.by_slug(user.name)
         if not u.authenticate(user.password):
             raise e.BadPassword(name=user.name)
-        return u, c.SERIALIZER.dumps({
-            "name": user.name,
-            "password": user.password,
-        })
+        return u, c.SERIALIZER.dumps({"name": user.name, "password": user.password,})
 
     @staticmethod
     def by_slug(slug: str) -> "User":
@@ -87,7 +81,12 @@ class User(Model):
         return f"/u/{self.name}"
 
     def get_links(self, page: int) -> typing.Tuple[typing.List["Link"], Pagination]:
-        links = Link.select().where(Link.user == self).order_by(-Link.created).paginate(page, c.PER_PAGE)
+        links = (
+            Link.select()
+            .where(Link.user == self)
+            .order_by(-Link.created)
+            .paginate(page, c.PER_PAGE)
+        )
         pagination = Pagination.from_total(page, Link.select().count())
         return links, pagination
 
@@ -159,8 +158,7 @@ class Tag(Model):
             .paginate(page, c.PER_PAGE)
         ]
         pagination = Pagination.from_total(
-            page,
-            HasTag.select().where((HasTag.tag == self)).count(),
+            page, HasTag.select().where((HasTag.tag == self)).count(),
         )
         return links, pagination
 

+ 1 - 4
scripts/populate.py

@@ -14,10 +14,7 @@ def main():
 
     u = m.User.get_or_none(name="gdritter")
     if not u:
-        u = m.User.from_request(r.User(
-            name="gdritter",
-            password="behest",
-        ))
+        u = m.User.from_request(r.User(name="gdritter", password="behest",))
         u.set_as_admin()
 
     with open("scripts/aisamanra.json") as f:

+ 1 - 1
stubs/peewee.py

@@ -30,7 +30,7 @@ class Model:
 
 # These all do things that MyPy chokes on, so we're going to treat
 # them like methods instead of naming classes
-def TextField(default: str = '', unique: bool = False) -> Any:
+def TextField(default: str = "", unique: bool = False) -> Any:
     pass
 
 

+ 3 - 1
tasks.py

@@ -52,4 +52,6 @@ def tc(c):
 @task
 def uwsgi(c, sock="lc.sock"):
     """Run a uwsgi server"""
-    c.run(f"poetry run uwsgi --socket {sock} --module lament-configuration:app --processes 4 --threads 2")
+    c.run(
+        f"poetry run uwsgi --socket {sock} --module lament-configuration:app --processes 4 --threads 2"
+    )