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 os import path, makedirs
from urllib.request import urlopen 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 from nerochan.models import User, Artwork, Transaction
@ -52,7 +52,7 @@ def cli(app):
try: try:
res = make_wallet_rpc('check_tx_key', data) res = make_wallet_rpc('check_tx_key', data)
if res['in_pool'] is False: 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) d = txdata.timestamp.astimezone(timezone.utc)
tx.atomic_xmr = res['received'] tx.atomic_xmr = res['received']
tx.tx_date = d tx.tx_date = d

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

@ -3,7 +3,7 @@ from flask_login import login_required, current_user
from nerochan.forms import UserForm from nerochan.forms import UserForm
from nerochan.decorators import admin_required 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') bp = Blueprint('admin', 'admin', url_prefix='/admin')
@ -12,46 +12,63 @@ bp = Blueprint('admin', 'admin', url_prefix='/admin')
@login_required @login_required
@admin_required @admin_required
def main(): def main():
admin_form = UserForm() artists = User.select().where(User.is_verified == True).count()
artist_form = UserForm() admins = User.select().where(User.is_admin == True).count()
if admin_form.validate_on_submit(): active_artworks = Artwork.select().where(Artwork.approved == True).count()
u = User.select().where(User.handle == admin_form.handle.data).first() pending_artworks = Artwork.select().where(Artwork.approved == False).count()
u.is_admin = True confirmed_tips = Transaction.select().where(Transaction.verified == True).count()
u.save() pending_tips = Transaction.select().where(Transaction.verified == False).count()
return redirect(request.referrer) # admin_form = UserForm()
if artist_form.validate_on_submit(): # artist_form = UserForm()
u = User.select().where(User.handle == artist_form.handle.data).first() # if admin_form.validate_on_submit():
u.is_verified = True # u = User.select().where(User.handle == admin_form.handle.data).first()
u.save() # u.is_admin = True
return redirect(request.referrer) # u.save()
if request.args.get('remove'): # return redirect(request.referrer)
a = User.select().where(User.handle == request.args.get('remove')).first() # if artist_form.validate_on_submit():
if a == current_user: # u = User.select().where(User.handle == artist_form.handle.data).first()
flash('cannot delete yourself') # u.is_verified = True
return redirect(url_for('admin.main')) # u.save()
if a: # return redirect(request.referrer)
a.is_admin = False # if request.args.get('remove'):
a.save() # a = User.select().where(User.handle == request.args.get('remove')).first()
return redirect(url_for('admin.main')) # if a == current_user:
if request.args.get('unverify'): # flash('cannot delete yourself')
a = User.select().where(User.handle == request.args.get('unverify')).first() # return redirect(url_for('admin.main'))
if a: # if a:
a.is_verified = False # a.is_admin = False
a.save() # a.save()
return redirect(url_for('admin.main')) # return redirect(url_for('admin.main'))
admins = User.select().where(User.is_admin == True).order_by(User.register_date.desc()) # if request.args.get('unverify'):
artists = User.select().where(User.is_verified == True).order_by(User.register_date.desc()) # 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( return render_template(
'admin/main.html', 'admin/main.html',
admins=admins,
artists=artists, artists=artists,
admin_form=admin_form, admins=admins,
artist_form=artist_form 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 # approve artwork
# ban user # ban user
# allow user # unban user
# hide artwork # hide artwork
# promote mod # promote mod
# demote 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="container">
<div class="row"> <div class="row">
<h1>admins</h1> <div class="three columns">
<p> <h1>{{ admins }}</h1>
Add a homie to be an admin. <br /> <h5>admin{% if admins != 1 %}s{% endif %}</h5>
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>
<div class="two columns"> <div class="three columns">
<input class="button-primary" type="submit" value="Submit"> <h1>{{ artists }}</h1>
<h5>verified<br />artist{% if artists != 1 %}s{% endif %}</h5>
</div> </div>
<div class="three columns">
<h1>{{ active_artworks }}</h1>
<h5>active<br />artwork{% if active_artworks != 1 %}s{% endif %}</h5>
</div> </div>
<ul> <div class="three columns">
{%- for field, errors in admin_form.errors.items() %} <h1>{{ pending_artworks }}</h1>
<li>{{ ', '.join(errors) }}</li> <h5>pending<br />artwork{% if pending_artworks != 1 %}s{% endif %}</h5>
{%- 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>
<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>
<div class="two columns"> <br />
<input class="button-primary" type="submit" value="Submit"> <div class="row">
<div class="three columns">
<h1>{{ confirmed_tips }}</h1>
<h5>confirmed<br />tip{% if confirmed_tips != 1 %}s{% endif %}</h5>
</div> </div>
<div class="three columns">
<h1>{{ pending_tips }}</h1>
<h5>pending<br />tip{% if pending_tips != 1 %}s{% endif %}</h5>
</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>
</div> </div>

Loading…
Cancel
Save