From df449ad4ed30d085340d5a9bbf5ac0a6b4050862 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sat, 3 Dec 2022 01:41:34 -0800 Subject: [PATCH] get artwork list working --- nerochan/models.py | 2 +- nerochan/routes/admin.py | 4 +-- nerochan/routes/artwork.py | 27 ++++++++++++++++++- nerochan/templates/artwork/list.html | 39 ++++++++++++++++++++++++++++ nerochan/templates/artwork/show.html | 5 +++- 5 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 nerochan/templates/artwork/list.html 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 %} + +
+
+

artworks

+ {% if artwork %} + {%- for _artwork in artwork | batch(4) %} + {%- for artwork in _artwork %} + + + + {%- endfor %} + {%- endfor %} + + + {% else %} +

There's nothing here yet...

+ {% endif %} +
+ {% if artwork %} +
+ + {% for i in range(1, total_pages + 1) %} +
+ {% if i == page %} + {{ page }} + {% else %} + {{ i }} + {% endif %} +
+ {% endfor %} +
+
+ {% endif %} +
+ +{% endblock %} diff --git a/nerochan/templates/artwork/show.html b/nerochan/templates/artwork/show.html index 2891d67..d89b948 100644 --- a/nerochan/templates/artwork/show.html +++ b/nerochan/templates/artwork/show.html @@ -7,7 +7,9 @@

{{ artwork.title }}

+ {% if artwork.nsfw %}

NSFW

+ {% endif %}
posted by {{ artwork.user.handle }} - {{ artwork.upload_date | humanize }}
@@ -16,12 +18,13 @@
{% if current_user.is_authenticated and current_user.is_admin %} + {% endif %} {% if not artwork.approved %} {% if artwork.hidden %} {% else %} - + {% endif %} {% endif %}