From c309953be359ab7247ffb1ba3ff2c2ba0623275c Mon Sep 17 00:00:00 2001 From: lza_menace Date: Fri, 2 Dec 2022 12:05:44 -0800 Subject: [PATCH] cleaning up admin, getting tips shown --- nerochan/routes/admin.py | 80 +++++++++++++++++-------- nerochan/routes/artwork.py | 5 ++ nerochan/routes/main.py | 19 +++++- nerochan/routes/user.py | 4 ++ nerochan/static/css/main.css | 4 ++ nerochan/templates/admin/admins.html | 37 ------------ nerochan/templates/admin/artists.html | 36 ----------- nerochan/templates/admin/dashboard.html | 55 +++++++++++++++++ nerochan/templates/admin/main.html | 37 ------------ nerochan/templates/admin/manage.html | 49 +++++++++++++++ nerochan/templates/admin/users.html | 0 nerochan/templates/includes/navbar.html | 2 +- nerochan/templates/index.html | 38 ++++++++++-- nerochan/templates/tips.html | 34 +++++++++++ 14 files changed, 256 insertions(+), 144 deletions(-) delete mode 100644 nerochan/templates/admin/admins.html delete mode 100644 nerochan/templates/admin/artists.html create mode 100644 nerochan/templates/admin/dashboard.html delete mode 100644 nerochan/templates/admin/main.html create mode 100644 nerochan/templates/admin/manage.html delete mode 100644 nerochan/templates/admin/users.html create mode 100644 nerochan/templates/tips.html diff --git a/nerochan/routes/admin.py b/nerochan/routes/admin.py index 7983573..6bca183 100644 --- a/nerochan/routes/admin.py +++ b/nerochan/routes/admin.py @@ -11,44 +11,27 @@ bp = Blueprint('admin', 'admin', url_prefix='/admin') @bp.route('', methods=['GET', 'POST']) @login_required @admin_required -def main(): +def dashboard(): artists = User.select().where(User.is_verified == True).count() admins = User.select().where(User.is_admin == True).count() active_artworks = Artwork.select().where(Artwork.approved == True).count() pending_artworks = Artwork.select().where(Artwork.approved == False).count() confirmed_tips = Transaction.select().where(Transaction.verified == True).count() pending_tips = Transaction.select().where(Transaction.verified == False).count() - # admin_form = UserForm() + # # artist_form = UserForm() - # if admin_form.validate_on_submit(): - # u = User.select().where(User.handle == admin_form.handle.data).first() - # u.is_admin = True - # u.save() - # return redirect(request.referrer) + # if artist_form.validate_on_submit(): # u = User.select().where(User.handle == artist_form.handle.data).first() # u.is_verified = True # u.save() # return redirect(request.referrer) - # if request.args.get('remove'): - # a = User.select().where(User.handle == request.args.get('remove')).first() - # if a == current_user: - # flash('cannot delete yourself') - # return redirect(url_for('admin.main')) - # if a: - # a.is_admin = False - # a.save() - # return redirect(url_for('admin.main')) - # if request.args.get('unverify'): - # a = User.select().where(User.handle == request.args.get('unverify')).first() - # if a: - # a.is_verified = False - # a.save() - # return redirect(url_for('admin.main')) + + # admins = User.select().where(User.is_admin == True).order_by(User.register_date.desc()) # artists = User.select().where(User.is_verified == True).order_by(User.register_date.desc()) return render_template( - 'admin/main.html', + 'admin/dashboard.html', artists=artists, admins=admins, active_artworks=active_artworks, @@ -57,8 +40,55 @@ def main(): pending_tips=pending_tips, ) -def admins(): - pass +@bp.route('/', methods=['GET', 'POST']) +@login_required +@admin_required +def manage(item): + form = None + items = None + action = None + if item == 'admins': + form = UserForm() + action = 'remove' + _action = request.args.get(action) + items = User.select().where(User.is_admin == True).order_by(User.register_date.desc()) + if form.validate_on_submit(): + u = User.select().where(User.handle == form.handle.data).first() + u.is_admin = True + u.save() + return redirect(request.referrer) + elif _action: + a = User.select().where(User.handle == _action).first() + if a == current_user: + flash('cannot remove yourself') + return redirect(request.referrer) + if a: + a.is_admin = False + a.save() + return redirect(request.referrer) + elif item == 'artists': + form = UserForm() + action = 'unverify' + _action = request.args.get(action) + items = User.select().where(User.is_verified == True).order_by(User.register_date.desc()) + if form.validate_on_submit(): + u = User.select().where(User.handle == form.handle.data).first() + u.is_verified = True + u.save() + return redirect(request.referrer) + elif _action: + a = User.select().where(User.handle == _action).first() + if a: + a.is_verified = False + a.save() + return redirect(request.referrer) + return render_template( + 'admin/manage.html', + item=item, + items=items, + action=action, + form=form + ) def artists(): pass diff --git a/nerochan/routes/artwork.py b/nerochan/routes/artwork.py index 25f2012..1e1a9da 100644 --- a/nerochan/routes/artwork.py +++ b/nerochan/routes/artwork.py @@ -12,6 +12,11 @@ bp = Blueprint('artwork', 'artwork', url_prefix='/artwork') def list(): return 'show all artwork' +@bp.route('/pending') +def pending(): + return 'show pending artwork' + + @bp.route('/', methods=['GET', 'POST']) def show(id): form = ConfirmTip() diff --git a/nerochan/routes/main.py b/nerochan/routes/main.py index c92ad1d..5713c50 100644 --- a/nerochan/routes/main.py +++ b/nerochan/routes/main.py @@ -2,7 +2,7 @@ from os import path from flask import Blueprint, render_template, send_from_directory -from nerochan.models import Artwork, User +from nerochan.models import Artwork, User, Transaction from nerochan import config @@ -17,9 +17,13 @@ def index(): Artwork.approved == True, Artwork.hidden == False ).order_by(Artwork.upload_date.desc()).limit(10) + transactions = Transaction.select().where( + Transaction.verified == True + ).order_by(Transaction.tx_date.desc()).limit(10) feed = { 'users': users, - 'artwork': artwork + 'artwork': artwork, + 'tips': transactions } return render_template( 'index.html', @@ -35,6 +39,17 @@ def uploaded_file(filename): file_path = path.join(config.DATA_PATH, 'uploads') return send_from_directory(file_path, filename) +@bp.route('/tips') +def tips(): + tips = Transaction.select().where(Transaction.verified == True).order_by(Transaction.tx_date.desc()) + total = sum([i.atomic_xmr for i in tips]) + return render_template( + 'tips.html', + tips=tips, + total=total + ) + + # most tipped artworks # most tipped artists diff --git a/nerochan/routes/user.py b/nerochan/routes/user.py index 6cad558..3642e91 100644 --- a/nerochan/routes/user.py +++ b/nerochan/routes/user.py @@ -6,6 +6,10 @@ from nerochan.models import User bp = Blueprint('user', 'user') +@bp.route('/users') +def list(): + return 'users list' + @bp.route('/user/') def show(handle: str): user = User.select().where(User.handle == handle).first() diff --git a/nerochan/static/css/main.css b/nerochan/static/css/main.css index 38c4b8a..2512cee 100644 --- a/nerochan/static/css/main.css +++ b/nerochan/static/css/main.css @@ -12,6 +12,10 @@ a, a:visited { margin-left: 2em; } +.mt-4 { + margin-top: 4em; +} + ul { list-style: circle; } diff --git a/nerochan/templates/admin/admins.html b/nerochan/templates/admin/admins.html deleted file mode 100644 index 079f15d..0000000 --- a/nerochan/templates/admin/admins.html +++ /dev/null @@ -1,37 +0,0 @@ -{% extends 'includes/base.html' %} - -{% block content %} - -
-
-

