get more artwork admin working

master
lza_menace 2 years ago
parent c309953be3
commit ea6d434575

@ -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()
)

@ -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

@ -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('/<int:id>/<action>')
@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('/<int:id>', 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:

@ -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;
}

@ -50,6 +50,15 @@
</h5>
</div>
</div>
<div class="row">
<div class="twelve columns">
<h1>{{ hidden_artworks }}</h1>
<h5>
<a href="{{ url_for('artwork.hidden') }}">
hidden<br />artwork{% if hidden_artworks != 1 %}s{% endif %}</h5>
</a>
</div>
</div>
</div>
{% endblock %}

@ -0,0 +1,23 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<h1>hidden</h1>
<p>These artworks were rejected by admins. You can choose to delete them now.</p>
{% if artwork %}
{%- for _artwork in artwork | batch(4) %}
{%- for art in _artwork %}
<a class="artworkLink" href="{{ url_for('artwork.show', id=art.id) }}">
<img src="{{ url_for('main.uploaded_file', filename=art.thumbnail) }}" width="150px">
</a>
{%- endfor %}
{%- endfor %}
{% else %}
<p>There's nothing pending approval...</p>
{% endif %}
</div>
</div>
{% endblock %}

@ -0,0 +1,27 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<h1>pending</h1>
<p>
These artworks were uploaded by users who have not yet been verified.
<br/>
They will not be shown to the public until approved by an admin.
</p>
{% if artwork %}
{%- for _artwork in artwork | batch(4) %}
{%- for art in _artwork %}
<a class="artworkLink" href="{{ url_for('artwork.show', id=art.id) }}">
<img src="{{ url_for('main.uploaded_file', filename=art.thumbnail) }}" width="150px">
</a>
{%- endfor %}
{%- endfor %}
{% else %}
<p>There's nothing pending approval...</p>
{% endif %}
</div>
</div>
{% endblock %}

@ -10,6 +10,17 @@
posted by <a href="{{ url_for('user.show', handle=artwork.user.handle) }}">{{ artwork.user.handle }}</a> - {{ artwork.upload_date | humanize }}
</h6>
<p class="artworkDescription">{{ artwork.description }}</p>
{% if not artwork.approved %}
<div class="row">
{% if artwork.hidden %}
<a href="{{ url_for('artwork.manage', id=artwork.id, action='delete') }}"><button class="button-secondary">Delete</button></a>
{% else %}
<a href="{{ url_for('artwork.manage', id=artwork.id, action='reject') }}"><button class="button">Reject</button></a>
{% endif %}
<a href="{{ url_for('artwork.manage', id=artwork.id, action='approve') }}"><button class="button-primary">Approve</button></a>
</div>
{% endif %}
</div>
<hr>
<div class="row">

Loading…
Cancel
Save