Commit e73628ba authored by Brian Guadalupe's avatar Brian Guadalupe

Merge branch 'final' into 'master'

Adds playlist delete, song remove from playlist

See merge request brian/mymusiclist!17
parents 2f2fb374 bbf6ea8a
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-19 11:12
# Generated by Django 1.11.6 on 2017-12-07 01:37
from __future__ import unicode_literals
from django.db import migrations, models
......
......@@ -31,7 +31,7 @@ urlpatterns = [
url(r'^signup/$', user_views.signup, name='signup'),
url(r'^search/$',search_views.search, name='search'),
url(r'^playlist/(?P<identifier>[0-9]+)/$', playlist_views.playlist_profile, name='playlist_profile'),
url(r'^manageplaylist/$', playlist_views.addSong, name='playlist_management'),
url(r'^manageplaylist/$', playlist_views.managePlaylist, name='playlist_management'),
url(r'^album/(?P<identifier>[0-9]+)/$', search_views.album_profile, name='album_profile'),
url(r'^artist/(?P<identifier>[0-9]+)/$', search_views.artist_profile, name='artist_profile'),
url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/$', user_views.user_profile_page, name='viewprofile'),
......
......@@ -9,14 +9,36 @@ from django.shortcuts import get_object_or_404
# Create your views here.
def addSong(request):
def managePlaylist(request):
response = HttpResponse("")
requesttype = request.GET.get('type','1')
print(requesttype)
if(not request.user.is_authenticated):
print("no auth")
response.status_code = 403
return response
plname = request.GET.get('playlist','')
playlist = MusicPlaylist.objects.filter(user = request.user, playlist_name = plname)
if((len(playlist) == 0) & (requesttype == "1")):
playlist = [MusicPlaylist(playlist_name = plname, is_public = True, user = request.user)]
playlist[0].save()
elif ((len(playlist) == 0) & ((requesttype == "2") | (requesttype == "3"))):
print("hihihi")
response.status_code = 404
return response
##REQUESTTYPE 1 = ADD
##REQUESTTYPE 2 = REMOVE
##REQUESTTYPE 3 = DELETE
if(requesttype == "3"):
print("hi")
playlist[0].delete()
response.status_code = 200
return response
song = Song.objects.filter(id = request.GET.get('song',''))
if(len(song) == 0):
......@@ -24,15 +46,15 @@ def addSong(request):
response.status_code = 404
return response
plname = request.GET.get('playlist','')
playlist = MusicPlaylist.objects.filter(user = request.user, playlist_name = plname)
if(len(playlist) == 0):
playlist = [MusicPlaylist(playlist_name = "New", is_public = True, user = request.user)]
playlist[0].save()
#MusicEntry Zone
if(requesttype == "2"):
fil = MusicEntry.objects.filter(playlist = playlist, song = song)
for i in fil:
fil.delete()
response.status_code = 200
return response
if(requesttype == "1"):
fil = MusicEntry.objects.filter(playlist = playlist)
if(len(fil) == 0):
high = 0
......
......@@ -69,7 +69,7 @@
<div>
{% block sidebar %}
{% block sidebar%}
<div class="w3-card-4 w3-black w3-opacity sidebar">
<h2>Featured Songs</h2>
<img src="/files/images/divide_edsheeran.jpeg" alt="Divide - Ed Sheeran">
......
......@@ -4,10 +4,12 @@
{% block sidebar %}
<div class="w3-card-4 w3-black w3-opacity sidebar w3-round">
<p>
<b> {{result.playlist_name}} </b> <br> <br>
made by
<a class = "link" href= "/profile/{{owner.username}}">{{owner.first_name}} {{owner.last_name}}</a> <br>
</div>
{% endblock %}
{% block content %}
......
......@@ -17,8 +17,8 @@
</ul>
{% if profile.username == request.user.username %}
<a href="edit" class="buttoned">Edit user profile</a>
</div>
{% endif %}
</div>
<div class = "boxified main profile">
<h2>{{profile.username}}'s Playlists </h2>
{% for i in playlists %}
......
......@@ -150,7 +150,7 @@
}
}
};
xhttp.open("GET", "/manageplaylist/?song=" + song + "&playlist=" + plname, true);
xhttp.open("GET", "/manageplaylist/?song=" + song + "&playlist=" + plname + "&type=" + "1", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment