Working interface

This commit is contained in:
Tris Forster 2020-09-04 23:08:23 +10:00
commit 555685b77f
22 changed files with 471 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
__pycache__
*.pyc
db.sqlite3

0
interface/__init__.py Normal file
View File

9
interface/admin.py Normal file
View File

@ -0,0 +1,9 @@
from django.contrib import admin
# Register your models here.
from . import models
admin.site.register(models.Project)
admin.site.register(models.Submission)
admin.site.register(models.WikiPage)

5
interface/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class InterfaceConfig(AppConfig):
name = 'interface'

View File

@ -0,0 +1,40 @@
# Generated by Django 3.1.1 on 2020-09-04 09:59
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Project',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='WikiPage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('markdown', models.TextField()),
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='wiki_pages', to='interface.project')),
],
),
migrations.CreateModel(
name='Submission',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('instrument', models.CharField(max_length=100)),
('notes', models.TextField()),
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='submissions', to='interface.project')),
],
),
]

View File

@ -0,0 +1,31 @@
# Generated by Django 3.1.1 on 2020-09-04 10:04
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('interface', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='submission',
name='date',
field=models.DateField(auto_created=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='wikipage',
name='title',
field=models.CharField(default='', max_length=255),
preserve_default=False,
),
migrations.AlterField(
model_name='submission',
name='notes',
field=models.TextField(blank=True),
),
]

View File

26
interface/models.py Normal file
View File

@ -0,0 +1,26 @@
from django.db import models
# Create your models here.
class Project(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class WikiPage(models.Model):
project = models.ForeignKey(Project, related_name='wiki_pages', on_delete=models.CASCADE)
title = models.CharField(max_length=255)
markdown = models.TextField()
def __str__(self):
return self.title
class Submission(models.Model):
project = models.ForeignKey(Project, related_name='submissions', on_delete=models.CASCADE)
date = models.DateField(auto_created=True)
name = models.CharField(max_length=255)
instrument = models.CharField(max_length=100)
notes = models.TextField(blank=True)
def __str__(self):
return f"{self.name}: {self.date}"

View File

@ -0,0 +1,8 @@
.navbar {
margin-bottom: 50px;
background-color: #69C;
}
#project H1 {
text-align: center;
}

View File

@ -0,0 +1,48 @@
{% load static %}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'interface/css/polyphonic.css' %}"></link>
<script src="https://kit.fontawesome.com/c837098e5b.js" crossorigin="anonymous"></script>
<title>{% block title %}Polyphonic{% endblock %}</title>
</head>
<body>
{% block header %}
<nav class="navbar navbar-expand-lg navbar-dark">
<a class="navbar-brand" href="#"><i class="fas fa-random"></i> Polyphonic</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<span class="navbar-text">Virtual Ensemble Manager</span>
<div class="collapse navbar-collapse" id="navbarSupportedContent"></div>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'myprojects' %}""><i class="fas fa-music"></i> My Projects</a>
</li>
<li class="nav-item">
<a class="nav-link" href=""><i class="fas fa-question"></i> About</a>
</li>
</ul>
</div>
</nav>
{% endblock %}
{% block content %}
<h1>No content!</h1>
{% endblock %}
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
</html>

View File

@ -0,0 +1,30 @@
{% extends "base.html" %}
{% block content %}
<div class="container" id="project">
<h1>{{ project.name }}</h1>
<div class="row">
<div class="col-9">
{% block page %}
<p>There have been {{ project.submissions.count }} submissions so far...</p>
{% endblock %}
</div>
<div class="col-3">
<div class="nav flex-column nav-pills" role="tablist">
<a class="nav-link" role=tab"
href="{% url 'project' project_id=project.id %}">Project info</a>
{% for page in project.wiki_pages.all %}
<a class="nav-link {% if page.id == wiki_id %}active{% endif %}"
href="{% url 'wiki' project_id=project.id wiki_id=page.id %}"
role="tab">{{ page.title }}</a>
{% endfor %}
<a class="nav-link" role="tab"
href="">Record a submission</a>
<a class="nav-link" role="tab"
href="{% url 'submission' project_id=project.id %}">Send a file</a>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,31 @@
{% extends "interface/project.html" %}
{% block page %}
<p>
Some instructions about how to submit the file
</p>
<div class="col-md-6 offset-md-3">
<form>
<div class="form-group">
<label for="name">Name</label>
<input type="text" id="name" class="form-control"/>
</div>
<div class="form-group">
<label for="instrument">Instrument</label>
<input type="text" id="instrument" class="form-control"/>
</div>
<div class="form-group">
<label for="video-file">Video File</label>
<input type="file" accept="video/*" class="" id="video-file" />
</div>
<div class="form-group">
<label for="notes">Notes</label>
<textarea class="form-control" id="notes"></textarea>
</div>
<div class="text-right">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
{% endblock %}

View File

@ -0,0 +1,7 @@
{% extends "interface/project.html" %}
{% block page %}
<div class="wiki-page">
{{ wiki_html|safe }}
</div>
{% endblock %}

3
interface/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

10
interface/urls.py Normal file
View File

@ -0,0 +1,10 @@
from django.urls import path
from . import views
urlpatterns = [
path('my_projects', views.myprojects, name='myprojects'),
path('<int:project_id>', views.project_page, name="project"),
path('<int:project_id>/page/<int:wiki_id>', views.wiki_page, name="wiki"),
path('<int:project_id>/submission', views.submission, name="submission"),
]

23
interface/views.py Normal file
View File

@ -0,0 +1,23 @@
from django.shortcuts import render, get_object_or_404
from markdown2 import markdown
from . import models
def project_page(request, project_id):
project = get_object_or_404(models.Project, pk=project_id)
context = {'project': project}
return render(request, 'interface/project.html', context)
def wiki_page(request, project_id, wiki_id):
wiki = get_object_or_404(models.WikiPage, pk=wiki_id, project=project_id)
context = {'project': wiki.project, 'wiki': wiki, 'wiki_html': markdown(wiki.markdown)}
return render(request, 'interface/wiki.html', context)
def submission(request, project_id):
project = get_object_or_404(models.Project, pk=project_id)
context = {'project': project}
return render(request, 'interface/submission.html', context)
def myprojects(request):
return render(request, 'interface/my_projects.html', {})

22
manage.py Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'polyphonic.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)
if __name__ == '__main__':
main()

0
polyphonic/__init__.py Normal file
View File

16
polyphonic/asgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
ASGI config for polyphonic 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.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'polyphonic.settings')
application = get_asgi_application()

121
polyphonic/settings.py Normal file
View File

@ -0,0 +1,121 @@
"""
Django settings for polyphonic project.
Generated by 'django-admin startproject' using Django 3.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '6y#33930^6@c762u(@6+&#_qx8eu^e8q+4t-(@m60vnjw37k26'
# 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',
'interface',
]
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 = 'polyphonic.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
WSGI_APPLICATION = 'polyphonic.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/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.1/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.1/howto/static-files/
STATIC_URL = '/static/'

22
polyphonic/urls.py Normal file
View File

@ -0,0 +1,22 @@
"""polyphonic URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/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('project/', include('interface.urls')),
]

16
polyphonic/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for polyphonic 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.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'polyphonic.settings')
application = get_wsgi_application()