votes left count

This commit is contained in:
2024-08-05 20:54:46 +02:00
parent ce788a545c
commit 8c9d97c317
3 changed files with 15 additions and 3 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{% extends "Base.html" %} {% extends "Base.html" %}
{% block window-title %} {% block window-title %}
Stemmen Stemmen{% if vote_left or skip_left %}: {{vote_left}}+{{skip_left}} te gaan.{% endif %}
{% endblock %} {% endblock %}
{% block main-content %} {% block main-content %}
+11
View File
@@ -26,6 +26,17 @@ def get_unvoted(user):
except IndexError: except IndexError:
return (None, False) return (None, False)
def get_unvoted_count(user):
votes = set(Vote.objects.filter(user=user).values_list('track_id', flat=True))
tracks = set(Track.objects.filter(banter_done=True).values_list('pk', flat=True))
try:
queue = list(tracks - votes)
skipped = list(Vote.objects.filter(user=user).filter(skipped=True).values_list('track_id', flat=True))
return (len(queue), len(skipped))
except IndexError:
return (0, 0)
def track_from_json(json): def track_from_json(json):
"""Creates the track, album and artist from spotify response.""" """Creates the track, album and artist from spotify response."""
# Album artists # Album artists
+3 -2
View File
@@ -11,7 +11,7 @@ from datetime import UTC, datetime
from collections import OrderedDict from collections import OrderedDict
from dotenv import load_dotenv from dotenv import load_dotenv
from .models import Track, Artist, Album, Vote, Background, Profile, Playlist from .models import Track, Artist, Album, Vote, Background, Profile, Playlist
from .utils import track_from_json, get_unvoted from .utils import track_from_json, get_unvoted, get_unvoted_count
from .spotify import spt from .spotify import spt
from .tasks import get_banter, get_and_dither_image from .tasks import get_banter, get_and_dither_image
@@ -27,11 +27,12 @@ class AuthView(View):
class VoteView(LoginRequiredMixin, View): class VoteView(LoginRequiredMixin, View):
def get(self, request, undo=None): def get(self, request, undo=None):
(track, skipped) = get_unvoted(request.user) (track, skipped) = get_unvoted(request.user)
(vote_left, skip_left) = get_unvoted_count(request.user)
if track and not track.album.image: if track and not track.album.image:
if not track.album.image_url: if not track.album.image_url:
get_and_dither_image("https://picsum.photos/256", track.album, "image") get_and_dither_image("https://picsum.photos/256", track.album, "image")
get_and_dither_image(track.album.image_url, track.album, "image") get_and_dither_image(track.album.image_url, track.album, "image")
return TemplateResponse(request, "Vote.html", {"track": track, "undo": undo, "skipped": skipped}) return TemplateResponse(request, "Vote.html", {"track": track, "undo": undo, "skipped": skipped, "vote_left": vote_left, "skip_left": skip_left})
def post(self, request): def post(self, request):
(profile,_) = Profile.objects.get_or_create(user=request.user) (profile,_) = Profile.objects.get_or_create(user=request.user)
try: try: