cleaning up admin, getting tips shown

master
lza_menace 2 years ago
parent bd3661c063
commit c309953be3

@ -11,44 +11,27 @@ bp = Blueprint('admin', 'admin', url_prefix='/admin')
@bp.route('', methods=['GET', 'POST']) @bp.route('', methods=['GET', 'POST'])
@login_required @login_required
@admin_required @admin_required
def main(): def dashboard():
artists = User.select().where(User.is_verified == True).count() artists = User.select().where(User.is_verified == True).count()
admins = User.select().where(User.is_admin == True).count() admins = User.select().where(User.is_admin == True).count()
active_artworks = Artwork.select().where(Artwork.approved == True).count() active_artworks = Artwork.select().where(Artwork.approved == True).count()
pending_artworks = Artwork.select().where(Artwork.approved == False).count() pending_artworks = Artwork.select().where(Artwork.approved == False).count()
confirmed_tips = Transaction.select().where(Transaction.verified == True).count() confirmed_tips = Transaction.select().where(Transaction.verified == True).count()
pending_tips = Transaction.select().where(Transaction.verified == False).count() pending_tips = Transaction.select().where(Transaction.verified == False).count()
# admin_form = UserForm() #
# artist_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(): # if artist_form.validate_on_submit():
# u = User.select().where(User.handle == artist_form.handle.data).first() # u = User.select().where(User.handle == artist_form.handle.data).first()
# u.is_verified = True # u.is_verified = True
# u.save() # u.save()
# return redirect(request.referrer) # 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()) # 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()) # artists = User.select().where(User.is_verified == True).order_by(User.register_date.desc())
return render_template( return render_template(
'admin/main.html', 'admin/dashboard.html',
artists=artists, artists=artists,
admins=admins, admins=admins,
active_artworks=active_artworks, active_artworks=active_artworks,
@ -57,8 +40,55 @@ def main():
pending_tips=pending_tips, pending_tips=pending_tips,
) )
def admins(): @bp.route('/<item>', methods=['GET', 'POST'])
pass @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(): def artists():
pass pass

@ -12,6 +12,11 @@ bp = Blueprint('artwork', 'artwork', url_prefix='/artwork')
def list(): def list():
return 'show all artwork' return 'show all artwork'
@bp.route('/pending')
def pending():
return 'show pending artwork'
@bp.route('/<int:id>', methods=['GET', 'POST']) @bp.route('/<int:id>', methods=['GET', 'POST'])
def show(id): def show(id):
form = ConfirmTip() form = ConfirmTip()

