From 92f1420e0fb272c0c07168d19aa89702716454a4 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 17 Feb 2022 09:02:44 +0200 Subject: [PATCH] xvc --- files/routes/admin.py | 34 ++++++++++++++++++++++++ files/routes/posts.py | 2 +- files/templates/admin/sidebar.html | 42 ++++++++++++++++++++++++++++++ files/templates/submit.html | 6 +++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 files/templates/admin/sidebar.html diff --git a/files/routes/admin.py b/files/routes/admin.py index 88009f961..fa0e33604 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -22,6 +22,40 @@ GUMROAD_TOKEN = environ.get("GUMROAD_TOKEN", "").strip() month = datetime.now().strftime('%B') +if SITE_NAME == 'PCM': + @app.get('/admin/sidebar') + @admin_level_required(3) + def get_sidebar(v): + + try: + with open(f'files/templates/sidebar_{SITE_NAME}.html', 'r', encoding="utf-8") as f: sidebar = f.read() + except: + sidebar = None + + return render_template('admin/sidebar.html', v=v, sidebar=sidebar) + + + @app.post('/admin/sidebar') + @limiter.limit("1/second;30/minute;200/hour;1000/day") + @admin_level_required(3) + def post_sidebar(v): + + text = request.values.get('sidebar', '').strip() + + with open(f'files/templates/sidebar_{SITE_NAME}.html', 'w+', encoding="utf-8") as f: f.write(text) + + with open(f'files/templates/sidebar_{SITE_NAME}.html', 'r', encoding="utf-8") as f: sidebar = f.read() + + ma = ModAction( + kind="change_sidebar", + user_id=v.id, + ) + g.db.add(ma) + + g.db.commit() + + return render_template('admin/sidebar.html', v=v, sidebar=sidebar, msg='Sidebar edited successfully!') + @app.post("/@/make_admin") @limiter.limit("1/second;5/day") diff --git a/files/routes/posts.py b/files/routes/posts.py index b9ad0ac35..bea2cef8c 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -862,7 +862,7 @@ def submit_post(v, sub=None): sub = request.values.get("sub") - if sub: + if sub and sub != 'none': sub = g.db.query(Sub.name).filter_by(name=sub.strip().lower()).one_or_none() if not sub: abort(404) sub = sub[0] diff --git a/files/templates/admin/sidebar.html b/files/templates/admin/sidebar.html new file mode 100644 index 000000000..ab5d6e1c4 --- /dev/null +++ b/files/templates/admin/sidebar.html @@ -0,0 +1,42 @@ +{% extends "default.html" %} + +{% block pagetitle %}Edit {{SITE_NAME}} sidebar{% endblock %} + +{% block content %} + +{% if msg %} + +{% endif %} + +
+
+
+
+

Edit Sidebar

+
+
+
+
+
+ + + +
+ +
+
+
+
+
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/files/templates/submit.html b/files/templates/submit.html index 7daee7910..430fba7b9 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -88,6 +88,12 @@ {% set SUBS = toomuch_subs %} {% endif %} + {% if SITE_NAME == 'PCM' %} + + {% endif %} + {% for s in SUBS %}