Skip to content

Commit

Permalink
Restart project using Django + ReactJS
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyCA committed Apr 20, 2020
1 parent 14767bc commit a078816
Show file tree
Hide file tree
Showing 39 changed files with 8,178 additions and 817 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.vscode

out/

# Models
pretrained_models/

Expand Down Expand Up @@ -31,3 +33,6 @@ venv/
ENV/
env.bak/
venv.bak/

*.sqlite3
.coverage
21 changes: 0 additions & 21 deletions Pipfile

This file was deleted.

650 changes: 0 additions & 650 deletions Pipfile.lock

This file was deleted.

1 change: 0 additions & 1 deletion Procfile

This file was deleted.

Empty file added app/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions app/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
4 changes: 4 additions & 0 deletions app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.apps import AppConfig

class MyAppConfig(AppConfig):
name = 'app'
24 changes: 24 additions & 0 deletions app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.0.5 on 2020-04-19 20:12

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Song',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('artist', models.CharField(max_length=100)),
('length', models.DurationField()),
('file', models.FileField(upload_to='')),
],
),
]
18 changes: 18 additions & 0 deletions app/migrations/0002_auto_20200419_2013.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.5 on 2020-04-19 20:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='song',
name='file',
field=models.FileField(upload_to='uploads/'),
),
]
Empty file added app/migrations/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models

# Create your models here.
class Song(models.Model):
title = models.CharField(max_length=100)
artist = models.CharField(max_length=100)
length = models.DurationField()
file = models.FileField(upload_to='uploads/')
7 changes: 7 additions & 0 deletions app/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import Song

class SongSerializer(serializers.ModelSerializer):
class Meta:
model = Song
fields = ('id', 'title', 'artist', 'length', 'file')
3 changes: 3 additions & 0 deletions app/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
21 changes: 21 additions & 0 deletions app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""app URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.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.urls import path, include
from . import views

urlpatterns = [
path('api/song/', views.SongListCreate.as_view()),
]
10 changes: 10 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.shortcuts import render

# Create your views here.
from .models import Song
from .serializers import SongSerializer
from rest_framework import generics

class SongListCreate(generics.ListCreateAPIView):
queryset = Song.objects.all()
serializer_class = SongSerializer
14 changes: 0 additions & 14 deletions config.py

This file was deleted.

Empty file added django_react/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions django_react/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for django_react project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_react.settings')

application = get_asgi_application()
143 changes: 143 additions & 0 deletions django_react/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
"""
Django settings for django_react project.
Generated by 'django-admin startproject' using Django 3.0.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.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__)))

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'frontend', 'assets'),
)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '***REMOVED***'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app.apps.MyAppConfig',
'rest_framework',
'frontend',
'webpack_loader'
]

WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'dist/',
'STATS_FILE': os.path.join(BASE_DIR, 'frontend', 'webpack-stats.json')
}
}

REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
)
}

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 = 'django_react.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'frontend', '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',
],
},
},
]

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'frontend', 'assets'),
)

WSGI_APPLICATION = 'django_react.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.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/3.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/3.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/3.0/howto/static-files/

STATIC_URL = '/static/'
23 changes: 23 additions & 0 deletions django_react/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""django_react URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.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.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('app.urls')),
path('', include('frontend.urls')),
]
16 changes: 16 additions & 0 deletions django_react/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for django_react 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/3.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_react.settings')

application = get_wsgi_application()
6 changes: 6 additions & 0 deletions frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env",
"@babel/react"
]
}
3 changes: 3 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
assets/
webpack-stats.json
Empty file added frontend/__init__.py
Empty file.
Loading

0 comments on commit a078816

Please sign in to comment.