@ -2,7 +2,7 @@ from os import path
from flask import Blueprint, render_template, send_from_directory 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 from nerochan import config
@ -17,9 +17,13 @@ def index():
Artwork.approved == True, Artwork.approved == True,
Artwork.hidden == False Artwork.hidden == False
).order_by(Artwork.upload_date.desc()).limit(10) ).order_by(Artwork.upload_date.desc()).limit(10)
transactions = Transaction.select().where(
Transaction.verified == True
).order_by(Transaction.tx_date.desc()).limit(10)
feed = { feed = {
'users': users, 'users': users,
'artwork': artwork 'artwork': artwork,
'tips': transactions
} }
return render_template( return render_template(
'index.html', 'index.html',
@ -35,6 +39,17 @@ def uploaded_file(filename):
file_path = path.join(config.DATA_PATH, 'uploads') file_path = path.join(config.DATA_PATH, 'uploads')
return send_from_directory(file_path, filename) 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 artworks
# most tipped artists # most tipped artists

@ -6,6 +6,10 @@ from nerochan.models import User
bp = Blueprint('user', 'user') bp = Blueprint('user', 'user')
@bp.route('/users')
def list():
return 'users list'
@bp.route('/user/<handle>') @bp.route('/user/<handle>')
def show(handle: str): def show(handle: str):
user = User.select().where(User.handle == handle).first() user = User.select().where(User.handle == handle).first()

@ -12,6 +12,10 @@ a, a:visited {
margin-left: 2em; margin-left: 2em;
} }
.mt-4 {
margin-top: 4em;
}
ul { ul {
list-style: circle; list-style: circle;
} }

@ -1,37 +0,0 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<h1>admins</h1>
<p>
Add a homie to be an admin. <br />
Admins can manage other admins as well as hide artwork, <br />
approve/reject artwork, ban artists, and verify artists.
</p>
<form method="post" action="">
{{ admin_form.csrf_token }}
<div class="row">
<div class="two columns">
{{ admin_form.handle }}
</div>
<div class="two columns">
<input class="button-primary" type="submit" value="Submit">
</div>
</div>
<ul>
{%- for field, errors in admin_form.errors.items() %}
<li>{{ ', '.join(errors) }}</li>
{%- endfor %}
</ul>
</form>
<ul>
{% for admin in admins %}
<li><h6>{{ admin.handle }} - <a href="?remove={{ admin.handle }}">remove</a></h6></li>
{% endfor %}
</ul>
</div>
</div>
{% endblock %}

@ -1,36 +0,0 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<h1>artists</h1>
<p>
Verified artists will skip the queue <br />
and have their artwork displayed immediately.
</p>
<form method="post" action="">
{{ artist_form.csrf_token }}
<div class="row">
<div class="two columns">
{{ artist_form.handle }}
</div>
<div class="two columns">
<input class="button-primary" type="submit" value="Submit">
</div>
</div>
<ul>
{%- for field, errors in artist_form.errors.items() %}
<li>{{ ', '.join(errors) }}</li>
{%- endfor %}
</ul>
</form>
<ul>
{% for artist in artists %}
<li><h6>{{ artist.handle }} - <a href="?unverify={{ artist.handle }}">remove</a></h6></li>
{% endfor %}
</ul>
</div>
</div>
{% endblock %}

@ -0,0 +1,55 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<div class="four columns">
<h1>{{ admins }}</h1>
<h5>
<a href="{{ url_for('admin.manage', item='admins') }}">
admin{% if admins != 1 %}s{% endif %}
</a>
</h5>
</div>
<div class="four columns">
<h1>{{ artists }}</h1>
<h5>
<a href="{{ url_for('admin.manage', item='artists') }}">
verified<br />artist{% if artists != 1 %}s{% endif %}
</a>
</h5>
</div>
<div class="three columns">
<h1>{{ pending_artworks }}</h1>
<h5>
<a href="{{ url_for('artwork.pending') }}">
pending<br />artwork{% if pending_artworks != 1 %}s{% endif %}</h5>
</a>
</div>
</div>
<br />
<div class="row">
<div class="four columns">
<h1>{{ confirmed_tips }}</h1>
<h5>
<a href="{{ url_for('main.tips') }}">
confirmed<br />tip{% if confirmed_tips != 1 %}s{% endif %}</h5>
</a>
</div>
<div class="four columns">
<h1>{{ pending_tips }}</h1>
<h5>pending<br />tip{% if pending_tips != 1 %}s{% endif %}</h5>
</div>
<div class="four columns">
<h1>{{ active_artworks }}</h1>
<h5>
<a href="{{ url_for('artwork.list') }}">
active<br />artwork{% if active_artworks != 1 %}s{% endif %}
</a>
</h5>
</div>
</div>
</div>
{% endblock %}

@ -1,37 +0,0 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<div class="three columns">
<h1>{{ admins }}</h1>
<h5>admin{% if admins != 1 %}s{% endif %}</h5>
</div>
<div class="three columns">
<h1>{{ artists }}</h1>
<h5>verified<br />artist{% if artists != 1 %}s{% endif %}</h5>
</div>
<div class="three columns">
<h1>{{ active_artworks }}</h1>
<h5>active<br />artwork{% if active_artworks != 1 %}s{% endif %}</h5>
</div>
<div class="three columns">
<h1>{{ pending_artworks }}</h1>
<h5>pending<br />artwork{% if pending_artworks != 1 %}s{% endif %}</h5>
</div>
</div>
<br />
<div class="row">
<div class="three columns">
<h1>{{ confirmed_tips }}</h1>
<h5>confirmed<br />tip{% if confirmed_tips != 1 %}s{% endif %}</h5>
</div>
<div class="three columns">
<h1>{{ pending_tips }}</h1>
<h5>pending<br />tip{% if pending_tips != 1 %}s{% endif %}</h5>
</div>
</div>
</div>
{% endblock %}

@ -0,0 +1,49 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<h1>{{ item }}</h1>
{% if item == 'admins' %}
<p>
Add a homie to be an admin. <br />
Admins can manage other admins as well as hide artwork, <br />
approve/reject artwork, ban artists, and verify artists.
</p>
{% elif item == 'artists' %}
<p>
Verified artists will skip the queue <br />
and have their artwork displayed immediately.
</p>
{% endif %}
<form method="post" action="">
{{ form.csrf_token }}
<div class="row">
<div class="three columns">
{{ form.handle }}
</div>
<div class="two columns">
<input class="button-primary" type="submit" value="Submit">
</div>
</div>
<ul>
{%- for field, errors in form.errors.items() %}
<li>{{ ', '.join(errors) }}</li>
{%- endfor %}
</ul>
</form>
<ul>
{% for item in items %}
<li>
<h6>{{ item.handle }} - <a href="?{{ action }}={{ item.handle }}">{{ action }}</a></h6>
</li>
{% endfor %}
</ul>
</div>
<div class="row mt-4">
<a href="{{ url_for('admin.dashboard') }}">...back to admin</a>
</div>
</div>
{% endblock %}

@ -5,7 +5,7 @@
<li class="navbar-item"><a class="navbar-link" href="{{ url_for('main.about') }}">About</a></li> <li class="navbar-item"><a class="navbar-link" href="{{ url_for('main.about') }}">About</a></li>
{%- if current_user.is_authenticated %} {%- if current_user.is_authenticated %}
{%- if current_user.is_admin %} {%- if current_user.is_admin %}
<li class="navbar-item"><a class="navbar-link" href="{{ url_for('admin.main') }}">Admin</a></li> <li class="navbar-item"><a class="navbar-link" href="{{ url_for('admin.dashboard') }}">Admin</a></li>
{% endif %} {% endif %}
<li class="navbar-item ml-2"><a class="navbar-link" href="{{ url_for('auth.logout') }}">Logout</a></li> <li class="navbar-item ml-2"><a class="navbar-link" href="{{ url_for('auth.logout') }}">Logout</a></li>
{%- else %} {%- else %}

@ -13,7 +13,7 @@
</a> </a>
{%- endfor %} {%- endfor %}
{%- endfor %} {%- endfor %}
<p><a href="{{ url_for('artwork.list') }}">...view all</a></p> <p class="mt-4"><a href="{{ url_for('artwork.list') }}">...view all</a></p>
{% else %} {% else %}
<p>There's nothing here yet...</p> <p>There's nothing here yet...</p>
{% endif %} {% endif %}
@ -24,15 +24,41 @@
{% for user in feed['users'] %} {% for user in feed['users'] %}
<p><a href="{{ url_for('user.show', handle=user.handle) }}">{{ user.handle }}</a></p> <p><a href="{{ url_for('user.show', handle=user.handle) }}">{{ user.handle }}</a></p>
{% endfor %} {% endfor %}
<p class="mt-4"><a href="{{ url_for('user.list') }}">...view all</a></p>
{% else %}
<p>There's nothing here yet...</p>
{% endif %}
</div>
<div class="row">
<h1>tips</h1>
{% if feed['tips'] %}
<table class="u-full-width">
<thead>
<tr>
<th>TXID</th>
<th>XMR</th>
<th>Artwork</th>
<th>Artist</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for tx in feed['tips'] %}
<tr>
<td><a href="{{ tx.tx_id | xmr_block_explorer }}" target="_blank">{{ tx.tx_id | shorten }}</a></td>
<td>{{ tx.atomic_xmr | atomic }}</td>
<td><a href="{{ url_for('artwork.show', id=tx.artwork.id) }}">{{ tx.artwork.id }}</a></td>
<td><a href="{{ url_for('user.show', handle=tx.artwork.user.handle) }}">{{ tx.artwork.user.handle }}</a></td>
<td>{{ tx.tx_date | humanize }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<p class="mt-4"><a href="{{ url_for('main.tips') }}">...view all</a></p>
{% else %} {% else %}
<p>There's nothing here yet...</p> <p>There's nothing here yet...</p>
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% if current_user.is_authenticated %}
<p>logged in: {{ current_user.handle }}</p>
{% endif %}
{% endblock %} {% endblock %}

@ -0,0 +1,34 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<h1>tips</h1>
<h6>{{ total | atomic }} XMR has been confirmed as sent directly to the artists on this platform.</h6>
<table class="u-full-width">
<thead>
<tr>
<th>TXID</th>
<th>XMR</th>
<th>Artwork</th>
<th>Artist</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for tx in tips %}
<tr>
<td><a href="{{ tx.tx_id | xmr_block_explorer }}" target="_blank">{{ tx.tx_id | shorten }}</a></td>
<td>{{ tx.atomic_xmr | atomic }}</td>
<td><a href="{{ url_for('artwork.show', id=tx.artwork.id) }}">{{ tx.artwork.id }}</a></td>
<td><a href="{{ url_for('user.show', handle=tx.artwork.user.handle) }}">{{ tx.artwork.user.handle }}</a></td>
<td>{{ tx.tx_date | humanize }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
Loading…
Cancel
Save