redoing admin a bit

master
lza_menace 2 years ago
parent 4c5a2bc1d6
commit bd3661c063

@ -6,7 +6,7 @@ from datetime import datetime, timedelta, timezone
from os import path, makedirs
from urllib.request import urlopen
from nerochan.helpers import make_wallet_rpc, daemon
from nerochan.helpers import make_wallet_rpc, get_daemon
from nerochan.models import User, Artwork, Transaction
@ -52,7 +52,7 @@ def cli(app):
try:
res = make_wallet_rpc('check_tx_key', data)
if res['in_pool'] is False:
txdata = daemon.transactions([tx.tx_id])[0]
txdata = get_daemon().transactions([tx.tx_id])[0]
d = txdata.timestamp.astimezone(timezone.utc)
tx.atomic_xmr = res['received']
tx.tx_date = d

@ -4,22 +4,24 @@ from monero.daemon import Daemon
from nerochan import config
daemon = Daemon(
def get_daemon():
return Daemon(
host=config.XMR_DAEMON_HOST,
port=config.XMR_DAEMON_PORT,
timeout=3
)
)
wallet = Wallet(
def get_wallet():
return Wallet(
port=config.XMR_WALLET_RPC_PORT,
user=config.XMR_WALLET_RPC_USER,
password=config.XMR_WALLET_RPC_PASS,
timeout=3
)
)
def make_wallet_rpc(method, data={}):
try:
w = wallet
w = get_wallet()
res = w._backend.raw_request(method, data)
return res
except Exception as e:
@ -27,7 +29,7 @@ def make_wallet_rpc(method, data={}):
def make_daemon_rpc(method, data={}):
try:
d = daemon
d = get_daemon()
res = d._backend.raw_request(method, data)
return res
except Exception as e:

@ -3,7 +3,7 @@ from flask_login import login_required, current_user
from nerochan.forms import UserForm
from nerochan.decorators import admin_required
from nerochan.models import User
from nerochan.models import User, Artwork, Transaction
bp = Blueprint('admin', 'admin', url_prefix='/admin')
@ -12,46 +12,63 @@ bp = Blueprint('admin', 'admin', url_prefix='/admin')
@login_required
@admin_required
def main():
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())
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',
admins=admins,
artists=artists,
admin_form=admin_form,
artist_form=artist_form
admins=admins,
active_artworks=active_artworks,
pending_artworks=pending_artworks,
confirmed_tips=confirmed_tips,
pending_tips=pending_tips,
)
def admins():
pass
def artists():
pass
def users():
pass
# approve artwork
# ban user
# allow user
# unban user
# hide artwork
# promote mod
# demote mod

@ -0,0 +1,37 @@
{% 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 %}

@ -0,0 +1,36 @@
{% 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 %}

@ -4,62 +4,33 @@
<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 class="three columns">
<h1>{{ admins }}</h1>
<h5>admin{% if admins != 1 %}s{% endif %}</h5>
</div>
<div class="two columns">
<input class="button-primary" type="submit" value="Submit">
<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>
<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 class="three columns">
<h1>{{ pending_artworks }}</h1>
<h5>pending<br />artwork{% if pending_artworks != 1 %}s{% endif %}</h5>
</div>
<hr>
<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">
<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>
<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>

Loading…
Cancel
Save