get artwork list working

master
lza_menace 2 years ago
parent 8208971f76
commit df449ad4ed

@ -116,7 +116,6 @@ class Artwork(pw.Model):
if self.image.endswith('.gif'): if self.image.endswith('.gif'):
image = Image.open(i) image = Image.open(i)
frames = ImageSequence.Iterator(image) frames = ImageSequence.Iterator(image)
image.close()
def thumbnails(frames): def thumbnails(frames):
for frame in frames: for frame in frames:
thumbnail = frame.copy().convert('RGBA') thumbnail = frame.copy().convert('RGBA')
@ -129,6 +128,7 @@ class Artwork(pw.Model):
_image.info = image.info _image.info = image.info
_image.save(t, save_all=True, append_images=list(_frames), disposal=2) _image.save(t, save_all=True, append_images=list(_frames), disposal=2)
_image.close() _image.close()
image.close()
elif self.is_video: elif self.is_video:
cap = VideoCapture(i) cap = VideoCapture(i)
_, frame = cap.read() _, frame = cap.read()

@ -14,9 +14,9 @@ bp = Blueprint('admin', 'admin', url_prefix='/admin')
def dashboard(): def dashboard():
artists = User.select().where(User.is_verified == True).count() artists = User.select().where(User.is_verified == True).count()
admins = User.select().where(User.is_admin == 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() 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() confirmed_tips = Transaction.select().where(Transaction.verified == True).count()
pending_tips = Transaction.select().where(Transaction.verified == False).count() pending_tips = Transaction.select().where(Transaction.verified == False).count()
return render_template( return render_template(

@ -1,3 +1,4 @@
from math import ceil
from pathlib import Path from pathlib import Path
from secrets import token_urlsafe from secrets import token_urlsafe
@ -15,7 +16,25 @@ bp = Blueprint('artwork', 'artwork', url_prefix='/artwork')
@bp.route('') @bp.route('')
def list(): 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') @bp.route('/pending')
@login_required @login_required
@ -77,6 +96,12 @@ def manage(id, action):
artwork.generate_thumbnail() artwork.generate_thumbnail()
flash(f'Generated new thumbnail for artwork {artwork.id}', 'success') flash(f'Generated new thumbnail for artwork {artwork.id}', 'success')
return redirect(url_for('artwork.show', id=artwork.id)) 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')) return redirect(url_for('artwork.pending'))

@ -0,0 +1,39 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<h1>artworks</h1>
{% if artwork %}
{%- for _artwork in artwork | batch(4) %}
{%- for artwork in _artwork %}
<a class="artworkLink" href="{{ url_for('artwork.show', id=artwork.id) }}">
<img src="{{ url_for('main.uploaded_file', filename=artwork.thumbnail) }}" width="150px">
</a>
{%- endfor %}
{%- endfor %}
{% else %}
<p>There's nothing here yet...</p>
{% endif %}
</div>
{% if artwork %}
<div class="row mt-4">
<span class="inline">
{% for i in range(1, total_pages + 1) %}
<h6 class="inline">
{% if i == page %}
{{ page }}
{% else %}
<a href="?page={{ i }}">{{ i }}</a>
{% endif %}
</h6>
{% endfor %}
</span>
</div>
{% endif %}
</div>
{% endblock %}

@ -7,7 +7,9 @@
<div class="row"> <div class="row">
<h2 class="no-margin"><strong>{{ artwork.title }}</strong></h2> <h2 class="no-margin"><strong>{{ artwork.title }}</strong></h2>
<span> <span>
{% if artwork.nsfw %}
<p class="inline nsfw">NSFW</p> <p class="inline nsfw">NSFW</p>
{% endif %}
<h6 class="no-margin inline"> <h6 class="no-margin inline">
posted by <a href="{{ url_for('user.show', handle=artwork.user.handle) }}">{{ artwork.user.handle }}</a> - {{ artwork.upload_date | humanize }} posted by <a href="{{ url_for('user.show', handle=artwork.user.handle) }}">{{ artwork.user.handle }}</a> - {{ artwork.upload_date | humanize }}
</h6> </h6>
@ -16,12 +18,13 @@
<div class="row"> <div class="row">
{% if current_user.is_authenticated and current_user.is_admin %} {% if current_user.is_authenticated and current_user.is_admin %}
<a href="{{ url_for('artwork.manage', id=artwork.id, action='regenerate_thumbnail') }}"><button class="button">Regen Thumbnail</button></a> <a href="{{ url_for('artwork.manage', id=artwork.id, action='regenerate_thumbnail') }}"><button class="button">Regen Thumbnail</button></a>
<a href="{{ url_for('artwork.manage', id=artwork.id, action='toggle_nsfw') }}"><button class="button">Toggle NSFW</button></a>
{% endif %} {% endif %}
{% if not artwork.approved %} {% if not artwork.approved %}
{% if artwork.hidden %} {% if artwork.hidden %}
<a href="{{ url_for('artwork.manage', id=artwork.id, action='delete') }}"><button class="button-secondary">Delete</button></a> <a href="{{ url_for('artwork.manage', id=artwork.id, action='delete') }}"><button class="button-secondary">Delete</button></a>
{% else %} {% else %}
<a href="{{ url_for('artwork.manage', id=artwork.id, action='reject') }}"><button class="button">Reject</button></a> <a href="{{ url_for('artwork.manage', id=artwork.id, action='reject') }}"><button class="button-secondary">Reject</button></a>
{% endif %} {% endif %}
<a href="{{ url_for('artwork.manage', id=artwork.id, action='approve') }}"><button class="button-primary">Approve</button></a> <a href="{{ url_for('artwork.manage', id=artwork.id, action='approve') }}"><button class="button-primary">Approve</button></a>
{% endif %} {% endif %}

Loading…
Cancel
Save