Browse Source

Automatic formatting commit: 2020-04-11T16:34:17.336838

Getty Ritter 4 years ago
parent
commit
e6e32f8568
4 changed files with 17 additions and 9 deletions
  1. 8 4
      lc/app.py
  2. 1 0
      lc/model.py
  3. 5 4
      lc/web.py
  4. 3 1
      stubs/playhouse/shortcuts.py

+ 8 - 4
lc/app.py

@@ -11,6 +11,7 @@ from lc.web import Endpoint, endpoint, render
 
 app = c.app
 
+
 @endpoint("/")
 class Index(Endpoint):
     def html(self):
@@ -31,13 +32,16 @@ class Login(Endpoint):
 
     def api_post(self):
         print(flask.request.form)
-        u, token = m.User.login(r.User(
-            name=flask.request.form["username"],
-            password=flask.request.form["password"],
-        ))
+        u, token = m.User.login(
+            r.User(
+                name=flask.request.form["username"],
+                password=flask.request.form["password"],
+            )
+        )
         flask.session["auth"] = token
         raise e.LCRedirect(u.base_url())
 
+
 @endpoint("/logout")
 class Logout(Endpoint):
     def html(self):

+ 1 - 0
lc/model.py

@@ -145,6 +145,7 @@ class HasTag(Model):
 class UserInvite(Model):
     token: str
 
+
 MODELS = [
     User,
     Link,

+ 5 - 4
lc/web.py

@@ -13,7 +13,7 @@ class Endpoint:
         # try finding the token
         token = None
         # first check the HTTP headers
-        if (auth := flask.request.headers.get("Authorization", None)):
+        if (auth := flask.request.headers.get("Authorization", None)) :
             token = auth.split()[1]
         # if that fails, check the session
         elif flask.session.get("auth", None):
@@ -34,11 +34,11 @@ class Endpoint:
                 self.user = u
 
     def require_authentication(self, name: str):
-        '''
+        """
         Check that the currently logged-in user exists and is the
         same as the user whose username is given. Raises an exception
         otherwise.
-        '''
+        """
         if not self.user or name != self.user.name:
             raise e.BadPermissions()
 
@@ -73,11 +73,12 @@ def endpoint(route):
             return cls().route(*args, **kwargs)
 
         methods = ["GET"]
-        if 'api_post' in dir(cls):
+        if "api_post" in dir(cls):
             methods.append("POST")
 
         func.__name__ = cls.__name__
         return c.app.route(route, methods=methods)(func)
+
     return do_endpoint
 
 

+ 3 - 1
stubs/playhouse/shortcuts.py

@@ -1,3 +1,5 @@
 import peewee
 
-def model_to_dict(m: peewee.Model) -> dict: pass
+
+def model_to_dict(m: peewee.Model) -> dict:
+    pass