admins

-

- Add a homie to be an admin.
- Admins can manage other admins as well as hide artwork,
- approve/reject artwork, ban artists, and verify artists. -

-
- {{ admin_form.csrf_token }} -
-
- {{ admin_form.handle }} -
-
- -
-
-
    - {%- for field, errors in admin_form.errors.items() %} -
  • {{ ', '.join(errors) }}
  • - {%- endfor %} -
-
-
    - {% for admin in admins %} -
  • {{ admin.handle }} - remove
  • - {% endfor %} -
-
-
- -{% endblock %} diff --git a/nerochan/templates/admin/artists.html b/nerochan/templates/admin/artists.html deleted file mode 100644 index 472d5d4..0000000 --- a/nerochan/templates/admin/artists.html +++ /dev/null @@ -1,36 +0,0 @@ -{% extends 'includes/base.html' %} - -{% block content %} - -
-
-

artists

-

- Verified artists will skip the queue
- and have their artwork displayed immediately. -

-
- {{ artist_form.csrf_token }} -
-
- {{ artist_form.handle }} -
-
- -
-
-
    - {%- for field, errors in artist_form.errors.items() %} -
  • {{ ', '.join(errors) }}
  • - {%- endfor %} -
-
-
    - {% for artist in artists %} -
  • {{ artist.handle }} - remove
  • - {% endfor %} -
-
-
- -{% endblock %} diff --git a/nerochan/templates/admin/dashboard.html b/nerochan/templates/admin/dashboard.html new file mode 100644 index 0000000..7185ed6 --- /dev/null +++ b/nerochan/templates/admin/dashboard.html @@ -0,0 +1,55 @@ +{% extends 'includes/base.html' %} + +{% block content %} + +
+ +
+
+ +
+

{{ pending_tips }}

+
pending
tip{% if pending_tips != 1 %}s{% endif %}
+
+ +
+
+ +{% endblock %} diff --git a/nerochan/templates/admin/main.html b/nerochan/templates/admin/main.html deleted file mode 100644 index cfc68fd..0000000 --- a/nerochan/templates/admin/main.html +++ /dev/null @@ -1,37 +0,0 @@ -{% extends 'includes/base.html' %} - -{% block content %} - -
-
-
-

{{ admins }}

-
admin{% if admins != 1 %}s{% endif %}
-
-
-

{{ artists }}

-
verified
artist{% if artists != 1 %}s{% endif %}
-
-
-

{{ active_artworks }}

-
active
artwork{% if active_artworks != 1 %}s{% endif %}
-
-
-

{{ pending_artworks }}

-
pending
artwork{% if pending_artworks != 1 %}s{% endif %}
-
-
-
-
-
-

{{ confirmed_tips }}

-
confirmed
tip{% if confirmed_tips != 1 %}s{% endif %}
-
-
-

{{ pending_tips }}

-
pending
tip{% if pending_tips != 1 %}s{% endif %}
-
-
-
- -{% endblock %} diff --git a/nerochan/templates/admin/manage.html b/nerochan/templates/admin/manage.html new file mode 100644 index 0000000..caa28e0 --- /dev/null +++ b/nerochan/templates/admin/manage.html @@ -0,0 +1,49 @@ +{% extends 'includes/base.html' %} + +{% block content %} + +
+
+

{{ item }}

+ {% if item == 'admins' %} +

+ Add a homie to be an admin.
+ Admins can manage other admins as well as hide artwork,
+ approve/reject artwork, ban artists, and verify artists. +

+ {% elif item == 'artists' %} +

+ Verified artists will skip the queue
+ and have their artwork displayed immediately. +

+ {% endif %} +
+ {{ form.csrf_token }} +
+
+ {{ form.handle }} +
+
+ +
+
+
    + {%- for field, errors in form.errors.items() %} +
  • {{ ', '.join(errors) }}
  • + {%- endfor %} +
+
+
    + {% for item in items %} +
  • +
    {{ item.handle }} - {{ action }}
    +
  • + {% endfor %} +
+
+ +
+ +{% endblock %} diff --git a/nerochan/templates/admin/users.html b/nerochan/templates/admin/users.html deleted file mode 100644 index e69de29..0000000 diff --git a/nerochan/templates/includes/navbar.html b/nerochan/templates/includes/navbar.html index e5a4e50..8aa6f02 100644 --- a/nerochan/templates/includes/navbar.html +++ b/nerochan/templates/includes/navbar.html @@ -5,7 +5,7 @@ {%- if current_user.is_authenticated %} {%- if current_user.is_admin %} - + {% endif %} {%- else %} diff --git a/nerochan/templates/index.html b/nerochan/templates/index.html index fa2ed64..805afb2 100644 --- a/nerochan/templates/index.html +++ b/nerochan/templates/index.html @@ -13,7 +13,7 @@ {%- endfor %} {%- endfor %} -

...view all

+

...view all

{% else %}

There's nothing here yet...

{% endif %} @@ -24,15 +24,41 @@ {% for user in feed['users'] %}

{{ user.handle }}

{% endfor %} +

...view all

+ {% else %} +

There's nothing here yet...

+ {% endif %} + +
+

tips

+ {% if feed['tips'] %} + + + + + + + + + + + + {% for tx in feed['tips'] %} + + + + + + + + {% endfor %} + +
TXIDXMRArtworkArtistDate
{{ tx.tx_id | shorten }}{{ tx.atomic_xmr | atomic }}{{ tx.artwork.id }}{{ tx.artwork.user.handle }}{{ tx.tx_date | humanize }}
+

...view all

{% else %}

There's nothing here yet...

{% endif %}
-{% if current_user.is_authenticated %} -

logged in: {{ current_user.handle }}

-{% endif %} - - {% endblock %} diff --git a/nerochan/templates/tips.html b/nerochan/templates/tips.html new file mode 100644 index 0000000..a4a72a5 --- /dev/null +++ b/nerochan/templates/tips.html @@ -0,0 +1,34 @@ +{% extends 'includes/base.html' %} + +{% block content %} + +
+
+

tips

+
{{ total | atomic }} XMR has been confirmed as sent directly to the artists on this platform.
+ + + + + + + + + + + + {% for tx in tips %} + + + + + + + + {% endfor %} + +
TXIDXMRArtworkArtistDate
{{ tx.tx_id | shorten }}{{ tx.atomic_xmr | atomic }}{{ tx.artwork.id }}{{ tx.artwork.user.handle }}{{ tx.tx_date | humanize }}
+
+
+ +{% endblock %}