diff --git a/nerochan/models.py b/nerochan/models.py index d5e43d1..6618f2f 100644 --- a/nerochan/models.py +++ b/nerochan/models.py @@ -116,7 +116,6 @@ class Artwork(pw.Model): if self.image.endswith('.gif'): image = Image.open(i) frames = ImageSequence.Iterator(image) - image.close() def thumbnails(frames): for frame in frames: thumbnail = frame.copy().convert('RGBA') @@ -129,6 +128,7 @@ class Artwork(pw.Model): _image.info = image.info _image.save(t, save_all=True, append_images=list(_frames), disposal=2) _image.close() + image.close() elif self.is_video: cap = VideoCapture(i) _, frame = cap.read() diff --git a/nerochan/routes/admin.py b/nerochan/routes/admin.py index 4df27f9..d98a06b 100644 --- a/nerochan/routes/admin.py +++ b/nerochan/routes/admin.py @@ -14,9 +14,9 @@ bp = Blueprint('admin', 'admin', url_prefix='/admin') 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() + active_artworks = Artwork.select().where(Artwork.approved == True, Artwork.hidden == False).count() hidden_artworks = Artwork.select().where(Artwork.hidden == True).count() - pending_artworks = Artwork.select().where(Artwork.approved == False).count() + pending_artworks = Artwork.select().where(Artwork.approved == False, Artwork.hidden == False).count() confirmed_tips = Transaction.select().where(Transaction.verified == True).count() pending_tips = Transaction.select().where(Transaction.verified == False).count() return render_template( diff --git a/nerochan/routes/artwork.py b/nerochan/routes/artwork.py index 681ac51..3034e72 100644 --- a/nerochan/routes/artwork.py +++ b/nerochan/routes/artwork.py @@ -1,3 +1,4 @@ +from math import ceil from pathlib import Path from secrets import token_urlsafe @@ -15,7 +16,25 @@ bp = Blueprint('artwork', 'artwork', url_prefix='/artwork') @bp.route('') def list(): - return 'show all artwork' + ipp = 20 + page = request.args.get("page", 1) + try: + page = int(page) + except: + flash('Invalid page number provided.', 'warning') + page = 1 + artwork = Artwork.select().where( + Artwork.approved == True, + Artwork.hidden == False + ).order_by(Artwork.upload_date.desc()) + paginated_posts = artwork.paginate(page, ipp) + total_pages = ceil(artwork.count() / ipp) + return render_template( + 'artwork/list.html', + artwork=paginated_posts, + page=page, + total_pages=total_pages + ) @bp.route('/pending') @login_required @@ -77,6 +96,12 @@ def manage(id, action): artwork.generate_thumbnail() flash(f'Generated new thumbnail for artwork {artwork.id}', 'success') return redirect(url_for('artwork.show', id=artwork.id)) + elif action == 'toggle_nsfw': + artwork.nsfw = not artwork.nsfw + artwork.save() + artwork.generate_thumbnail() + flash(f'Toggled NSFW status for artwork {artwork.id} and regenerated thumbnail.', 'success') + return redirect(url_for('artwork.show', id=artwork.id)) return redirect(url_for('artwork.pending')) diff --git a/nerochan/templates/artwork/list.html b/nerochan/templates/artwork/list.html new file mode 100644 index 0000000..8252688 --- /dev/null +++ b/nerochan/templates/artwork/list.html @@ -0,0 +1,39 @@ +{% extends 'includes/base.html' %} + +{% block content %} + +
There's nothing here yet...
+ {% endif %} +NSFW
+ {% endif %}