diff --git a/playlist/static/style.css b/playlist/static/style.css index b5d850d..5442288 100644 --- a/playlist/static/style.css +++ b/playlist/static/style.css @@ -24,6 +24,10 @@ body { left: 0; width: calc(100% - 6px); } + + #main-window > .window-body { + min-height: calc(100vh - 42px); + } } input[type=submit] { @@ -47,7 +51,7 @@ input#spotify-input + input[type=submit]{ } .tree-view.overview { - height: 400px; + height: 384px; overflow-y: scroll; } diff --git a/playlist/templates/Base.html b/playlist/templates/Base.html index e599c71..fe582b6 100644 --- a/playlist/templates/Base.html +++ b/playlist/templates/Base.html @@ -19,7 +19,7 @@
- +
  • Stemmen
  • @@ -33,8 +33,37 @@ Instellingen
    + {% block multi-row %}{% endblock %}
    + {% if message_type %} + + + {% endif %} {% block main-content %}{% endblock %}
    diff --git a/playlist/templates/Nominate.html b/playlist/templates/Nominate.html index 35b580e..d83c4f8 100644 --- a/playlist/templates/Nominate.html +++ b/playlist/templates/Nominate.html @@ -11,42 +11,6 @@ Nomineren -{% if nominated or error or warning %} - - -{% endif %} {% endblock %} {% block status-bar%} diff --git a/playlist/templates/Overview.html b/playlist/templates/Overview.html index d50326c..ccdfdd0 100644 --- a/playlist/templates/Overview.html +++ b/playlist/templates/Overview.html @@ -4,6 +4,17 @@ Overzicht {% endblock %} +{% block multi-row %} + +
  • + Tracks +
  • +
  • + Playlists +
  • +
    +{% endblock %} + {% block main-content %}

    Onderstaand alle nummers waar je al op gestemd hebt.

    {% else %} -
    +
    diff --git a/playlist/urls.py b/playlist/urls.py index 0e04732..28c8394 100644 --- a/playlist/urls.py +++ b/playlist/urls.py @@ -8,9 +8,9 @@ urlpatterns = [ path('vote/', views.VoteView.as_view(), name="vote"), path('vote/undo', views.UndoView.as_view(), name="undo"), 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('spotify/', views.SpotifyView.as_view(), name="spotify"), + path('overview/playlist', views.PlaylistListView.as_view(), name="playlist-list"), + path('overview/playlist/', views.PlaylistDetailView.as_view(), name="playlist-detail"), path('spotify/callback', views.SpotifyCallbackView.as_view(), name="spotify-callback"), 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 9836eeb..259ea37 100644 --- a/playlist/views.py +++ b/playlist/views.py @@ -53,7 +53,7 @@ class NominateView(LoginRequiredMixin, View): def post(self, request): (profile,_) = Profile.objects.get_or_create(user=request.user) 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: 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) spotify_id = m.group(1) 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: track = Track.all_tracks.get(pk=spotify_id) @@ -72,19 +72,21 @@ class NominateView(LoginRequiredMixin, View): track.old = False track.save() return TemplateResponse(request, "Nominate.html", { - "warning": "Hey een klassieker.", - "nominated": track + "message_type": "warning", + "message": "Hey een klassieker.", + "message_title": str(track) }) return TemplateResponse(request, "Nominate.html", { - "error": "Deze is al genomineerd dit jaar, probeer eens iets anders.", - "nominated": track + "message_type": "error", + "message_title": str(track), + "message": "Deze is al genomineerd dit jaar, probeer eens iets anders.", }) except Track.DoesNotExist: try: json = spt.get_song_info(spotify_id) except Exception as 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 = [] @@ -115,8 +117,9 @@ class NominateView(LoginRequiredMixin, View): if dup: track.delete() return TemplateResponse(request, "Nominate.html", { - "error": f"Die hadden we al knul.", - "nominated": dup + "message_type": "error", + "message": "Die hadden we al knul.", + "message_title": str(dup) }) track.album = album track.save() @@ -124,7 +127,7 @@ class NominateView(LoginRequiredMixin, View): profile.quota -= 1 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): def get(self, request): @@ -196,14 +199,25 @@ class OverView(LoginRequiredMixin, View): } 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): context = {} if count: #tracks = Track.objects.order_by('score')[count] tracks = Track.objects.annotate(average_points=Avg('vote__points')).order_by('-average_points')[:count] context["tracks"] = tracks - return TemplateResponse(request, "PlaylistMaker.html", context) + return TemplateResponse(request, "PlaylistDetail.html", context) def post(self, request): try: count = int(self.request.POST['count']) @@ -222,18 +236,11 @@ class SpotifyCallbackView(LoginRequiredMixin, View): error = self.request.GET.get('error') code = self.request.GET.get('code') 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: (profile,_) = Profile.objects.get_or_create(user=request.user) 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 TemplateResponse(request, "Nominate.html", {"warning": code}) + else: + url = spt.get_oauth_redirect() + return HttpResponseRedirect(url)