Commit 494dd4dc authored by Brian Guadalupe's avatar Brian Guadalupe

Modify app `core`

parent e5014a01
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=255)
last_name = forms.CharField(max_length=255)
email = forms.EmailField(max_length=255, help_text='Please enter a valid email address.')
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', )
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.apps import AppConfig
class MusicBrainzHook(AppConfig):
name = 'Musicbrainzhook'
verbose_name = name
def ready(self):
print("Self called")
def custom():
print("print called")
\ No newline at end of file
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})
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