Backgrounds

This commit is contained in:
2024-02-21 15:49:44 +01:00
parent ae7268736f
commit 81a60804b1
10 changed files with 113 additions and 13 deletions
+22 -2
View File
@@ -4,7 +4,7 @@ from django.http import HttpResponse, HttpResponseRedirect
from django.template.response import TemplateResponse
from django.contrib.auth.mixins import LoginRequiredMixin
import re
from .models import Track, Artist, Album, Vote
from .models import Track, Artist, Album, Vote, Background, Profile
from .utils import from_json, get_unvoted
from . import spotify
from .tasks import get_banter
@@ -105,4 +105,24 @@ class NominateView(LoginRequiredMixin, View):
class SettingsView(LoginRequiredMixin, View):
def get(self, request):
return TemplateResponse(request, "Settings.html")
backgrounds = Background.objects.all()
print(backgrounds)
(profile,created) = Profile.objects.get_or_create(user=request.user)
context = {
"backgrounds": backgrounds,
"currentBackground": (profile.background.id if profile.background else 1)
}
return TemplateResponse(request, "Settings.html", context)
def post(self, request):
print(request.POST)
try:
bg = Background.objects.get(pk=request.POST['background'])
print(f"{request.user} wants their background set to {bg}")
(profile,_) = Profile.objects.get_or_create(user=request.user)
print(profile)
profile.background = bg
profile.save()
except:
pass
finally:
return self.get(request)