From 02d99a16717ef8863e273663775d53f36c183f7c Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Wed, 12 Apr 2023 15:18:13 +0000 Subject: [PATCH] Format with Black --- gallery/__init__.py | 10 +++++----- gallery/api.py | 7 ++++++- gallery/models.py | 31 ++++++++++++++++++------------- gallery/views/group.py | 9 +++------ gallery/views/index.py | 5 +++-- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/gallery/__init__.py b/gallery/__init__.py index 1ecd6d0..0e54219 100644 --- a/gallery/__init__.py +++ b/gallery/__init__.py @@ -43,17 +43,17 @@ def create_app(): # pylint: disable=R0914 print("Creating database") with app.app_context(): db.create_all() - + register_user = User( username=app.config["ADMIN_CONF"]["username"], email=app.config["ADMIN_CONF"]["email"], - password=generate_password_hash('changeme!', method="sha256"), + password=generate_password_hash("changeme!", method="sha256"), ) db.session.add(register_user) db.session.commit() - + print( - """ + """ #################################################### # DEFAULY ADMIN USER GENERATED WITH GIVEN USERNAME # # THE DEFAULT PASSWORD "changeme!" HAS BEEN USED, # @@ -67,7 +67,7 @@ def create_app(): # pylint: disable=R0914 if not os.path.exists(MIGRATIONS_DIR): print("Creating migrations directory") migrate_init(directory=MIGRATIONS_DIR) - + # Check if migrations are up to date with app.app_context(): print("Checking for schema changes...") diff --git a/gallery/api.py b/gallery/api.py index a21d026..b30857d 100644 --- a/gallery/api.py +++ b/gallery/api.py @@ -170,7 +170,12 @@ def modify_group(): if group.author_id != current_user.id: abort(403) - if action == "add" and not GroupJunction.query.filter_by(group_id=group_id, post_id=image_id).first(): + if ( + action == "add" + and not GroupJunction.query.filter_by( + group_id=group_id, post_id=image_id + ).first() + ): db.session.add(GroupJunction(group_id=group_id, post_id=image_id)) elif request.form["action"] == "remove": GroupJunction.query.filter_by(group_id=group_id, post_id=image_id).delete() diff --git a/gallery/models.py b/gallery/models.py index 7cf628f..3958f9c 100644 --- a/gallery/models.py +++ b/gallery/models.py @@ -11,6 +11,7 @@ class GroupJunction(db.Model): # pylint: disable=too-few-public-methods, C0103 Junction table for posts and groups Joins with posts and groups """ + __tablename__ = "group_junction" id = db.Column(db.Integer, primary_key=True) @@ -29,46 +30,49 @@ class Post(db.Model): # pylint: disable=too-few-public-methods, C0103 """ Post table """ + __tablename__ = "post" id = db.Column(db.Integer, primary_key=True) - + author_id = db.Column(db.Integer, db.ForeignKey("user.id")) - + filename = db.Column(db.String, unique=True, nullable=False) mimetype = db.Column(db.String, nullable=False) exif = db.Column(db.PickleType, nullable=False) colours = db.Column(db.PickleType, nullable=False) - + description = db.Column(db.String, nullable=False) alt = db.Column(db.String, nullable=False) - + created_at = db.Column( db.DateTime, nullable=False, server_default=db.func.now(), # pylint: disable=E1102 ) - + junction = db.relationship("GroupJunction", backref="posts") + class Group(db.Model): # pylint: disable=too-few-public-methods, C0103 """ Group table """ + __tablename__ = "group" id = db.Column(db.Integer, primary_key=True) - + name = db.Column(db.String, nullable=False) description = db.Column(db.String, nullable=False) - + author_id = db.Column(db.Integer, db.ForeignKey("user.id")) created_at = db.Column( db.DateTime, nullable=False, server_default=db.func.now(), # pylint: disable=E1102 ) - + junction = db.relationship("GroupJunction", backref="groups") @@ -76,15 +80,16 @@ class User(db.Model, UserMixin): # pylint: disable=too-few-public-methods, C010 """ User table """ + __tablename__ = "user" # Gallery used information id = db.Column(db.Integer, primary_key=True) alt_id = db.Column(db.String, unique=True, nullable=False, default=str(uuid4())) - + profile_picture = db.Column(db.String, nullable=True, default=None) username = db.Column(db.String, unique=True, nullable=False) - + email = db.Column(db.String, unique=True, nullable=False) password = db.Column(db.String, nullable=False) joined_at = db.Column( @@ -92,9 +97,9 @@ class User(db.Model, UserMixin): # pylint: disable=too-few-public-methods, C010 nullable=False, server_default=db.func.now(), # pylint: disable=E1102 ) - - posts = db.relationship('Post', backref='author') - groups = db.relationship('Group', backref='author') + + posts = db.relationship("Post", backref="author") + groups = db.relationship("Group", backref="author") def get_id(self): return str(self.alt_id) diff --git a/gallery/views/group.py b/gallery/views/group.py index c50deaf..0491a59 100644 --- a/gallery/views/group.py +++ b/gallery/views/group.py @@ -30,8 +30,7 @@ def groups(): # Get the 3 most recent images images = ( - GroupJunction.query - .with_entities(GroupJunction.post_id) + GroupJunction.query.with_entities(GroupJunction.post_id) .filter(GroupJunction.group_id == group.id) .order_by(GroupJunction.date_added.desc()) .limit(3) @@ -41,8 +40,7 @@ def groups(): group.images = [] for image in images: group.images.append( - Post.query - .with_entities(Post.filename, Post.alt, Post.colours, Post.id) + Post.query.with_entities(Post.filename, Post.alt, Post.colours, Post.id) .filter(Post.id == image[0]) .first() ) @@ -60,8 +58,7 @@ def group(group_id): # Get all images in the group from the junction table junction = ( - GroupJunction.query - .with_entities(GroupJunction.post_id) + GroupJunction.query.with_entities(GroupJunction.post_id) .filter(GroupJunction.group_id == group_id) .order_by(GroupJunction.date_added.desc()) .all() diff --git a/gallery/views/index.py b/gallery/views/index.py index a79204b..b676f1e 100644 --- a/gallery/views/index.py +++ b/gallery/views/index.py @@ -38,8 +38,9 @@ def index(): # get the images for the current page images = ( - Post.query - .with_entities( Post.filename, Post.alt, Post.colours, Post.created_at, Post.id) + Post.query.with_entities( + Post.filename, Post.alt, Post.colours, Post.created_at, Post.id + ) .order_by(Post.id.desc()) .offset((page - 1) * limit) .limit(limit)