From 555685b77f6ea91a0a5aa3f4f492892270089f70 Mon Sep 17 00:00:00 2001 From: Tris Forster Date: Fri, 4 Sep 2020 23:08:23 +1000 Subject: [PATCH] Working interface --- .gitignore | 3 + interface/__init__.py | 0 interface/admin.py | 9 ++ interface/apps.py | 5 + interface/migrations/0001_initial.py | 40 ++++++ .../migrations/0002_auto_20200904_1004.py | 31 +++++ interface/migrations/__init__.py | 0 interface/models.py | 26 ++++ interface/static/interface/css/polyphonic.css | 8 ++ interface/templates/base.html | 48 +++++++ interface/templates/interface/project.html | 30 +++++ interface/templates/interface/submission.html | 31 +++++ interface/templates/interface/wiki.html | 7 + interface/tests.py | 3 + interface/urls.py | 10 ++ interface/views.py | 23 ++++ manage.py | 22 ++++ polyphonic/__init__.py | 0 polyphonic/asgi.py | 16 +++ polyphonic/settings.py | 121 ++++++++++++++++++ polyphonic/urls.py | 22 ++++ polyphonic/wsgi.py | 16 +++ 22 files changed, 471 insertions(+) create mode 100644 .gitignore create mode 100644 interface/__init__.py create mode 100644 interface/admin.py create mode 100644 interface/apps.py create mode 100644 interface/migrations/0001_initial.py create mode 100644 interface/migrations/0002_auto_20200904_1004.py create mode 100644 interface/migrations/__init__.py create mode 100644 interface/models.py create mode 100644 interface/static/interface/css/polyphonic.css create mode 100644 interface/templates/base.html create mode 100644 interface/templates/interface/project.html create mode 100644 interface/templates/interface/submission.html create mode 100644 interface/templates/interface/wiki.html create mode 100644 interface/tests.py create mode 100644 interface/urls.py create mode 100644 interface/views.py create mode 100755 manage.py create mode 100644 polyphonic/__init__.py create mode 100644 polyphonic/asgi.py create mode 100644 polyphonic/settings.py create mode 100644 polyphonic/urls.py create mode 100644 polyphonic/wsgi.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2747baa --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +*.pyc +db.sqlite3 \ No newline at end of file diff --git a/interface/__init__.py b/interface/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interface/admin.py b/interface/admin.py new file mode 100644 index 0000000..557a206 --- /dev/null +++ b/interface/admin.py @@ -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) \ No newline at end of file diff --git a/interface/apps.py b/interface/apps.py new file mode 100644 index 0000000..7810300 --- /dev/null +++ b/interface/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class InterfaceConfig(AppConfig): + name = 'interface' diff --git a/interface/migrations/0001_initial.py b/interface/migrations/0001_initial.py new file mode 100644 index 0000000..b8da9cb --- /dev/null +++ b/interface/migrations/0001_initial.py @@ -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')), + ], + ), + ] diff --git a/interface/migrations/0002_auto_20200904_1004.py b/interface/migrations/0002_auto_20200904_1004.py new file mode 100644 index 0000000..1aa1682 --- /dev/null +++ b/interface/migrations/0002_auto_20200904_1004.py @@ -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), + ), + ] diff --git a/interface/migrations/__init__.py b/interface/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interface/models.py b/interface/models.py new file mode 100644 index 0000000..e9c33ba --- /dev/null +++ b/interface/models.py @@ -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}" \ No newline at end of file diff --git a/interface/static/interface/css/polyphonic.css b/interface/static/interface/css/polyphonic.css new file mode 100644 index 0000000..448c10d --- /dev/null +++ b/interface/static/interface/css/polyphonic.css @@ -0,0 +1,8 @@ +.navbar { + margin-bottom: 50px; + background-color: #69C; +} + +#project H1 { + text-align: center; +} \ No newline at end of file diff --git a/interface/templates/base.html b/interface/templates/base.html new file mode 100644 index 0000000..a801535 --- /dev/null +++ b/interface/templates/base.html @@ -0,0 +1,48 @@ +{% load static %} + + + + + + + + + + + + + {% block title %}Polyphonic{% endblock %} + + + + {% block header %} + + {% endblock %} + + {% block content %} +

No content!

+ {% endblock %} + + + + + + + + \ No newline at end of file diff --git a/interface/templates/interface/project.html b/interface/templates/interface/project.html new file mode 100644 index 0000000..f54a8b5 --- /dev/null +++ b/interface/templates/interface/project.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} + +{% block content %} +
+ +

{{ project.name }}

+
+
+ {% block page %} +

There have been {{ project.submissions.count }} submissions so far...

+ {% endblock %} +
+
+ +
+
+
+{% endblock %} \ No newline at end of file diff --git a/interface/templates/interface/submission.html b/interface/templates/interface/submission.html new file mode 100644 index 0000000..008d091 --- /dev/null +++ b/interface/templates/interface/submission.html @@ -0,0 +1,31 @@ +{% extends "interface/project.html" %} + +{% block page %} +

+ Some instructions about how to submit the file +

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/interface/templates/interface/wiki.html b/interface/templates/interface/wiki.html new file mode 100644 index 0000000..665bb63 --- /dev/null +++ b/interface/templates/interface/wiki.html @@ -0,0 +1,7 @@ +{% extends "interface/project.html" %} + +{% block page %} +
+{{ wiki_html|safe }} +
+{% endblock %} \ No newline at end of file diff --git a/interface/tests.py b/interface/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/interface/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/interface/urls.py b/interface/urls.py new file mode 100644 index 0000000..b16b967 --- /dev/null +++ b/interface/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('my_projects', views.myprojects, name='myprojects'), + path('', views.project_page, name="project"), + path('/page/', views.wiki_page, name="wiki"), + path('/submission', views.submission, name="submission"), +] \ No newline at end of file diff --git a/interface/views.py b/interface/views.py new file mode 100644 index 0000000..22ff069 --- /dev/null +++ b/interface/views.py @@ -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', {}) \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..2c318bb --- /dev/null +++ b/manage.py @@ -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() diff --git a/polyphonic/__init__.py b/polyphonic/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/polyphonic/asgi.py b/polyphonic/asgi.py new file mode 100644 index 0000000..c0c4aa2 --- /dev/null +++ b/polyphonic/asgi.py @@ -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() diff --git a/polyphonic/settings.py b/polyphonic/settings.py new file mode 100644 index 0000000..145a7ed --- /dev/null +++ b/polyphonic/settings.py @@ -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/' diff --git a/polyphonic/urls.py b/polyphonic/urls.py new file mode 100644 index 0000000..c8f9c7f --- /dev/null +++ b/polyphonic/urls.py @@ -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')), +] diff --git a/polyphonic/wsgi.py b/polyphonic/wsgi.py new file mode 100644 index 0000000..afba7c6 --- /dev/null +++ b/polyphonic/wsgi.py @@ -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()