diff --git a/nerochan/cli.py b/nerochan/cli.py index b67b0a2..90e8030 100644 --- a/nerochan/cli.py +++ b/nerochan/cli.py @@ -95,7 +95,10 @@ def cli(app): 'https://www.monerochan.art/commissions/dandelion.png', 'https://www.monerochan.art/commissions/volleyball_1.jpg', 'https://www.monerochan.art/commissions/volleyball_2.jpg', - 'https://www.monerochan.art/commissions/virgin_killer.png' + 'https://www.monerochan.art/commissions/virgin_killer.png', + 'https://www.monerochan.art/commissions/mememe_bikini.gif', + 'https://www.monerochan.art/commissions/lofi_monerochan.mp4', + 'https://www.monerochan.art/commissions/Doompa.webm' ] } } @@ -125,7 +128,7 @@ def cli(app): artwork = Artwork( user=_user, image=bn, - approved=True, + approved=False, title=lorem.sentence(), description=lorem.sentence() ) diff --git a/nerochan/routes/admin.py b/nerochan/routes/admin.py index 6bca183..4df27f9 100644 --- a/nerochan/routes/admin.py +++ b/nerochan/routes/admin.py @@ -15,26 +15,16 @@ 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() + hidden_artworks = Artwork.select().where(Artwork.hidden == 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() - # - # artist_form = UserForm() - - # 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) - - - # 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/dashboard.html', artists=artists, admins=admins, active_artworks=active_artworks, + hidden_artworks=hidden_artworks, pending_artworks=pending_artworks, confirmed_tips=confirmed_tips, pending_tips=pending_tips, @@ -90,11 +80,6 @@ def manage(item): form=form ) -def artists(): - pass - -def users(): - pass # approve artwork # ban user diff --git a/nerochan/routes/artwork.py b/nerochan/routes/artwork.py index 1e1a9da..461f7e6 100644 --- a/nerochan/routes/artwork.py +++ b/nerochan/routes/artwork.py @@ -1,9 +1,12 @@ -from flask import Blueprint, render_template, flash, redirect, url_for -from flask_login import login_required +from pathlib import Path + +from flask import Blueprint, render_template, flash, redirect, url_for, request +from flask_login import login_required, current_user -from nerochan.helpers import make_wallet_rpc from nerochan.forms import ConfirmTip +from nerochan.decorators import admin_required from nerochan.models import Artwork, Transaction +from nerochan import config bp = Blueprint('artwork', 'artwork', url_prefix='/artwork') @@ -13,8 +16,62 @@ def list(): return 'show all artwork' @bp.route('/pending') +@login_required +@admin_required def pending(): - return 'show pending artwork' + artwork = Artwork.select().where( + Artwork.approved == False, + Artwork.hidden == False + ).order_by(Artwork.upload_date.asc()) + return render_template( + 'artwork/pending.html', + artwork=artwork + ) + +@bp.route('/hidden') +@login_required +@admin_required +def hidden(): + artwork = Artwork.select().where( + Artwork.hidden == True + ).order_by(Artwork.upload_date.asc()) + return render_template( + 'artwork/hidden.html', + artwork=artwork + ) + +@bp.route('//') +@login_required +@admin_required +def manage(id, action): + artwork = Artwork.get_or_none(id) + if not artwork: + flash('That artwork does not exist.', 'warning') + return redirect(url_for('main.index')) + if action == 'approve': + artwork.approved = True + artwork.hidden = False + artwork.save() + flash(f'Artwork {artwork.id} has been approved', 'success') + elif action == 'reject': + artwork.approved = False + artwork.hidden = True + artwork.save() + flash(f'Artwork {artwork.id} has been rejected and hidden', 'success') + elif action == 'delete': + if artwork.approved: + flash('Cannot delete an artwork that is already approved', 'warning') + return redirect(url_for('artwork.show', id=artwork.id)) + elif not artwork.hidden: + flash('Cannot delete an artwork unless it is hidden first', 'warning') + return redirect(url_for('artwork.show', id=artwork.id)) + base = Path(config.DATA_PATH).joinpath('uploads') + base.joinpath(artwork.image).unlink(missing_ok=True) + base.joinpath(artwork.thumbnail).unlink(missing_ok=True) + artwork.delete_instance() + flash('Artwork has been deleted from the system.', 'success') + return redirect(url_for('artwork.hidden')) + return redirect(url_for('artwork.pending')) @bp.route('/', methods=['GET', 'POST']) @@ -24,6 +81,10 @@ def show(id): if not artwork: flash('That artwork does not exist.', 'warning') return redirect(url_for('main.index')) + if not artwork.approved: + if not current_user.is_authenticated or not current_user.is_admin: + flash('That artwork is pending approval.') + return redirect(url_for('main.index')) if form.validate_on_submit(): # Create a tx object to verify later try: diff --git a/nerochan/static/css/main.css b/nerochan/static/css/main.css index 2512cee..ddc5f47 100644 --- a/nerochan/static/css/main.css +++ b/nerochan/static/css/main.css @@ -16,6 +16,33 @@ a, a:visited { margin-top: 4em; } +.button { + color: white; + border: 1px solid white; + transition: all .3s ease; +} + +.button:hover { + color: black; + border: 1px solid white; + background-color: white; + transition: all .3s ease; +} + +.button-secondary { + color: black; + background-color: white; + border: 1px solid white; + transition: all .3s ease; +} + +.button-secondary:hover { + color: white; + border: 1px solid red; + background-color: red; + transition: all .3s ease; +} + ul { list-style: circle; } diff --git a/nerochan/templates/admin/dashboard.html b/nerochan/templates/admin/dashboard.html index 7185ed6..a136aa0 100644 --- a/nerochan/templates/admin/dashboard.html +++ b/nerochan/templates/admin/dashboard.html @@ -50,6 +50,15 @@ + {% endblock %} diff --git a/nerochan/templates/artwork/hidden.html b/nerochan/templates/artwork/hidden.html new file mode 100644 index 0000000..bec19a8 --- /dev/null +++ b/nerochan/templates/artwork/hidden.html @@ -0,0 +1,23 @@ +{% extends 'includes/base.html' %} + +{% block content %} + +
+
+

hidden

+

These artworks were rejected by admins. You can choose to delete them now.

+ {% if artwork %} + {%- for _artwork in artwork | batch(4) %} + {%- for art in _artwork %} + + + + {%- endfor %} + {%- endfor %} + {% else %} +

There's nothing pending approval...

+ {% endif %} +
+
+ +{% endblock %} \ No newline at end of file diff --git a/nerochan/templates/artwork/pending.html b/nerochan/templates/artwork/pending.html new file mode 100644 index 0000000..ec489ee --- /dev/null +++ b/nerochan/templates/artwork/pending.html @@ -0,0 +1,27 @@ +{% extends 'includes/base.html' %} + +{% block content %} + +
+
+

pending

+

+ These artworks were uploaded by users who have not yet been verified. +
+ They will not be shown to the public until approved by an admin. +

+ {% if artwork %} + {%- for _artwork in artwork | batch(4) %} + {%- for art in _artwork %} + + + + {%- endfor %} + {%- endfor %} + {% else %} +

There's nothing pending approval...

+ {% endif %} +
+
+ +{% endblock %} \ No newline at end of file diff --git a/nerochan/templates/artwork/show.html b/nerochan/templates/artwork/show.html index d3b272e..01cc76b 100644 --- a/nerochan/templates/artwork/show.html +++ b/nerochan/templates/artwork/show.html @@ -10,6 +10,17 @@ posted by {{ artwork.user.handle }} - {{ artwork.upload_date | humanize }}

{{ artwork.description }}

+ {% if not artwork.approved %} +
+ {% if artwork.hidden %} + + {% else %} + + {% endif %} + + +
+ {% endif %}