Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mymusiclist
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Brian Guadalupe
mymusiclist
Commits
6243c637
Commit
6243c637
authored
Nov 29, 2017
by
Gink
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds playlist features
parent
bc4759fc
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
129 additions
and
24 deletions
+129
-24
urls.py
mymusiclist/urls.py
+3
-0
models.py
playlist/models.py
+1
-13
views.py
playlist/views.py
+58
-0
base.html
templates/base.html
+4
-2
playlist.html
templates/playlist.html
+19
-0
profile.html
templates/profile.html
+13
-2
search.html
templates/search.html
+28
-6
views.py
user/views.py
+3
-1
No files found.
mymusiclist/urls.py
View file @
6243c637
...
@@ -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'
),
...
...
playlist/models.py
View file @
6243c637
...
@@ -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
playlist/views.py
View file @
6243c637
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
[
0
]
=
MusicPlaylist
(
playlist_name
=
"New"
,
is_public
=
True
,
user
=
request
.
user
)
playlist
.
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
templates/base.html
View file @
6243c637
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
<div
class=
"w3-card-4 w3-green sidebar"
>
<div
class=
"w3-card-4 w3-green sidebar"
style=
"position:fixed"
>
{% block sidebar %}
{% block sidebar %}
<h2>
Featured Songs
</h2>
<h2>
Featured Songs
</h2>
<img
src=
"/files/images/divide_edsheeran.jpeg"
alt=
"Divide - Ed Sheeran"
>
<img
src=
"/files/images/divide_edsheeran.jpeg"
alt=
"Divide - Ed Sheeran"
>
...
@@ -71,7 +71,6 @@
...
@@ -71,7 +71,6 @@
<script>
<script>
function
mainA
(){
function
mainA
(){
document
.
getElementById
(
"search_type"
).
innerHTML
=
"Album Search"
;
document
.
getElementById
(
"search_type"
).
innerHTML
=
"Album Search"
;
...
@@ -85,6 +84,9 @@
...
@@ -85,6 +84,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>
...
...
templates/playlist.html
0 → 100644
View file @
6243c637
{% 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
templates/profile.html
View file @
6243c637
...
@@ -3,8 +3,8 @@
...
@@ -3,8 +3,8 @@
{% block title %}{{profile.username}}'s Profile{% endblock %}
{% block title %}{{profile.username}}'s Profile{% endblock %}
{% block content %}
{% block content %}
<div
class=
"boxified main 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>
...
@@ -13,9 +13,20 @@
...
@@ -13,9 +13,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 %}
templates/search.html
View file @
6243c637
...
@@ -92,11 +92,11 @@
...
@@ -92,11 +92,11 @@
{% if request.user.is_authenticated %}
{% if request.user.is_authenticated %}
<!-- ... -->
<!-- ... -->
<div
class=
"w3-dropdown-hover"
>
<div
class=
"w3-dropdown-hover"
>
<button
id=
"search_type"
class=
"w3-button"
style=
"width:200px; text-align: left;"
><i
class=
"fa fa-caret-down"
></i>
</button>
<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"
>
<div
class=
"w3-dropdown-content w3-bar-block w3-card-4"
>
<button
class=
"
w3-bar-item w3-button"
>
Update existing playlist
</button>
<button
class=
"w3-bar-item w3-button"
>
Update existing playlist
</button>
<button
onclick=
"alert('{{type}} id is {{i.id}}')"
>
Show {{type}}
</button>
<button
onclick=
"alert('{{type}} id is {{i.id}}')"
>
Show {{type}}
</button>
<button
class=
" w3-bar-item w3-button"
>
Create new playlist
</button>
<button
onclick=
"addSong({{i.id}},0)"
class=
" w3-bar-item w3-button"
>
Create new playlist
</button>
</div>
</div>
</div>
</div>
<!-- ... -->
<!-- ... -->
...
@@ -108,6 +108,28 @@
...
@@ -108,6 +108,28 @@
</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
user/views.py
View file @
6243c637
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment