diff --git a/nerochan/cli.py b/nerochan/cli.py index c0451e1..b67b0a2 100644 --- a/nerochan/cli.py +++ b/nerochan/cli.py @@ -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 diff --git a/nerochan/helpers.py b/nerochan/helpers.py index 8ebfc1b..4dc92aa 100644 --- a/nerochan/helpers.py +++ b/nerochan/helpers.py @@ -4,22 +4,24 @@ from monero.daemon import Daemon from nerochan import config -daemon = Daemon( - host=config.XMR_DAEMON_HOST, - port=config.XMR_DAEMON_PORT, - timeout=3 -) +def get_daemon(): + return Daemon( + host=config.XMR_DAEMON_HOST, + port=config.XMR_DAEMON_PORT, + timeout=3 + ) -wallet = Wallet( - port=config.XMR_WALLET_RPC_PORT, - user=config.XMR_WALLET_RPC_USER, - password=config.XMR_WALLET_RPC_PASS, - timeout=3 -) +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: diff --git a/nerochan/routes/admin.py b/nerochan/routes/admin.py index f1c5741..7983573 100644 --- a/nerochan/routes/admin.py +++ b/nerochan/routes/admin.py @@ -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 \ No newline at end of file diff --git a/nerochan/templates/admin/admins.html b/nerochan/templates/admin/admins.html new file mode 100644 index 0000000..079f15d --- /dev/null +++ b/nerochan/templates/admin/admins.html @@ -0,0 +1,37 @@ +{% extends 'includes/base.html' %} + +{% block content %} + +
+ Add a homie to be an admin.
+ Admins can manage other admins as well as hide artwork,
+ approve/reject artwork, ban artists, and verify artists.
+
+ Verified artists will skip the queue
+ and have their artwork displayed immediately.
+
- Add a homie to be an admin.
- Admins can manage other admins as well as hide artwork,
- approve/reject artwork, ban artists, and verify artists.
-
- Verified artists will skip the queue
- and have their artwork displayed immediately.
-