Commit 95b54b6b authored by Brian Guadalupe's avatar Brian Guadalupe

Merge branch 'refactor' into 'master'

Refactor the whole codebase

See merge request brian/mymusiclist!10
parents 1d1fb543 065e1184
...@@ -3,3 +3,4 @@ __pycache__/ ...@@ -3,3 +3,4 @@ __pycache__/
*.py[cod] *.py[cod]
*.sqlite3 *.sqlite3
desktop.ini desktop.ini
migrations/
\ No newline at end of file
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-05 05:39
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0001_initial'),
]
operations = [
migrations.RenameModel(
old_name='MusicEntry',
new_name='music_entry',
),
migrations.RenameModel(
old_name='MusicPlaylist',
new_name='music_playlist',
),
migrations.RenameModel(
old_name='UserAccount',
new_name='user_account',
),
migrations.AlterField(
model_name='album',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
migrations.AlterField(
model_name='music_entry',
name='song',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.song'),
),
migrations.AlterField(
model_name='song',
name='album',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.album'),
),
migrations.AlterField(
model_name='song',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-05 05:39
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0002_auto_20171105_1339'),
]
operations = [
migrations.AlterField(
model_name='album',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
migrations.AlterField(
model_name='music_entry',
name='song',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.song'),
),
migrations.AlterField(
model_name='song',
name='album',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.album'),
),
migrations.AlterField(
model_name='song',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-05 05:50
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0003_auto_20171105_1339'),
]
operations = [
migrations.AlterField(
model_name='album',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
migrations.AlterField(
model_name='music_entry',
name='song',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.song'),
),
migrations.AlterField(
model_name='song',
name='album',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.album'),
),
migrations.AlterField(
model_name='song',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-05 05:52
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0004_auto_20171105_1350'),
]
operations = [
migrations.AlterField(
model_name='album',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
migrations.AlterField(
model_name='music_entry',
name='song',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.song'),
),
migrations.AlterField(
model_name='song',
name='album',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.album'),
),
migrations.AlterField(
model_name='song',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-05 06:53
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0005_auto_20171105_1352'),
]
operations = [
migrations.AlterField(
model_name='album',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
migrations.AlterField(
model_name='music_entry',
name='song',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.song'),
),
migrations.AlterField(
model_name='song',
name='album',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.album'),
),
migrations.AlterField(
model_name='song',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.artist'),
),
]
from django.db import models from django.db import models
class UserAccount(models.Model):
id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64)
email = models.CharField(max_length=64)
class Artist(models.Model): class Artist(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64) name = models.CharField(max_length=64)
...@@ -31,37 +25,3 @@ class Song(models.Model): ...@@ -31,37 +25,3 @@ class Song(models.Model):
album = models.ForeignKey(Album) album = models.ForeignKey(Album)
def __str__(self): def __str__(self):
return self.song_name return self.song_name
class MusicPlaylist(models.Model):
id = models.AutoField(primary_key=True)
playlist_name = models.CharField(max_length=32)
is_public = models.BooleanField(default=False)
user = models.ForeignKey(UserAccount)
def __str__(self):
return self.playlist_name
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)
order_in_playlist = models.PositiveSmallIntegerField()
rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES)
playlist = models.ForeignKey(MusicPlaylist)
song = models.ForeignKey(Song)
class Tag(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=32)
tag = models.ManyToManyField(MusicEntry)
def __str__(self):
return self.name
from django.shortcuts import render from django.shortcuts import render
from django.contrib.auth import login, authenticate
from django.contrib.auth.models import User
from django.shortcuts import render, redirect, get_object_or_404
from django.views.generic.edit import UpdateView
from core.forms import SignUpForm
from core.models import *
from core.musicbrainzhook import *
def signup(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')
#user = authenticate(username=username, password=raw_password)
#login(request, user)
return redirect('/')
else:
form = SignUpForm()
return render(request, 'signup.html', {'form': form})
def home(request): def home(request):
return render(request, 'home.html') return render(request, 'home.html')
def user_profile_page(request, slug):
user = get_object_or_404(User, username=slug)
return render(request, 'profile.html', {'profile': user})
class EditProfile(UpdateView):
model = User
fields = ['username', 'email', 'first_name', 'last_name']
template_name = 'edit_profile.html'
slug_field = 'username'
slug_url_kwarg = 'slug'
def search(request):
type = request.GET.get('searchtype', '')
term = request.GET.get('search', '')
artistAlbums = Album.objects.filter(artist__name__contains = term)
if type == 'song':
results =Song.objects.filter(song_name__contains = term)
elif type == 'album':
results = Album.objects.filter(album_name__contains = term)
elif type == 'artist':
results = Artist.objects.filter(name__contains = term)
context = {
'type': type,
'term': term,
'results': results,
'albums': artistAlbums,
}
return render(request, 'search.html', context)
def artist_profile(request, identifier):
result = Artist.objects.filter(id = identifier)
albums = Album.objects.filter(artist = identifier)
return render(request, 'artist.html', {'result': result[0], 'albums': albums})
def album_profile(request, identifier):
result = Album.objects.filter(id = identifier)
artist_name = result[0].artist.name
songs =Song.objects.filter(album = identifier)
return render(request, 'album.html', {'result':result[0], 'songs': songs, 'artist': artist_name})
# def search(request,term):
# results = album.objects.filter(album_name__contains = term)
# custom()
# return render(request, 'search.html',{'term': term, 'results': results})
# def edit_profile(request, username):
# if request.method == 'POST':
# form = EditProfile(request.POST, instance=request.user)
# if form.is_valid():
# form.save()
# return HttpResponseRedirect(reverse('update_profile_success'))
# else:
# form = EditProfile(initial={'username': request.user.username, 'email': request.user.email, 'first_name': request.user.first_name, 'last_name': request.user.last_name})
# return render(request, 'edit_profile.html', {'form': form})
...@@ -33,7 +33,11 @@ ALLOWED_HOSTS = [] ...@@ -33,7 +33,11 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [ INSTALLED_APPS = [
'core', 'core',
'core.musicbrainzhook', 'search',
'playlist',
'tag',
'user',
'search.musicbrainzhook',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
......
...@@ -16,23 +16,21 @@ Including another URLconf ...@@ -16,23 +16,21 @@ Including another URLconf
from django.conf.urls import url from django.conf.urls import url
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.contrib import admin from django.contrib import admin
from django.contrib.auth import views as auth_views from django.contrib.auth import views as auth_views
from core import views as core_views from core import views as core_views
from user import views as user_views
from search import views as search_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'),
url(r'^logout/$', auth_views.logout, {'template_name': 'logged_out.html'}, name='logout'), url(r'^logout/$', auth_views.logout, {'template_name': 'logged_out.html'}, name='logout'),
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^signup/$', core_views.signup, name='signup'), url(r'^signup/$', user_views.signup, name='signup'),
url(r'^search/$',search_views.search, name='search'),
# url(r'^search_by_(?P<type>[A-Za-z0-9-+_.@]+)/?search=(?P<term>[A-Za-z0-9-+_.@]+)/$',core_views.search, name='search'), url(r'^album/(?P<identifier>[0-9]+)/$', search_views.album_profile, name='album_profile'),
url(r'^search/$',core_views.search, name='search'), url(r'^artist/(?P<identifier>[0-9]+)/$', search_views.artist_profile, name='artist_profile'),
url(r'^album/(?P<identifier>[0-9]+)/$', core_views.album_profile, name='album_profile'), url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/$', user_views.user_profile_page, name='viewprofile'),
url(r'^artist/(?P<identifier>[0-9]+)/$', core_views.artist_profile, name='artist_profile'), url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/edit/$', user_views.EditProfile.as_view(success_url=reverse_lazy('home')), name='editprofile'),
# url(r'^search/(?P<term>[A-Za-z0-9-+_.@]+)/$',core_views.search, name='search'),
url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/$', core_views.user_profile_page, name='viewprofile'),
url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/edit/$', core_views.EditProfile.as_view(success_url=reverse_lazy('home')), name='editprofile'),
# url(r'^profile/(?P<slug>[A-Za-z0-9-+_.@]+)/edit/$', core_views.EditProfile.as_view(success_url=reverse_lazy('profile', kwargs={'update':'true'})), name='editprofile'),
url(r'^$', core_views.home, name='home') url(r'^$', core_views.home, name='home')
] ]
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class PlaylistConfig(AppConfig):
name = 'playlist'
from django.db import models
from core.models import *
from user.models import *
class MusicPlaylist(models.Model):
id = models.AutoField(primary_key=True)
playlist_name = models.CharField(max_length=32)
is_public = models.BooleanField(default=False)
user = models.ForeignKey(UserAccount)
def __str__(self):
return self.playlist_name
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)
order_in_playlist = models.PositiveSmallIntegerField()
rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES)
playlist = models.ForeignKey(MusicPlaylist)
song = models.ForeignKey(Song)
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class SearchConfig(AppConfig):
name = 'search'
from django.db import models
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render, redirect, get_object_or_404
from core.models import *
from search.musicbrainzhook import *
def search(request):
type = request.GET.get('searchtype', '')
term = request.GET.get('search', '')
artistAlbums = Album.objects.filter(artist__name__contains = term)
if type == 'song':
results = Song.objects.filter(song_name__contains = term)
elif type == 'album':
results = Album.objects.filter(album_name__contains = term)
elif type == 'artist':
results = Artist.objects.filter(name__contains = term)
context = {
'type': type,
'term': term,
'results': results,
'albums': artistAlbums,
}
return render(request, 'search.html', context)
def artist_profile(request, identifier):
result = Artist.objects.filter(id = identifier)
albums = Album.objects.filter(artist = identifier)
return render(request, 'artist.html', {'result': result[0], 'albums': albums})
def album_profile(request, identifier):
result = Album.objects.filter(id = identifier)
artist_name = result[0].artist.name
songs = Song.objects.filter(album = identifier)
return render(request, 'album.html', {'result':result[0], 'songs': songs, 'artist': artist_name})
\ No newline at end of file
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class TagConfig(AppConfig):
name = 'tag'
from django.db import models
from playlist.models import *
class Tag(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=32)
tag = models.ManyToManyField(MusicEntry)
def __str__(self):
return self.name
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class UserConfig(AppConfig):
name = 'user'
from django.db import models
class UserAccount(models.Model):
id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64)
email = models.CharField(max_length=64)
from django.test import TestCase
# Create your tests here.
from django.contrib.auth import login, authenticate
from django.contrib.auth.models import User
from django.shortcuts import render, redirect, get_object_or_404
from django.views.generic.edit import UpdateView
from user.forms import SignUpForm
from user.models import *
def signup(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')
return redirect('/')
else:
form = SignUpForm()
return render(request, 'signup.html', {'form': form})
def user_profile_page(request, slug):
user = get_object_or_404(User, username=slug)
return render(request, 'profile.html', {'profile': user})
class EditProfile(UpdateView):
model = User
fields = ['username', 'email', 'first_name', 'last_name']
template_name = 'edit_profile.html'
slug_field = 'username'
slug_url_kwarg = 'slug'
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