From 68a228e95f651359de35fd2744b74623365f0579 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 16:57:38 +0200 Subject: [PATCH] Fixed user-generated static resources paths. --- matemat/__main__.py | 2 +- matemat/webserver/pagelets/admin.py | 8 ++++---- matemat/webserver/pagelets/modproduct.py | 6 +++--- matemat/webserver/pagelets/moduser.py | 6 +++--- templates/modproduct.html | 2 +- templates/moduser.html | 2 +- templates/productlist.html | 2 +- templates/userlist.html | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/matemat/__main__.py b/matemat/__main__.py index eef1fd5..579321a 100644 --- a/matemat/__main__.py +++ b/matemat/__main__.py @@ -13,4 +13,4 @@ if __name__ == '__main__': port = int(sys.argv[1]) # Start the web server - MatematWebserver(port=port, staticroot='/var/matemat/upload').start() + MatematWebserver(port=port, staticroot='./static').start() diff --git a/matemat/webserver/pagelets/admin.py b/matemat/webserver/pagelets/admin.py index f7e5ce8..412e194 100644 --- a/matemat/webserver/pagelets/admin.py +++ b/matemat/webserver/pagelets/admin.py @@ -78,8 +78,8 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No if 'avatar' not in args: return avatar = bytes(args.avatar) - os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True) - with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f: + os.makedirs('./static/upload/thumbnails/users/', exist_ok=True) + with open(f'./static/upload/thumbnails/users/{user.id}.png', 'wb') as f: f.write(avatar) except UnicodeDecodeError: @@ -111,8 +111,8 @@ def handle_admin_change(args: RequestArguments, db: MatematDatabase): newproduct = db.create_product(name, price_member, price_non_member) if 'image' in args: image = bytes(args.image) - os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True) - with open(f'/var/matemat/upload/thumbnails/products/{newproduct.id}.png', 'wb') as f: + os.makedirs('./static/upload/thumbnails/products/', exist_ok=True) + with open(f'./static/upload/thumbnails/products/{newproduct.id}.png', 'wb') as f: f.write(image) elif change == 'restock': diff --git a/matemat/webserver/pagelets/modproduct.py b/matemat/webserver/pagelets/modproduct.py index c5938a4..7bd11b7 100644 --- a/matemat/webserver/pagelets/modproduct.py +++ b/matemat/webserver/pagelets/modproduct.py @@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase) if change == 'del': db.delete_product(product) try: - os.remove(f'/var/matemat/upload/thumbnails/products/{product.id}.png') + os.remove(f'./static/upload/thumbnails/products/{product.id}.png') except FileNotFoundError: pass @@ -76,6 +76,6 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase) if 'image' in args: image = bytes(args.image) if len(image) > 0: - os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True) - with open(f'/var/matemat/upload/thumbnails/products/{product.id}.png', 'wb') as f: + os.makedirs('./static/upload/thumbnails/products/', exist_ok=True) + with open(f'./static/upload/thumbnails/products/{product.id}.png', 'wb') as f: f.write(image) diff --git a/matemat/webserver/pagelets/moduser.py b/matemat/webserver/pagelets/moduser.py index f385d56..b42342a 100644 --- a/matemat/webserver/pagelets/moduser.py +++ b/matemat/webserver/pagelets/moduser.py @@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No if change == 'del': db.delete_user(user) try: - os.remove(f'/var/matemat/upload/thumbnails/users/{user.id}.png') + os.remove(f'./static/upload/thumbnails/users/{user.id}.png') except FileNotFoundError: pass @@ -83,6 +83,6 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No if 'avatar' in args: avatar = bytes(args.avatar) if len(avatar) > 0: - os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True) - with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f: + os.makedirs('./static/upload/thumbnails/users/', exist_ok=True) + with open(f'./static/upload/thumbnails/users/{user.id}.png', 'wb') as f: f.write(avatar) diff --git a/templates/modproduct.html b/templates/modproduct.html index a5ee3e7..698790f 100644 --- a/templates/modproduct.html +++ b/templates/modproduct.html @@ -24,7 +24,7 @@


diff --git a/templates/moduser.html b/templates/moduser.html index a67b67e..e28ef82 100644 --- a/templates/moduser.html +++ b/templates/moduser.html @@ -30,7 +30,7 @@


diff --git a/templates/productlist.html b/templates/productlist.html index 4e4d7e0..6163de4 100644 --- a/templates/productlist.html +++ b/templates/productlist.html @@ -26,7 +26,7 @@ Your balance: {{ authuser.balance }} {% endif %} ; Stock: {{ product.stock }}
- Picture of {{ product.name }} + Picture of {{ product.name }}
diff --git a/templates/userlist.html b/templates/userlist.html index d1724f9..57717cc 100644 --- a/templates/userlist.html +++ b/templates/userlist.html @@ -11,7 +11,7 @@ {{ user.name }}
- Avatar of {{ user.name }} + Avatar of {{ user.name }}