deadlines

This commit is contained in:
2024-07-19 17:30:36 +02:00
parent 8a7ae9c2f9
commit 5858cee900
8 changed files with 182 additions and 50 deletions
+10 -2
View File
@@ -6,12 +6,17 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Avg
from django.urls import reverse
import re
import os
from datetime import UTC, datetime
from collections import OrderedDict
from dotenv import load_dotenv
from .models import Track, Artist, Album, Vote, Background, Profile, Playlist
from .utils import from_json, get_unvoted
from .spotify import spt
from .tasks import get_banter, get_and_dither_image
load_dotenv()
class AuthView(View):
def get(self, request):
if request.user.is_authenticated:
@@ -26,7 +31,10 @@ class VoteView(LoginRequiredMixin, View):
get_and_dither_image(track.album.image_url, track.album, "image")
return TemplateResponse(request, "Vote.html", {"track": track, "undo": undo})
def post(self, request):
(profile,_) = Profile.objects.get_or_create(user=request.user)
try:
if not profile.can_vote:
raise Exception(f"{request.user} tried to vote after closing for {track}")
spotify_id = self.request.POST['spotify_id']
score = int(self.request.POST['vote'])
score = min(max(1, score), 5)
@@ -49,10 +57,10 @@ class NominateView(LoginRequiredMixin, View):
def get(self, request):
(profile,_) = Profile.objects.get_or_create(user=request.user)
profile.update_quota()
return TemplateResponse(request, "Nominate.html", {})
return TemplateResponse(request, "Nominate.html", {'end_time': os.getenv('DATE_NOM_END')})
def post(self, request):
(profile,_) = Profile.objects.get_or_create(user=request.user)
if profile.quota < 1:
if not profile.can_nominate[0]:
return TemplateResponse(request, "Nominate.html", {"message_type": "error", "message": "Nee nee nee, dat gaan we dus even niet doen."})
try:
spotify_link = self.request.POST['spotify_link']