提交 028461ce 编写于 作者: Ryanxhl's avatar Ryanxhl

Initial commit

上级
# Auto detect text files and perform LF normalization
* text=auto
文件已添加
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
from django.contrib import admin
from .models import Album, Song
admin.site.register(Album)
admin.site.register(Song)
\ No newline at end of file
from django.apps import AppConfig
class MusicConfig(AppConfig):
name = 'music'
# Generated by Django 2.0.3 on 2018-03-31 12:48
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Album',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('artist', models.CharField(max_length=250)),
('album_title', models.CharField(max_length=500)),
('genre', models.CharField(max_length=100)),
('album_logo', models.CharField(max_length=1000)),
],
),
migrations.CreateModel(
name='Song',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file_type', models.CharField(max_length=10)),
('song_title', models.CharField(max_length=250)),
('album', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='music.Album')),
],
),
]
# Generated by Django 2.0.3 on 2018-04-01 09:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('music', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='song',
name='is_favorite',
field=models.BooleanField(default=False),
),
]
# Generated by Django 2.0.3 on 2018-04-09 12:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('music', '0002_song_is_favorite'),
]
operations = [
migrations.AlterField(
model_name='album',
name='album_logo',
field=models.FileField(upload_to=''),
),
]
from django.db import models
from django.urls import reverse
# Create your models here.
class Album(models.Model):
artist = models.CharField(max_length=250)
album_title = models.CharField(max_length=500)
genre = models.CharField(max_length=100)
album_logo = models.FileField()
def get_absolute_url(self):
return reverse('music:detail', kwargs={'pk':self.pk})
def __str__(self):
return self.album_title + '-' + self.artist
class Song(models.Model):
album = models.ForeignKey(Album, on_delete=models.CASCADE)
file_type = models.CharField(max_length=10)
song_title = models.CharField(max_length=250)
is_favorite = models.BooleanField(default=False)
def __str__(self):
return self.song_title
.navbar{
border-radius: 0;
}
.navbar-brand{
font-family:'Satisfy',cursive;
}
.body{
padding-top: 65px;
}
\ No newline at end of file
{% extends 'music/base.html' %}
{% block title %}Add a New Album{% endblock %}
{% block albums_active %}active{% endblock %}
{% block body %}
<div class="container-fluid">
<div class="row">
<div class="col-sm-12 col-md-7">
<div class="panel panel-default">
<div class="panel-body">
<h3>Add a New Album</h3>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{% include 'music/form-template.html' %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col-sm-12 col-md-5">
<div class="panel panel-default">
<div class="panel-body">
<h3>What is Viberr?</h3>
<p>Viberr is an app that allows you to upload and store all of your music on the cloud.</p>
<h3>How do I add music?</h3>
<p>First, create a new album by filling out the form on this page. Once an album is created you will be able to add/upload songs.</p>
<h3>What are some Album logo best practices?</h3>
<ul>
<li>Have a resolution of 512x512</li>
<li>Use common image formats such as .JPG, .GIF, or .PNG</li>
<li>Remain under the 2MB limit.</li>
<li>Square images look best</li>
</ul>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}Viberr{% endblock %}</title>
{% load staticfiles %}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Satisfy" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="{% static 'music/style.css' %}"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar navbar-default navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#topNavBar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'music:index' %}">Viberr</a>
</div>
<div class="collapse navbar-collapse" id="topNavBar">
<ul class="nav navbar-nav">
<li class="active">
<a href="{% url 'music:index' %}">
<span class="glyphicon glyphicon-cd" aria-hidden="true"></span>&nbsp;Albums
</a>
</li>
<li class="">
<a href="#">
<span class="glyphicon glyphicon-music" aria-hidden="true"></span>&nbsp;Songs
</a>
</li>
</ul>
<form class="navbar-form navbar-left" role="search" method="get" action="#">
<div>
<input type="text" class="form-control" name="q" value="">
<button type="submit" class="btn btn-default">Search</button>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="active">
<a href="{% url 'music:album-add' %}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;Add Album
</a>
</li>
<li class="active">
<a href="{% url 'music:index' %}">
<span class="glyphicon glyphicon-off" aria-hidden="true"></span>&nbsp;Logout
</a>
</li>
</ul>
</div>
</div>
</nav>
{% block body %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'music/base.html' %}
{% block title %}Album Detail{% endblock %}
{% block body %}
<img scr="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" style="width: 160px;height:90px">
<h1>{{ album.album_title }}</h1>
<h2>{{ album.artist }}</h2>
{% for song in album.song_set.all %}
{{ song.song_title }}
{% if song.is_favorite %}
<img scr="#"/>
{% endif %}
{% endfor %}
{% endblock %}
{% for field in form %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<span class="text-danger small">{{ field.errors }}</span>
</div>
<label class="control-label col-sm-2" for="song_title">{{ field.label_tag }}</label>
<div class="col-sm-10">{{ field }}</div>
</div>
{% endfor %}
\ No newline at end of file
{% extends 'music/base.html' %}
{% block albums_active %}active{% endblock %}
{% block body %}
<div class="albums-container container-fluid">
<!-- Albums -->
<div class="row">
<div class="col-sm-12">
<h3>{{ user.username }}'s Albums</h3>
</div>
{% if albums %}
{% for album in albums %}
<div class="col-sm-4 col-lg-2">
<div class="thumbnail">
<a href="{% url 'music:detail' album.id %}">
<img src="{{ album.album_logo.url }}"; class="img-responsive">
</a>
<div class="caption">
<h2>{{ album.album_title }}</h2>
<h4>{{ album.artist }}</h4>
<!-- View Details -->
<a href="{% url 'music:detail' album.id %}" class="btn btn-primary btn-sm" role="button">View Details</a>
<!-- Delete Album -->
<form action="{% url 'music:delete_album' album.id %}" method="post" style="display: inline;">
{% csrf_token %}
<input type="hidden" name="album_id" value="{{ album.id }}" />
<button type="submit" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-trash"></span>
</button>
</form>
<!-- Favorite Album -->
<a href="{% url 'music:favorite_album' album.id %}" class="btn btn-default btn-sm btn-favorite" role="button">
<span class="glyphicon glyphicon-star {% if album.is_favorite %}active{% endif %}"></span>
</a>
</div>
</div>
</div>
{% cycle '' '' '' '' '' '<div class="clearfix visible-lg"></div>' %}
{% endfor %}
{% else %}
<div class="col-sm-12">
<br>
<a href="#">
<button type="button" class="btn btn-success">
<span class="glyphicon glyphicon-plus"></span>&nbsp; Add an Album
</button>
</a>
</div>
{% endif %}
</div>
<!-- If user searches and there are songs -->
{% if songs %}
<div class="row">
<div class="col-sm-12">
<h3>Songs</h3>
</div>
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-body">
<table class="table">
<thead>
<tr>
<th>Song Title</th>
<th>Artist</th>
<th>Audio File</th>
<th>Album</th>
<th>Favorite</th>
</tr>
</thead>
<tbody>
{% for song in songs %}
<tr>
<td>{{ song.song_title }}</td>
<td>{{ song.album.artist }}</td>
<td>
<a target="_blank" href="{{ song.audio_file.url }}">
<button type="button" class="btn btn-success btn-xs">
<span class="glyphicon glyphicon-play"></span>&nbsp; Play
</button>
</a>
</td>
<td>
<a href="{% url 'music:detail' song.album.id %}">
<img src="{{ song.album.album_logo.url }}" class="img-responsive" style="width: 20px; float: left; margin-right: 10px;" />
</a>
<a href="{% url 'music:detail' song.album.id %}">{{ song.album.album_title }}</a>
</td>
<td>
<a href="{% url 'music:favorite' song.id %}" class="btn-favorite"><span class="glyphicon glyphicon-star {% if song.is_favorite %}active{% endif %}"></span></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
# -*- coding: utf-8 -*-
from django.conf.urls import url
from . import views
app_name = 'music'
urlpatterns = [
url(r'^$',views.IndexView.as_view(), name='index'),
url(r'^(?P<pk>[0-9]+)/$',views.DetailView.as_view(), name='detail'),
url(r'album/add/$', views.AlbumCreate.as_view(), name='album-add' ),
url(r'^(?P<pk>[0-9]+)/$', views.AlbumUpdate.as_view(), name='album-update' ),
url(r'^(?P<pk>[0-9]+)/delete/$', views.AlbumDelete.as_view(), name='album-delete' ),
]
from django.views import generic
from .models import Album
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.urls import reverse_lazy
class IndexView(generic.ListView):
template_name = 'music/index.html'
context_object_name = 'all_albums'
def get_queryset(self):
return Album.objects.all()
class DetailView(generic.DetailView):
model = Album
template_name = 'music/detail.html'
class AlbumCreate(CreateView):
model = Album
fields = ['artist', 'album_title', 'genre', 'album_logo', ]
class AlbumUpdate(UpdateView):
model = Album
fields = ['artist', 'album_title', 'genre', 'album_logo', ]
class AlbumDelete(DeleteView):
model = Album
success_url = reverse_lazy('music:index')
\ No newline at end of file
"""
Django settings for website project.
Generated by 'django-admin startproject' using Django 2.0.3.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'o-*9)!)4qj9jq40!8@kehw_edb4p^0a)+$pfz8d_kz(@o_%e&j'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'music.apps.MusicConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'website.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.media',
],
},
},
]
WSGI_APPLICATION = 'website.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
"""website URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf.urls import url,include
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^music/', include('music.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
"""
WSGI config for website project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings")
application = get_wsgi_application()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册