Commit aa3ac8dd authored by Brian Guadalupe's avatar Brian Guadalupe

Merge branch 'createplaylistactualwip' into 'master'

Implement backend capabilities for adding to playlist

See merge request brian/mymusiclist!15
parents e45f1ff1 d74fad45
...@@ -22,6 +22,7 @@ from core import views as core_views ...@@ -22,6 +22,7 @@ from core import views as core_views
from core import exthook as exthook from core import exthook as exthook
from user import views as user_views from user import views as user_views
from search import views as search_views from search import views as search_views
from playlist import views as playlist_views
urlpatterns = [ urlpatterns = [
url(r'^login/$', auth_views.login, {'template_name': 'login.html'}, name='login'), url(r'^login/$', auth_views.login, {'template_name': 'login.html'}, name='login'),
...@@ -29,6 +30,8 @@ urlpatterns = [ ...@@ -29,6 +30,8 @@ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^signup/$', user_views.signup, name='signup'), url(r'^signup/$', user_views.signup, name='signup'),
url(r'^search/$',search_views.search, name='search'), 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'^album/(?P<identifier>[0-9]+)/$', search_views.album_profile, name='album_profile'), 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'^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'), url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/$', user_views.user_profile_page, name='viewprofile'),
......
...@@ -11,20 +11,8 @@ class MusicPlaylist(models.Model): ...@@ -11,20 +11,8 @@ class MusicPlaylist(models.Model):
return self.playlist_name return self.playlist_name
class MusicEntry(models.Model): class MusicEntry(models.Model):
RATING_CHOICES = (
(0,'1'),
(1,'2'),
(2,'3'),
(3,'4'),
(4,'5'),
(5,'6'),
(6,'7'),
(7,'8'),
(8,'9'),
(9,'10')
)
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
order_in_playlist = models.PositiveSmallIntegerField() order_in_playlist = models.PositiveSmallIntegerField()
rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES) rating = models.DecimalField(max_digits=1, decimal_places=0)
playlist = models.ForeignKey(MusicPlaylist) playlist = models.ForeignKey(MusicPlaylist)
song = models.ForeignKey(Song) song = models.ForeignKey(Song)
\ No newline at end of file
from django.db.models import Max
from django.http import HttpResponse
from django.shortcuts import render from django.shortcuts import render
from django.contrib.auth.models import User
from core.models import Song as Song
from playlist.models import MusicPlaylist, MusicEntry
from django.shortcuts import get_object_or_404
# Create your views here. # Create your views here.
def addSong(request):
response = HttpResponse("")
if(not request.user.is_authenticated):
print("no auth")
response.status_code = 403
return response
song = Song.objects.filter(id = request.GET.get('song',''))
if(len(song) == 0):
print("song len 0")
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
fil = MusicEntry.objects.filter(playlist = playlist)
if(len(fil) == 0):
high = 0
else:
high = fil.aggregate(Max('order_in_playlist'))['order_in_playlist__max']
high += 1
entry = MusicEntry(order_in_playlist=high, rating = 9, playlist = playlist[0], song = song[0])
entry.save()
response.status_code = 200
return response;
def playlist_profile(request,identifier):
response = HttpResponse("")
result = MusicPlaylist.objects.filter(id = identifier)
if(len(result) == 0):
response.status_code = 404
return response
if(result[0].is_public or result[0].user == request.user):
entries = MusicEntry.objects.filter(playlist = result)
return render(request, 'playlist.html', {'result':result[0], 'owner': request.user, 'entries': entries})
return render(request, 'album.html', {'result':result[0], 'songs': songs, 'artist': artist_name})
\ No newline at end of file
...@@ -95,10 +95,6 @@ ...@@ -95,10 +95,6 @@
<script> <script>
function mainA(){ function mainA(){
document.getElementById("search_type").innerHTML = "Album Search"; document.getElementById("search_type").innerHTML = "Album Search";
...@@ -112,6 +108,9 @@ ...@@ -112,6 +108,9 @@
document.getElementById("search_type").innerHTML = "Song Search"; document.getElementById("search_type").innerHTML = "Song Search";
document.getElementById("searchbytype").value = "song"; document.getElementById("searchbytype").value = "song";
} }
{% block js %}
{% endblock %}
</script> </script>
......
{% extends 'base.html' %}
{% block title %}Viewing Playlist{% endblock %}
{% block sidebar %}
<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>
{% endblock %}
{% block content %}
<div class = "boxified main">
{% for i in entries %}
<h3> {{i.song.song_name}} </h3>
{% endfor %}
</div>
{% endblock %}
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
{% block content %} {% block content %}
<div class="w3-card-4 w3-green w3-container w3-padding profile"> <div class="w3-card-4 w3-green w3-container w3-padding profile">
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<div class="boxified main profile">
<h2>{{profile.username}}'s Profile</h2> <h2>{{profile.username}}'s Profile</h2>
<ul> <ul>
<li><strong>First Name:</strong> {{profile.first_name}}</li> <li><strong>First Name:</strong> {{profile.first_name}}</li>
...@@ -16,9 +17,20 @@ ...@@ -16,9 +17,20 @@
</ul> </ul>
{% if profile.username == request.user.username %} {% if profile.username == request.user.username %}
<a href="edit" class="buttoned">Edit user profile</a> <a href="edit" class="buttoned">Edit user profile</a>
</div>
{% endif %} {% endif %}
<div class = "boxified main profile">
<h2>{{profile.username}}'s Playlists </h2>
{% for i in playlists %}
<a class="link" href="/playlist/{{i.id}}">{{i.playlist_name}}</a>
{% endfor %}
</div>
{% else %} {% else %}
<div class="boxified main profile">
<p>Please <a href="{% url 'login' %}">log in</a> to your account to view {{profile.username}}'s profile.</p> <p>Please <a href="{% url 'login' %}">log in</a> to your account to view {{profile.username}}'s profile.</p>
</div>
{% endif %} {% endif %}
</div>
{% endblock %} {% endblock %}
...@@ -112,14 +112,49 @@ ...@@ -112,14 +112,49 @@
<p>Artist: <a href="/artist/{{i.artist.id}}">{{i.artist.name}}</a><br> <p>Artist: <a href="/artist/{{i.artist.id}}">{{i.artist.name}}</a><br>
Year: {{i.album.year}} </p> Year: {{i.album.year}} </p>
</div> </div>
<!-- ... -->
{% if request.user.is_authenticated %}
<!-- ... -->
<div class="w3-dropdown-hover">
<button id="search_type" class="w3-button" style="width:200px; text-align: left;"><i id = {{i.id}} class="fa fa-caret-down"></i> </button>
<div class="w3-dropdown-content w3-bar-block w3-card-4">
<button class="w3-bar-item w3-button">Update existing playlist</button>
<button onclick="alert('{{type}} id is {{i.id}}')">Show {{type}}</button>
<button onclick="addSong({{i.id}},0)" class=" w3-bar-item w3-button">Create new playlist</button>
</div>
</div>
<!-- ... -->
{% endif %}
<!-- ... -->
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}
<script>
function addSong(song, plname){
{% endblock %} if(plname == 0){
plname = "New";
}
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if(this.status == 200) {
document.getElementById(song).className = "fa fa-check-circle-o";
} else if (this.status= 403){
document.getElementById(song).className = "fa fa-times-circle";
} else{
alert("failed?");
}
}
};
xhttp.open("GET", "/manageplaylist/?song=" + song + "&playlist=" + plname, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send();
}
</script>
{% endblock %}
\ No newline at end of file
...@@ -5,6 +5,7 @@ from django.views.generic.edit import UpdateView ...@@ -5,6 +5,7 @@ from django.views.generic.edit import UpdateView
from user.forms import SignUpForm from user.forms import SignUpForm
from user.models import * from user.models import *
from playlist.models import MusicPlaylist
def signup(request): def signup(request):
if request.method == 'POST': if request.method == 'POST':
...@@ -20,7 +21,8 @@ def signup(request): ...@@ -20,7 +21,8 @@ def signup(request):
def user_profile_page(request, slug): def user_profile_page(request, slug):
user = get_object_or_404(User, username=slug) user = get_object_or_404(User, username=slug)
return render(request, 'profile.html', {'profile': user}) playlists = MusicPlaylist.objects.filter(user = user)
return render(request, 'profile.html', {'profile': user, 'playlists': playlists})
class EditProfile(UpdateView): class EditProfile(UpdateView):
model = User model = User
......
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