diff --git a/playlist/admin.py b/playlist/admin.py
index b8b863a..6ffd1ab 100644
--- a/playlist/admin.py
+++ b/playlist/admin.py
@@ -1,5 +1,5 @@
from django.contrib import admin
-from .models import Track, Artist, Album
+from .models import Track, Artist, Album, Background
class TrackAdmin(admin.ModelAdmin):
pass
@@ -7,7 +7,10 @@ class ArtistAdmin(admin.ModelAdmin):
pass
class AlbumAdmin(admin.ModelAdmin):
pass
+class BackgroundAdmin(admin.ModelAdmin):
+ pass
admin.site.register(Track, TrackAdmin)
admin.site.register(Artist, ArtistAdmin)
admin.site.register(Album, AlbumAdmin)
+admin.site.register(Background, BackgroundAdmin)
diff --git a/playlist/models/__init__.py b/playlist/models/__init__.py
index 9db89c7..2af94c6 100644
--- a/playlist/models/__init__.py
+++ b/playlist/models/__init__.py
@@ -2,3 +2,4 @@ from .track import Track
from .artist import Artist
from .album import Album
from .vote import Vote
+from .profile import Profile, Background
diff --git a/playlist/models/profile.py b/playlist/models/profile.py
new file mode 100644
index 0000000..6b690d9
--- /dev/null
+++ b/playlist/models/profile.py
@@ -0,0 +1,26 @@
+from django.db import models
+from django.contrib.auth.models import User
+from django.db.models.signals import post_save
+from django.dispatch import receiver
+
+class Background(models.Model):
+ def __str__(self):
+ return self.name
+ name = models.CharField(max_length=128)
+ image = models.ImageField(upload_to="wallpapers/", null=True, blank=True)
+ repeat = models.BooleanField(default=False)
+ color = models.CharField(max_length=32, blank=True)
+
+class Profile(models.Model):
+ user = models.OneToOneField(User, on_delete=models.CASCADE)
+ background = models.ForeignKey(Background, null=True, on_delete=models.SET_NULL)
+
+@receiver(post_save, sender=User)
+def create_user_profile(sender, instance, created, **kwargs):
+ if created:
+ Profile.objects.create(user=instance)
+
+@receiver(post_save, sender=User)
+def save_user_profile(sender, instance, **kwargs):
+ Profile.objects.get_or_create(user=instance)
+ instance.profile.save()
diff --git a/playlist/static/style.css b/playlist/static/style.css
index c3b484e..d601b0b 100644
--- a/playlist/static/style.css
+++ b/playlist/static/style.css
@@ -1,8 +1,5 @@
body {
background-color: #01817F;
- background-size: cover;
- background-repeat: no-repeat;
- background-attachment: fixed;
margin: 0;
}
@@ -26,10 +23,24 @@ body {
}
}
+input[type=submit] {
+ filter: contrast(1);
+}
+
.hide {
display: none;
}
+.offscreen {
+ clip: rect(0 0 0 0);
+ clip-path: inset(50%);
+ height: 1px;
+ overflow: hidden;
+ position: absolute;
+ white-space: nowrap;
+ width: 1px;
+}
+
.window.popup {
position: fixed;
z-index: 100;
diff --git a/playlist/templates/Base.html b/playlist/templates/Base.html
index 805f4d7..ab775d5 100644
--- a/playlist/templates/Base.html
+++ b/playlist/templates/Base.html
@@ -4,6 +4,15 @@
{% include "head.html" %}
+
diff --git a/playlist/templates/Settings.html b/playlist/templates/Settings.html
index aece6a1..6edc5c6 100644
--- a/playlist/templates/Settings.html
+++ b/playlist/templates/Settings.html
@@ -10,11 +10,25 @@
{% endif %}
-
-
-
-
-
+
{% endblock %}
diff --git a/playlist/templates/background.css b/playlist/templates/background.css
new file mode 100644
index 0000000..0292f63
--- /dev/null
+++ b/playlist/templates/background.css
@@ -0,0 +1,10 @@
+{% load static %}
+
+body {
+ {% if background.image %}
+ background-image: url('{{background.image.url}}');
+ {% if not background.repeat %}background-repeat: no-repeat;{% endif %}
+ {% else %}
+ background-color: {{background.color}};
+ {% endif %}
+}
\ No newline at end of file
diff --git a/playlist/templates/head.html b/playlist/templates/head.html
index 81daf1d..b6b1d5c 100644
--- a/playlist/templates/head.html
+++ b/playlist/templates/head.html
@@ -4,6 +4,11 @@
+
+
+
diff --git a/playlist/urls.py b/playlist/urls.py
index b97fa66..7c4fdbc 100644
--- a/playlist/urls.py
+++ b/playlist/urls.py
@@ -1,9 +1,11 @@
from django.urls import path
from . import views
+from django.conf import settings
+from django.conf.urls.static import static
urlpatterns = [
path('track/', views.NominateView.as_view(), name="nominate"),
path('vote/', views.VoteView.as_view(), name="vote"),
path('settings/', views.SettingsView.as_view(), name="settings"),
path('', views.AuthView.as_view()),
-]
+] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
diff --git a/playlist/views.py b/playlist/views.py
index 9edf888..61748ca 100644
--- a/playlist/views.py
+++ b/playlist/views.py
@@ -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)
\ No newline at end of file