Backgrounds
This commit is contained in:
+4
-1
@@ -1,5 +1,5 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Track, Artist, Album
|
from .models import Track, Artist, Album, Background
|
||||||
|
|
||||||
class TrackAdmin(admin.ModelAdmin):
|
class TrackAdmin(admin.ModelAdmin):
|
||||||
pass
|
pass
|
||||||
@@ -7,7 +7,10 @@ class ArtistAdmin(admin.ModelAdmin):
|
|||||||
pass
|
pass
|
||||||
class AlbumAdmin(admin.ModelAdmin):
|
class AlbumAdmin(admin.ModelAdmin):
|
||||||
pass
|
pass
|
||||||
|
class BackgroundAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
admin.site.register(Track, TrackAdmin)
|
admin.site.register(Track, TrackAdmin)
|
||||||
admin.site.register(Artist, ArtistAdmin)
|
admin.site.register(Artist, ArtistAdmin)
|
||||||
admin.site.register(Album, AlbumAdmin)
|
admin.site.register(Album, AlbumAdmin)
|
||||||
|
admin.site.register(Background, BackgroundAdmin)
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ from .track import Track
|
|||||||
from .artist import Artist
|
from .artist import Artist
|
||||||
from .album import Album
|
from .album import Album
|
||||||
from .vote import Vote
|
from .vote import Vote
|
||||||
|
from .profile import Profile, Background
|
||||||
|
|||||||
@@ -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()
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
body {
|
body {
|
||||||
background-color: #01817F;
|
background-color: #01817F;
|
||||||
background-size: cover;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-attachment: fixed;
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,10 +23,24 @@ body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=submit] {
|
||||||
|
filter: contrast(1);
|
||||||
|
}
|
||||||
|
|
||||||
.hide {
|
.hide {
|
||||||
display: none;
|
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 {
|
.window.popup {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
|
|||||||
@@ -4,6 +4,15 @@
|
|||||||
{% include "head.html" %}
|
{% include "head.html" %}
|
||||||
</head>
|
</head>
|
||||||
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
|
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
|
||||||
|
<svg class="offscreen" width="0" height="0" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
||||||
|
<defs>
|
||||||
|
<filter id="crispify">
|
||||||
|
<feComponentTransfer>
|
||||||
|
<feFuncA type="discrete" tableValues="0 1"/>
|
||||||
|
</feComponentTransfer>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
|
</svg>
|
||||||
<script>setWallpaper()</script>
|
<script>setWallpaper()</script>
|
||||||
<div class="window" id="main-window">
|
<div class="window" id="main-window">
|
||||||
<div class="title-bar main-title-bar">
|
<div class="title-bar main-title-bar">
|
||||||
|
|||||||
@@ -10,11 +10,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="field-row">
|
<form method="post">
|
||||||
<label for="wallpaper">Eigen wallpaper url:</label>
|
{% csrf_token %}
|
||||||
<input id="wallpaper" type="text" onchange="wallpaperChanged()" />
|
{% if backgrounds %}
|
||||||
<button id="wallpaper-reset" onclick="wallpaperChanged()">Reset</button>
|
<div class="field-row">
|
||||||
</div>
|
<label for="wallpaper">Wallpaper:</label>
|
||||||
|
<select id="background" name="background" onchange="this.form.submit()">
|
||||||
|
{% for background in backgrounds %}
|
||||||
|
<option
|
||||||
|
value="{{background.id}}"
|
||||||
|
{% if background.id == currentBackground %} selected{% endif %}
|
||||||
|
>
|
||||||
|
{{background.name}}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<button id="wallpaper-reset" onclick="wallpaperChanged()">Reset</button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
<script>
|
<script>
|
||||||
function wallpaperChanged() {
|
function wallpaperChanged() {
|
||||||
const expression = /^https?:\/\/.*\.(jpeg|jpg|png|gif)$/
|
const expression = /^https?:\/\/.*\.(jpeg|jpg|png|gif)$/
|
||||||
@@ -26,6 +40,5 @@
|
|||||||
setWallpaper()
|
setWallpaper()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -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 %}
|
||||||
|
}
|
||||||
@@ -4,6 +4,11 @@
|
|||||||
<script src="https://unpkg.com/interactjs"></script>
|
<script src="https://unpkg.com/interactjs"></script>
|
||||||
<link rel="stylesheet" href="https://unpkg.com/98.css" >
|
<link rel="stylesheet" href="https://unpkg.com/98.css" >
|
||||||
<link href="{% static 'style.css'%}" rel="stylesheet" type="text/css" />
|
<link href="{% static 'style.css'%}" rel="stylesheet" type="text/css" />
|
||||||
|
<style>
|
||||||
|
{% include 'background.css' with background=user.profile.background %}
|
||||||
|
</style>
|
||||||
|
<link href="{% static 'style.css'%}" rel="stylesheet" type="text/css" />
|
||||||
|
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'apple-touch-icon.png' %}">
|
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'apple-touch-icon.png' %}">
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'favicon-32x32.png' %}">
|
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'favicon-32x32.png' %}">
|
||||||
<link rel="icon" type="image/png" sizes="16x16" href="{% static 'favicon-16x16.png' %}">
|
<link rel="icon" type="image/png" sizes="16x16" href="{% static 'favicon-16x16.png' %}">
|
||||||
|
|||||||
+3
-1
@@ -1,9 +1,11 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
|
from django.conf import settings
|
||||||
|
from django.conf.urls.static import static
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('track/', views.NominateView.as_view(), name="nominate"),
|
path('track/', views.NominateView.as_view(), name="nominate"),
|
||||||
path('vote/', views.VoteView.as_view(), name="vote"),
|
path('vote/', views.VoteView.as_view(), name="vote"),
|
||||||
path('settings/', views.SettingsView.as_view(), name="settings"),
|
path('settings/', views.SettingsView.as_view(), name="settings"),
|
||||||
path('', views.AuthView.as_view()),
|
path('', views.AuthView.as_view()),
|
||||||
]
|
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|||||||
+22
-2
@@ -4,7 +4,7 @@ from django.http import HttpResponse, HttpResponseRedirect
|
|||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
import re
|
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 .utils import from_json, get_unvoted
|
||||||
from . import spotify
|
from . import spotify
|
||||||
from .tasks import get_banter
|
from .tasks import get_banter
|
||||||
@@ -105,4 +105,24 @@ class NominateView(LoginRequiredMixin, View):
|
|||||||
|
|
||||||
class SettingsView(LoginRequiredMixin, View):
|
class SettingsView(LoginRequiredMixin, View):
|
||||||
def get(self, request):
|
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)
|
||||||
Reference in New Issue
Block a user