Template refactors
En iets met de playlist-maker. URLs opnieuw ingedeeld.
This commit is contained in:
@@ -24,6 +24,10 @@ body {
|
|||||||
left: 0;
|
left: 0;
|
||||||
width: calc(100% - 6px);
|
width: calc(100% - 6px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#main-window > .window-body {
|
||||||
|
min-height: calc(100vh - 42px);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type=submit] {
|
input[type=submit] {
|
||||||
@@ -47,7 +51,7 @@ input#spotify-input + input[type=submit]{
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tree-view.overview {
|
.tree-view.overview {
|
||||||
height: 400px;
|
height: 384px;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="window-body">
|
<div class="window-body">
|
||||||
<menu role="tablist" hx-boost="true">
|
<menu role="tablist" hx-boost="true" class="multirows">
|
||||||
<li role="tab" {% if request.path == '/vote/' %}aria-selected="true" {% endif %}>
|
<li role="tab" {% if request.path == '/vote/' %}aria-selected="true" {% endif %}>
|
||||||
<a href="{% url 'vote' %}">Stemmen</a>
|
<a href="{% url 'vote' %}">Stemmen</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -33,8 +33,37 @@
|
|||||||
<a href="{% url 'settings' %}">Instellingen</a>
|
<a href="{% url 'settings' %}">Instellingen</a>
|
||||||
</li>
|
</li>
|
||||||
</menu>
|
</menu>
|
||||||
|
{% block multi-row %}{% endblock %}
|
||||||
<div class="window" role="tabpanel">
|
<div class="window" role="tabpanel">
|
||||||
<div class="window-body">
|
<div class="window-body">
|
||||||
|
{% if message_type %}
|
||||||
|
<script>
|
||||||
|
function hidePopup() {
|
||||||
|
document.getElementById("info-window").classList.add("hide");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<div class="window popup" id="info-window">
|
||||||
|
<div class="title-bar">
|
||||||
|
<div class="title-bar-text">
|
||||||
|
{% if message_title %}{{message_title}}{% else %}{{message_type | title}}{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="title-bar-controls">
|
||||||
|
<button aria-label="Close" onclick="hidePopup()"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="window-body">
|
||||||
|
<div class="icon {{message_type}}"></div>
|
||||||
|
<div class="text">
|
||||||
|
<div>
|
||||||
|
{{message}}
|
||||||
|
</div>
|
||||||
|
<section class="field-row" style="justify-content: flex-end">
|
||||||
|
<button onclick="hidePopup()">Ok</button>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% block main-content %}{% endblock %}
|
{% block main-content %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,42 +11,6 @@ Nomineren
|
|||||||
<input type="text" id="spotify-input" name="spotify_link" placeholder="Spotify-link">
|
<input type="text" id="spotify-input" name="spotify_link" placeholder="Spotify-link">
|
||||||
<input type="submit" value="Insturen" {% if user.profile.quota < 1%}disabled{%endif%}>
|
<input type="submit" value="Insturen" {% if user.profile.quota < 1%}disabled{%endif%}>
|
||||||
</form>
|
</form>
|
||||||
{% if nominated or error or warning %}
|
|
||||||
<script>
|
|
||||||
function hidePopup() {
|
|
||||||
document.getElementById("info-window").classList.add("hide");
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<div class="window popup" id="info-window">
|
|
||||||
<div class="title-bar">
|
|
||||||
<div class="title-bar-text">
|
|
||||||
{% if nominated %}
|
|
||||||
{{nominated}}
|
|
||||||
{% elif error %}
|
|
||||||
Error
|
|
||||||
{% else %}
|
|
||||||
Let op!
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<div class="title-bar-controls">
|
|
||||||
<button aria-label="Close" onclick="hidePopup()"></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="window-body">
|
|
||||||
<div class="icon {% if warning %}warning{% elif error %}error{% endif %}"></div>
|
|
||||||
<div class="text">
|
|
||||||
<div>
|
|
||||||
{{warning}}
|
|
||||||
{{error}}
|
|
||||||
{% if not error %}Genomineerd!{% endif %}
|
|
||||||
</div>
|
|
||||||
<section class="field-row" style="justify-content: flex-end">
|
|
||||||
<button onclick="hidePopup()">Ok</button>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block status-bar%}
|
{% block status-bar%}
|
||||||
|
|||||||
@@ -4,6 +4,17 @@
|
|||||||
Overzicht
|
Overzicht
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block multi-row %}
|
||||||
|
<menu role="tablist" hx-boost="true" class="multirows">
|
||||||
|
<li role="tab" aria-selected="true">
|
||||||
|
<a href="{% url 'overview' %}">Tracks</a>
|
||||||
|
</li>
|
||||||
|
<li role="tab">
|
||||||
|
<a href="{% url 'playlist-list' %}">Playlists</a>
|
||||||
|
</li>
|
||||||
|
</menu>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block main-content %}
|
{% block main-content %}
|
||||||
<p>Onderstaand alle nummers waar je al op gestemd hebt.</p>
|
<p>Onderstaand alle nummers waar je al op gestemd hebt.</p>
|
||||||
<ul class="tree-view overview">
|
<ul class="tree-view overview">
|
||||||
|
|||||||
@@ -1,31 +1,17 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
<div class="window popup">
|
<script>
|
||||||
|
function hidePopup() {
|
||||||
|
document.getElementById("info-window").classList.add("hide");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<div class="window popup" id="info-window">
|
||||||
<div class="title-bar">
|
<div class="title-bar">
|
||||||
<div class="title-bar-text">{{title}}</div>
|
<div class="title-bar-text">
|
||||||
|
{{title}}
|
||||||
|
<button aria-label="Close" onclick="hidePopup()"></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="window-body">
|
<div class="window-body">
|
||||||
{{body}}
|
{{body}}
|
||||||
{% if img %}
|
|
||||||
<br /><img src="{% static img %}" />
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<div class="status-bar">
|
|
||||||
<p class="status-bar-field">{{title}}</p>
|
|
||||||
<p class="status-bar-field">CPU Usage: 14%</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
|
||||||
position = { x: 0, y: 0 }
|
|
||||||
|
|
||||||
interact('.popup .title-bar').draggable({
|
|
||||||
listeners: {
|
|
||||||
move (event) {
|
|
||||||
position.x += event.dx
|
|
||||||
position.y += event.dy
|
|
||||||
|
|
||||||
event.target.parentElement.style.transform =
|
|
||||||
`translate(${position.x}px, ${position.y}px)`
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ Instellingen
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<form action="{% url 'spotify' %}">
|
<form action="{% url 'spotify-callback' %}">
|
||||||
<div class="field-row settings">
|
<div class="field-row settings">
|
||||||
<label>Link je spotify:</label>
|
<label>Link je spotify:</label>
|
||||||
<input type="submit" value="" class="icon spotify" />
|
<input type="submit" value="" class="icon spotify" />
|
||||||
|
|||||||
+2
-2
@@ -8,9 +8,9 @@ urlpatterns = [
|
|||||||
path('vote/', views.VoteView.as_view(), name="vote"),
|
path('vote/', views.VoteView.as_view(), name="vote"),
|
||||||
path('vote/undo', views.UndoView.as_view(), name="undo"),
|
path('vote/undo', views.UndoView.as_view(), name="undo"),
|
||||||
path('settings/', views.SettingsView.as_view(), name="settings"),
|
path('settings/', views.SettingsView.as_view(), name="settings"),
|
||||||
path('settings/make-playlist', views.PlaylistMake.as_view(), name="playlist"),
|
|
||||||
path('overview/', views.OverView.as_view(), name="overview"),
|
path('overview/', views.OverView.as_view(), name="overview"),
|
||||||
path('spotify/', views.SpotifyView.as_view(), name="spotify"),
|
path('overview/playlist', views.PlaylistListView.as_view(), name="playlist-list"),
|
||||||
|
path('overview/playlist/<int:id>', views.PlaylistDetailView.as_view(), name="playlist-detail"),
|
||||||
path('spotify/callback', views.SpotifyCallbackView.as_view(), name="spotify-callback"),
|
path('spotify/callback', views.SpotifyCallbackView.as_view(), name="spotify-callback"),
|
||||||
path('', views.AuthView.as_view()),
|
path('', views.AuthView.as_view()),
|
||||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|||||||
+30
-23
@@ -53,7 +53,7 @@ class NominateView(LoginRequiredMixin, View):
|
|||||||
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)
|
||||||
if profile.quota < 1:
|
if profile.quota < 1:
|
||||||
return TemplateResponse(request, "Nominate.html", {"error": "Nee nee nee, dat gaan we dus even niet doen."})
|
return TemplateResponse(request, "Nominate.html", {"message_type": "error", "message": "Nee nee nee, dat gaan we dus even niet doen."})
|
||||||
try:
|
try:
|
||||||
spotify_link = self.request.POST['spotify_link']
|
spotify_link = self.request.POST['spotify_link']
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ class NominateView(LoginRequiredMixin, View):
|
|||||||
m = re.match(r"^https:\/\/open.spotify.com\/track\/([a-zA-Z0-9]+)\??", spotify_link)
|
m = re.match(r"^https:\/\/open.spotify.com\/track\/([a-zA-Z0-9]+)\??", spotify_link)
|
||||||
spotify_id = m.group(1)
|
spotify_id = m.group(1)
|
||||||
except:
|
except:
|
||||||
return TemplateResponse(request, "Nominate.html", {"error": "Geef een geldige spotify link op!"})
|
return TemplateResponse(request, "Nominate.html", {"message_type": "error", "message": "Geef een geldige spotify link op!"})
|
||||||
try:
|
try:
|
||||||
track = Track.all_tracks.get(pk=spotify_id)
|
track = Track.all_tracks.get(pk=spotify_id)
|
||||||
|
|
||||||
@@ -72,19 +72,21 @@ class NominateView(LoginRequiredMixin, View):
|
|||||||
track.old = False
|
track.old = False
|
||||||
track.save()
|
track.save()
|
||||||
return TemplateResponse(request, "Nominate.html", {
|
return TemplateResponse(request, "Nominate.html", {
|
||||||
"warning": "Hey een klassieker.",
|
"message_type": "warning",
|
||||||
"nominated": track
|
"message": "Hey een klassieker.",
|
||||||
|
"message_title": str(track)
|
||||||
})
|
})
|
||||||
return TemplateResponse(request, "Nominate.html", {
|
return TemplateResponse(request, "Nominate.html", {
|
||||||
"error": "Deze is al genomineerd dit jaar, probeer eens iets anders.",
|
"message_type": "error",
|
||||||
"nominated": track
|
"message_title": str(track),
|
||||||
|
"message": "Deze is al genomineerd dit jaar, probeer eens iets anders.",
|
||||||
})
|
})
|
||||||
except Track.DoesNotExist:
|
except Track.DoesNotExist:
|
||||||
try:
|
try:
|
||||||
json = spt.get_song_info(spotify_id)
|
json = spt.get_song_info(spotify_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return TemplateResponse(request, "Nominate.html", {"error": "Fout bij het ophalen van het liedje."})
|
return TemplateResponse(request, "Nominate.html", {"message_type": "error", "message": "Fout bij het ophalen van het liedje."})
|
||||||
|
|
||||||
# Album artists
|
# Album artists
|
||||||
album_artists = []
|
album_artists = []
|
||||||
@@ -115,8 +117,9 @@ class NominateView(LoginRequiredMixin, View):
|
|||||||
if dup:
|
if dup:
|
||||||
track.delete()
|
track.delete()
|
||||||
return TemplateResponse(request, "Nominate.html", {
|
return TemplateResponse(request, "Nominate.html", {
|
||||||
"error": f"Die hadden we al knul.",
|
"message_type": "error",
|
||||||
"nominated": dup
|
"message": "Die hadden we al knul.",
|
||||||
|
"message_title": str(dup)
|
||||||
})
|
})
|
||||||
track.album = album
|
track.album = album
|
||||||
track.save()
|
track.save()
|
||||||
@@ -124,7 +127,7 @@ class NominateView(LoginRequiredMixin, View):
|
|||||||
profile.quota -= 1
|
profile.quota -= 1
|
||||||
profile.save()
|
profile.save()
|
||||||
|
|
||||||
return TemplateResponse(request, "Nominate.html", {"nominated": track})
|
return TemplateResponse(request, "Nominate.html", {"message_type": "nominated", "message_title": str(track), "message": "Genomineerd!"})
|
||||||
|
|
||||||
class SettingsView(LoginRequiredMixin, View):
|
class SettingsView(LoginRequiredMixin, View):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
@@ -196,14 +199,25 @@ class OverView(LoginRequiredMixin, View):
|
|||||||
}
|
}
|
||||||
return TemplateResponse(request, "Overview.html", context)
|
return TemplateResponse(request, "Overview.html", context)
|
||||||
|
|
||||||
class PlaylistMake(LoginRequiredMixin, View):
|
class PlaylistListView(LoginRequiredMixin, View):
|
||||||
|
def get(self, request, count=None):
|
||||||
|
return TemplateResponse(request, "PlaylistList.html", context)
|
||||||
|
def post(self, request):
|
||||||
|
name = self.request.POST.get('name', None)
|
||||||
|
if name:
|
||||||
|
new_playlist = Playlist(name=name)
|
||||||
|
return TemplateResponse(request, "PlaylistList.html", context)
|
||||||
|
return self.get(request, count=count)
|
||||||
|
|
||||||
|
|
||||||
|
class PlaylistDetailView(LoginRequiredMixin, View):
|
||||||
def get(self, request, count=None):
|
def get(self, request, count=None):
|
||||||
context = {}
|
context = {}
|
||||||
if count:
|
if count:
|
||||||
#tracks = Track.objects.order_by('score')[count]
|
#tracks = Track.objects.order_by('score')[count]
|
||||||
tracks = Track.objects.annotate(average_points=Avg('vote__points')).order_by('-average_points')[:count]
|
tracks = Track.objects.annotate(average_points=Avg('vote__points')).order_by('-average_points')[:count]
|
||||||
context["tracks"] = tracks
|
context["tracks"] = tracks
|
||||||
return TemplateResponse(request, "PlaylistMaker.html", context)
|
return TemplateResponse(request, "PlaylistDetail.html", context)
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
try:
|
try:
|
||||||
count = int(self.request.POST['count'])
|
count = int(self.request.POST['count'])
|
||||||
@@ -222,18 +236,11 @@ class SpotifyCallbackView(LoginRequiredMixin, View):
|
|||||||
error = self.request.GET.get('error')
|
error = self.request.GET.get('error')
|
||||||
code = self.request.GET.get('code')
|
code = self.request.GET.get('code')
|
||||||
if error:
|
if error:
|
||||||
return TemplateResponse(request, "Nominate.html", {"error": "Je moet wel accepteren, pannenkoek."})
|
return TemplateResponse(request, "Settings.html", {"message": "Je moet wel accepteren"})
|
||||||
elif code:
|
elif code:
|
||||||
(profile,_) = Profile.objects.get_or_create(user=request.user)
|
(profile,_) = Profile.objects.get_or_create(user=request.user)
|
||||||
profile.init_spt(code)
|
profile.init_spt(code)
|
||||||
# data = spt.get_user_token(code)
|
|
||||||
# access = data.get('access_token', None)
|
|
||||||
# refresh = data.get('refresh_token', None)
|
|
||||||
# expires = data.get('expires_in', 3600)
|
|
||||||
|
|
||||||
# if access and refresh:
|
|
||||||
# profile.set_spotify(access, refresh, expires)
|
|
||||||
# else:
|
|
||||||
# return TemplateResponse(request, "Nominate.html", {"error": "No."})
|
|
||||||
return HttpResponseRedirect(reverse('settings'))
|
return HttpResponseRedirect(reverse('settings'))
|
||||||
#return TemplateResponse(request, "Nominate.html", {"warning": code})
|
else:
|
||||||
|
url = spt.get_oauth_redirect()
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|||||||
Reference in New Issue
Block a user