Compare commits
25
Commits
b1ea75cec0
...
material
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1301d19c08 | ||
|
|
ca3effcad1 | ||
|
|
5468f6d3e7 | ||
|
|
e46d8145a7 | ||
|
|
3444cdbc59 | ||
|
|
6e77474d15 | ||
|
|
72bad08a61 | ||
|
|
b217fbea5e | ||
|
|
cec64ecd2f | ||
|
|
d30005d5b6 | ||
|
|
ef981e06e8 | ||
|
|
4cef5800bc | ||
|
|
78441dc142 | ||
|
|
c96a2ad80b | ||
|
|
7e0c77f260 | ||
|
|
ff17114514 | ||
|
|
533d6f09e8 | ||
|
|
eeb35ce4f6 | ||
|
|
947626c2af | ||
|
|
c1f0e48f80 | ||
|
|
ab7d32d46e | ||
|
|
5116247ae8 | ||
|
|
93c4926dfd | ||
|
|
27d1b03c3c | ||
|
|
4e102c07ac |
+16
-12
@@ -1,21 +1,25 @@
|
|||||||
FROM alpine:3.14
|
FROM alpine:latest
|
||||||
|
|
||||||
RUN apk add --no-cache python3 git ghostscript sqlite
|
ENV TARGET=/opt/polyphonic
|
||||||
|
#ENV RELEASE=polyphonic-0.8.4-py3-none-any.whl
|
||||||
|
ENV RELEASE=git+https://gitea.tfconsulting.com.au/projects/polyphonic.git
|
||||||
|
|
||||||
|
RUN apk add --no-cache python3 py3-pip git ghostscript sqlite
|
||||||
|
|
||||||
WORKDIR /root
|
WORKDIR /root
|
||||||
RUN python3 -m ensurepip
|
|
||||||
RUN pip3 install -U pip --no-cache-dir
|
|
||||||
|
|
||||||
COPY app/requirements.txt .
|
RUN python3 -m venv ${TARGET}
|
||||||
RUN pip3 install -r requirements.txt --no-cache-dir
|
ENV PATH="${TARGET}/bin:$PATH"
|
||||||
|
|
||||||
COPY app /opt/polyphonic
|
#COPY dist/${RELEASE} .
|
||||||
WORKDIR /opt/polyphonic
|
RUN pip3 install ${RELEASE} --no-cache-dir
|
||||||
|
RUN pip3 install gunicorn whitenoise
|
||||||
|
|
||||||
COPY docker_settings.py polyphonic/local_settings.py
|
WORKDIR ${TARGET}
|
||||||
RUN SECRET_KEY=_ python3 manage.py collectstatic --noinput
|
|
||||||
|
RUN SECRET_KEY=_ poly-tool collectstatic --noinput
|
||||||
|
|
||||||
VOLUME ["/var/polyphonic"]
|
VOLUME ["/var/polyphonic"]
|
||||||
|
EXPOSE 8000/tcp
|
||||||
|
|
||||||
ENTRYPOINT ["python3", "manage.py"]
|
CMD ["gunicorn", "-b", "0.0.0.0", "polyphonic.config.wsgi"]
|
||||||
CMD ["runserver", "0.0.0.0:8000", "--insecure"]
|
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
PYTHON=env/bin/python
|
PYTHON=env/bin/python
|
||||||
DROPZONE=5.7.0
|
DROPZONE=5.7.0
|
||||||
|
|
||||||
test: check
|
test:
|
||||||
poetry run coverage run --include "app/*" --omit "*/migrations/*" app/manage.py test app
|
poetry run coverage run --include "polyphonic/*" --omit "*/migrations/*" polyphonic/manage.py test polyphonic
|
||||||
poetry run coverage html
|
poetry run coverage html
|
||||||
poetry run coverage report
|
poetry run coverage report
|
||||||
|
|
||||||
check:
|
check:
|
||||||
poetry run ruff check app
|
poetry run ruff check polyphonic
|
||||||
|
poetry run ruff format --check polyphonic
|
||||||
|
|
||||||
|
pre-commit: check test
|
||||||
|
|
||||||
build:
|
build:
|
||||||
poetry build
|
poetry build
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
from django import template
|
|
||||||
from django.utils import timesince
|
|
||||||
|
|
||||||
register = template.Library()
|
|
||||||
|
|
||||||
|
|
||||||
def roughtimesince(value):
|
|
||||||
return timesince.timesince(value, depth=1)
|
|
||||||
|
|
||||||
|
|
||||||
register.filter("roughtimesince", roughtimesince)
|
|
||||||
|
|
||||||
|
|
||||||
def roughtimeuntil(value):
|
|
||||||
return timesince.timeuntil(value, depth=1)
|
|
||||||
|
|
||||||
|
|
||||||
register.filter("roughtimeuntil", roughtimeuntil)
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
from django.core.files.storage import Storage
|
|
||||||
from collections import namedtuple
|
|
||||||
import requests
|
|
||||||
import re
|
|
||||||
from gzip import GzipFile
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
SHARED_FOLDER = re.compile(r"https://drive.google.com/drive/folders/(\w+)")
|
|
||||||
SHARED_FILE = re.compile(r"https://drive.google.com/file/d/([\w\-]+)")
|
|
||||||
|
|
||||||
FILES_API = "https://www.googleapis.com/drive/v3/files"
|
|
||||||
|
|
||||||
|
|
||||||
class DriveObject(namedtuple("DriveObject", ("id", "name"))):
|
|
||||||
@classmethod
|
|
||||||
def from_string(cls, s):
|
|
||||||
return cls(*s.split("/", 1))
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.id}/{self.name}"
|
|
||||||
|
|
||||||
|
|
||||||
class GDriveLinkStorage(Storage):
|
|
||||||
is_writable = False
|
|
||||||
|
|
||||||
def __init__(self, api_key):
|
|
||||||
self.api_key = api_key
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
def parse_id(self, name):
|
|
||||||
parts = name.split("/")
|
|
||||||
return parts[0]
|
|
||||||
|
|
||||||
def extract_id(self, url, *patterns):
|
|
||||||
logger.debug("EXTRACT_ID: %r", url)
|
|
||||||
for pattern in patterns:
|
|
||||||
match = pattern.match(url)
|
|
||||||
if match:
|
|
||||||
return match.groups()[0]
|
|
||||||
raise FileNotFoundError(f"Not a valid url: {url}")
|
|
||||||
|
|
||||||
def get_json(self, url):
|
|
||||||
logger.debug("GET_JSON: %s", url)
|
|
||||||
response = requests.get(url)
|
|
||||||
data = response.json()
|
|
||||||
logger.debug("Data: %r", data)
|
|
||||||
return data
|
|
||||||
|
|
||||||
def listdir(self, path) -> tuple[list[str], list[str]]:
|
|
||||||
|
|
||||||
# used to test for valid connection parameters - should do something to validate API key here
|
|
||||||
if path == "":
|
|
||||||
return [], []
|
|
||||||
|
|
||||||
logger.debug("LISTDIR: %s", path)
|
|
||||||
folder_id = self.parse_id(path)
|
|
||||||
url = f"{FILES_API}?q='{folder_id}'+in+parents&key={self.api_key}"
|
|
||||||
data = self.get_json(url)
|
|
||||||
files = []
|
|
||||||
folders = []
|
|
||||||
for x in data["files"]:
|
|
||||||
if x["mimeType"] == "application/vnd.google-apps.folder":
|
|
||||||
# folders.append(f"{x['id']}/{x['name']}")
|
|
||||||
folders.append(DriveObject(x["id"], x["name"]))
|
|
||||||
else:
|
|
||||||
# files.append(f"{x['id']}/{x['name']}")
|
|
||||||
files.append(DriveObject(x["id"], x["name"]))
|
|
||||||
|
|
||||||
return folders, files
|
|
||||||
|
|
||||||
def get_meta(self, name):
|
|
||||||
file_id = self.parse_id(name)
|
|
||||||
url = f"{FILES_API}/{file_id}?key={self.api_key}"
|
|
||||||
return self.get_json(url)
|
|
||||||
|
|
||||||
def open(self, name, mode="rb"):
|
|
||||||
file_id = self.parse_id(name)
|
|
||||||
url = f"{FILES_API}/{file_id}?alt=media&key={self.api_key}"
|
|
||||||
logger.info("URL: %s", url)
|
|
||||||
response = requests.get(url, stream=True)
|
|
||||||
return GzipFile(name, "rb", 9, response.raw)
|
|
||||||
|
|
||||||
def size(self, name):
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def delete(self, name):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def url(self, name):
|
|
||||||
logger.debug("URL: %r", name)
|
|
||||||
file_id = self.parse_id(name)
|
|
||||||
return f"https://drive.usercontent.google.com/download?export=download&id={file_id}&confirm=yes"
|
|
||||||
|
|
||||||
def get_folder_id(self, url):
|
|
||||||
try:
|
|
||||||
return self.extract_id(url, SHARED_FOLDER)
|
|
||||||
except FileNotFoundError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_file_id(self, url):
|
|
||||||
try:
|
|
||||||
return self.extract_id(url, SHARED_FILE)
|
|
||||||
except FileNotFoundError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
def import_link(self, url) -> str:
|
|
||||||
file_id = self.extract_id(url, SHARED_FILE)
|
|
||||||
meta = self.get_meta(file_id)
|
|
||||||
return f"{file_id}/{meta['name']}"
|
|
||||||
|
|
||||||
def folder_import(self, url) -> list[str]:
|
|
||||||
folder_id = self.extract_id(url, SHARED_FOLDER)
|
|
||||||
_, files = self.listdir(folder_id)
|
|
||||||
return files
|
|
||||||
"""
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
try:
|
|
||||||
from .local_settings import * # noqa
|
|
||||||
except ImportError:
|
|
||||||
from .default_settings import * # noqa
|
|
||||||
|
|
||||||
INSTALLED_APPS += POLYPHONIC_MODULES # type: ignore #noqa
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
polyphonic:
|
||||||
|
image: "polyphonic:0.8.4"
|
||||||
|
build: "."
|
||||||
|
ports:
|
||||||
|
- "8001:8000"
|
||||||
|
volumes:
|
||||||
|
- "./data:/var/polyphonic"
|
||||||
|
- "./local_settings.py:/opt/polyphonic/local_settings.py"
|
||||||
|
env_file: "compose.env"
|
||||||
|
environment:
|
||||||
|
DJANGO_SETTINGS_MODULE: local_settings
|
||||||
|
PYTHONPATH: /opt/polyphonic
|
||||||
|
WORK_DIR: /var/polyphonic
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
from .default_settings import *
|
|
||||||
|
|
||||||
DATABASES = {
|
|
||||||
'default': {
|
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
|
||||||
'NAME': '/var/polyphonic/db.sqlite3',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,6 +11,6 @@ import os
|
|||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'polyphonic.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "polyphonic.settings")
|
||||||
|
|
||||||
application = get_asgi_application()
|
application = get_asgi_application()
|
||||||
@@ -11,26 +11,29 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from os import environ
|
import os
|
||||||
|
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent
|
||||||
|
|
||||||
SECRET_KEY = environ.get("SECRET_KEY")
|
# A place to put things
|
||||||
|
WORK_DIR = os.environ.get("WORK_DIR") or os.path.join(BASE_DIR, "data")
|
||||||
|
|
||||||
|
# Will fail to start if not defined
|
||||||
|
SECRET_KEY = os.environ.get("SECRET_KEY")
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
||||||
|
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
ALLOWED_HOSTS = ["localhost"]
|
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
|
||||||
INTERNAL_IPS = ["127.0.0.1"]
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
POLYPHONIC_MODULES = ["library"]
|
POLYPHONIC_MODULES = ["polyphonic.library"]
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
"django.contrib.admin",
|
"django.contrib.admin",
|
||||||
@@ -44,9 +47,11 @@ INSTALLED_APPS = [
|
|||||||
"crispy_forms",
|
"crispy_forms",
|
||||||
"crispy_bulma",
|
"crispy_bulma",
|
||||||
"byostorage",
|
"byostorage",
|
||||||
"interface",
|
"polyphonic.interface",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
INSTALLED_APPS += POLYPHONIC_MODULES
|
||||||
|
|
||||||
CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",)
|
CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",)
|
||||||
CRISPY_TEMPLATE_PACK = "bulma"
|
CRISPY_TEMPLATE_PACK = "bulma"
|
||||||
|
|
||||||
@@ -60,7 +65,7 @@ MIDDLEWARE = [
|
|||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = "polyphonic.urls"
|
ROOT_URLCONF = "polyphonic.config.urls"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
@@ -78,7 +83,7 @@ TEMPLATES = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = "polyphonic.wsgi.application"
|
WSGI_APPLICATION = "polyphonic.config.wsgi.application"
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
@@ -87,7 +92,7 @@ WSGI_APPLICATION = "polyphonic.wsgi.application"
|
|||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.sqlite3",
|
"ENGINE": "django.db.backends.sqlite3",
|
||||||
"NAME": BASE_DIR / "db.sqlite3",
|
"NAME": os.path.join(WORK_DIR, "db.sqlite3"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,17 +125,18 @@ LANGUAGE_CODE = "en-us"
|
|||||||
TIME_ZONE = "Australia/Melbourne"
|
TIME_ZONE = "Australia/Melbourne"
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
USE_L10N = True
|
USE_L10N = True
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = "/static/"
|
STATIC_URL = "/static/"
|
||||||
STATIC_ROOT = "static"
|
STATIC_ROOT = "static"
|
||||||
|
|
||||||
# Need to set this
|
# Library settings
|
||||||
AWS_BUCKET = ""
|
|
||||||
|
CACHED_STORAGE_REMOTE = "byostorage.user.BYOStorage"
|
||||||
|
CACHED_STORAGE_DIR = os.path.join(WORK_DIR, "cache")
|
||||||
|
WHOOSH_INDEX = os.path.join(WORK_DIR, "index")
|
||||||
|
STORAGE_CLASSES = ["polyphonic.library.gdrive.storage.GDriveLinkStorage"]
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
from .base import * # noqa
|
||||||
|
from os import environ
|
||||||
|
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
SECRET_KEY = "DO NOT USE IN PRODUCTION"
|
||||||
|
|
||||||
|
# Enable debug toolbar
|
||||||
|
INSTALLED_APPS.append("debug_toolbar") # noqa
|
||||||
|
MIDDLEWARE.insert(1, "debug_toolbar.middleware.DebugToolbarMiddleware") # noqa
|
||||||
|
INTERNAL_IPS = ["127.0.0.1"]
|
||||||
|
|
||||||
|
LOGGING = {
|
||||||
|
"version": 1,
|
||||||
|
"disable_existing_loggers": False,
|
||||||
|
"handlers": {
|
||||||
|
"console": {
|
||||||
|
"class": "logging.StreamHandler",
|
||||||
|
"level": environ.get("DEBUG_LEVEL", "WARNING"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"loggers": {
|
||||||
|
"polyphonic": {
|
||||||
|
"handlers": ["console"],
|
||||||
|
"level": environ.get("DEBUG_LEVEL", "WARNING"),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
from .base import * # noqa
|
||||||
|
|
||||||
|
# Enable WhiteNoise for static files
|
||||||
|
MIDDLEWARE.insert(1, "whitenoise.middleware.WhiteNoiseMiddleware") # noqa
|
||||||
@@ -19,9 +19,9 @@ from django.urls import path, include
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path("", include("interface.urls")),
|
path("", include("polyphonic.interface.urls")),
|
||||||
# path('', include('submissions.urls')),
|
# path('', include('submissions.urls')),
|
||||||
path("", include("library.urls")),
|
path("", include("polyphonic.library.urls")),
|
||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -11,6 +11,6 @@ import os
|
|||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'polyphonic.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "polyphonic.config.settings.base")
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
@@ -2,4 +2,4 @@ from django.apps import AppConfig
|
|||||||
|
|
||||||
|
|
||||||
class InterfaceConfig(AppConfig):
|
class InterfaceConfig(AppConfig):
|
||||||
name = "interface"
|
name = "polyphonic.interface"
|
||||||
+3
-3
@@ -4,7 +4,7 @@ import byostorage.user
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
import interface.models
|
import polyphonic.interface.models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@@ -23,7 +23,7 @@ class Migration(migrations.Migration):
|
|||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('name', models.CharField(help_text='Display name', max_length=100)),
|
('name', models.CharField(help_text='Display name', max_length=100)),
|
||||||
('slug', models.SlugField(editable=False, help_text='Short name for the ensemble - used for folders', max_length=100, unique=True)),
|
('slug', models.SlugField(editable=False, help_text='Short name for the ensemble - used for folders', max_length=100, unique=True)),
|
||||||
('code', models.CharField(default=interface.models.generate_code, help_text='Ensemble registration code', max_length=9)),
|
('code', models.CharField(default=polyphonic.interface.models.generate_code, help_text='Ensemble registration code', max_length=9)),
|
||||||
('passphrase', models.CharField(help_text='Used to register ensembles', max_length=100)),
|
('passphrase', models.CharField(help_text='Used to register ensembles', max_length=100)),
|
||||||
('details', models.TextField(blank=True, help_text='Description of the ensemble (markdown)')),
|
('details', models.TextField(blank=True, help_text='Description of the ensemble (markdown)')),
|
||||||
('admins', models.ManyToManyField(related_name='ensembles', to=settings.AUTH_USER_MODEL)),
|
('admins', models.ManyToManyField(related_name='ensembles', to=settings.AUTH_USER_MODEL)),
|
||||||
@@ -60,7 +60,7 @@ class Migration(migrations.Migration):
|
|||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('name', models.CharField(max_length=100)),
|
('name', models.CharField(max_length=100)),
|
||||||
('description', models.TextField(blank=True)),
|
('description', models.TextField(blank=True)),
|
||||||
('file', models.FileField(storage=byostorage.user.BYOStorage(), upload_to=interface.models.resource_key)),
|
('file', models.FileField(storage=byostorage.user.BYOStorage(), upload_to=polyphonic.interface.models.resource_key)),
|
||||||
('media_type', models.CharField(choices=[('audio', 'Audio'), ('video', 'Video'), ('general', 'General')], default='*', max_length=10)),
|
('media_type', models.CharField(choices=[('audio', 'Audio'), ('video', 'Video'), ('general', 'General')], default='*', max_length=10)),
|
||||||
('visible', models.BooleanField(default=True)),
|
('visible', models.BooleanField(default=True)),
|
||||||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='resources', to='interface.project')),
|
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='resources', to='interface.project')),
|
||||||
|
Before Width: | Height: | Size: 426 KiB After Width: | Height: | Size: 426 KiB |
|
Before Width: | Height: | Size: 258 B After Width: | Height: | Size: 258 B |
@@ -11,7 +11,8 @@
|
|||||||
<script src="{% static 'interface/js/interface.js' %}"></script>
|
<script src="{% static 'interface/js/interface.js' %}"></script>
|
||||||
<script src="//unpkg.com/alpinejs" defer></script>
|
<script src="//unpkg.com/alpinejs" defer></script>
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" defer></script>
|
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" defer></script>
|
||||||
<script src="//kit.fontawesome.com/c837098e5b.js" crossorigin="anonymous" defer></script>
|
<!-- script src="//kit.fontawesome.com/c837098e5b.js" crossorigin="anonymous" defer></script -->
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" rel="stylesheet" />
|
||||||
<title>{% block title %}Polyphonic{% endblock %}</title>
|
<title>{% block title %}Polyphonic{% endblock %}</title>
|
||||||
{% block media %}{% endblock %}
|
{% block media %}{% endblock %}
|
||||||
<style>{% block style %}{% endblock %}</style>
|
<style>{% block style %}{% endblock %}</style>
|
||||||
@@ -23,7 +24,7 @@
|
|||||||
<nav class="navbar" role="navigation">
|
<nav class="navbar" role="navigation">
|
||||||
<div class="navbar-brand has-text-primary">
|
<div class="navbar-brand has-text-primary">
|
||||||
<a class="navbar-item" href="/">
|
<a class="navbar-item" href="/">
|
||||||
<span class="icon fancy is-size-2 is-size-4-mobile mx-4"><i class="fas fa-random"></i></span>
|
<span class="icon fancy mx-4"><span class="material-symbols-outlined is-size-1 is-size-3-mobile">groups</span></span>
|
||||||
<span class="fancy is-size-2 is-size-4-mobile">Polyphonic</span>
|
<span class="fancy is-size-2 is-size-4-mobile">Polyphonic</span>
|
||||||
</a>
|
</a>
|
||||||
<span class="navbar-item is-hidden-mobile fancy is-size-5">Musical Ensemble Manager</span>
|
<span class="navbar-item is-hidden-mobile fancy is-size-5">Musical Ensemble Manager</span>
|
||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
{% crispy_field field 'class' 'file-input'%}
|
{% crispy_field field 'class' 'file-input'%}
|
||||||
<span class="file-cta">
|
<span class="file-cta">
|
||||||
<span class="file-icon">
|
<span class="file-icon">
|
||||||
<i class="fas fa-upload"></i>
|
<span class="material-symbols-outlined">file_upload</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="file-label">
|
<span class="file-label">
|
||||||
Choose a file…
|
Choose a file…
|
||||||
+4
-3
@@ -1,19 +1,20 @@
|
|||||||
{% extends "interface/project_base.html" %}
|
{% extends "interface/project_base.html" %}
|
||||||
{% load md2 %}
|
{% load md2 %}
|
||||||
|
{% load polyphonic %}
|
||||||
|
|
||||||
{% block admin %}
|
{% block admin %}
|
||||||
<a href="{% url 'project_create' object.slug %}" class="button is-link">
|
<a href="{% url 'project_create' object.slug %}" class="button is-link">
|
||||||
<span class="icon"><i class="fas fa-plus-circle"></i></span>
|
{{ "add_notes"|icon }}
|
||||||
<span>Add project</span>
|
<span>Add project</span>
|
||||||
</a>
|
</a>
|
||||||
{% if inactive %}
|
{% if inactive %}
|
||||||
<a href="?" class="button is-link">
|
<a href="?" class="button is-link">
|
||||||
<span class="icon"><i class="fas fa-archive"></i></span>
|
{{ "preview_off"|icon }}
|
||||||
<span>Hide old</span>
|
<span>Hide old</span>
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="?inactive" class="button is-link">
|
<a href="?inactive" class="button is-link">
|
||||||
<span class="icon"><i class="fas fa-archive"></i></span>
|
{{ "preview"|icon }}
|
||||||
<span>Show all</span>
|
<span>Show all</span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
+5
-2
@@ -5,7 +5,7 @@
|
|||||||
{% comment %}
|
{% comment %}
|
||||||
<div class="admin-tools is-pulled-right">
|
<div class="admin-tools is-pulled-right">
|
||||||
<a class="button is-link" href="{% url 'register' %}">
|
<a class="button is-link" href="{% url 'register' %}">
|
||||||
<span class="icon"><i class="fas fa-plus-circle"></i></span>
|
{% icon "add_file" %}
|
||||||
<span>Register another</span>
|
<span>Register another</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -25,10 +25,13 @@
|
|||||||
<img src="https://www.gravatar.com/avatar/{{ ensemble.email }}?d=mp" alt="Placeholder image">
|
<img src="https://www.gravatar.com/avatar/{{ ensemble.email }}?d=mp" alt="Placeholder image">
|
||||||
</figure>
|
</figure>
|
||||||
</div>
|
</div>
|
||||||
<div class="media-content" style="min-height: 60px">
|
<div class="media-content" style="min-height: 100px">
|
||||||
<a href="{% url 'ensemble_detail' ensemble.slug %}">
|
<a href="{% url 'ensemble_detail' ensemble.slug %}">
|
||||||
<p class="title is-4">{{ ensemble.name }}</p>
|
<p class="title is-4">{{ ensemble.name }}</p>
|
||||||
</a>
|
</a>
|
||||||
|
<div class="mt-3">
|
||||||
|
{{ ensemble.details|markdown }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
+2
-2
@@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
{% block admin %}
|
{% block admin %}
|
||||||
<a href="{% url 'wiki_create' project=project.pk %}" class="button is-link">
|
<a href="{% url 'wiki_create' project=project.pk %}" class="button is-link">
|
||||||
<span class="icon"><i class="fas fa-file"></i></span>
|
{{ "add_notes"|icon }}
|
||||||
<span>Add Page</span>
|
<span>Add Page</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="{% url 'project_edit' project=project.pk %}" class="button is-link">
|
<a href="{% url 'project_edit' project=project.pk %}" class="button is-link">
|
||||||
<span class="icon"><i class="fas fa-edit"></i></span>
|
{{ "edit"|icon }}
|
||||||
<span>Edit</span>
|
<span>Edit</span>
|
||||||
</a>
|
</a>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
+6
-5
@@ -1,9 +1,10 @@
|
|||||||
{% extends "interface/project_base.html" %}
|
{% extends "interface/project_base.html" %}
|
||||||
{% load md2 %}
|
{% load md2 %}
|
||||||
|
{% load polyphonic %}
|
||||||
|
|
||||||
{% block admin %}
|
{% block admin %}
|
||||||
<a class="button is-link" href="{% url 'resource_create' project=project.pk %}">
|
<a class="button is-link" href="{% url 'resource_create' project=project.pk %}">
|
||||||
<span class="icon"><i class="fas fa-plus-circle"></i></span>
|
{% icon "add_notes" %}
|
||||||
<span>Add new</span>
|
<span>Add new</span>
|
||||||
</a>
|
</a>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -27,11 +28,11 @@
|
|||||||
|
|
||||||
<div class="card-header-icon">
|
<div class="card-header-icon">
|
||||||
{% if request.is_admin %}
|
{% if request.is_admin %}
|
||||||
<a href="{% url 'resource_upload' project=project.pk pk=resource.pk %}" class="icon" title="Upload">
|
<a href="{% url 'resource_upload' project=project.pk pk=resource.pk %}" title="Upload">
|
||||||
<i class="fas fa-upload"></i>
|
{% icon "upload_file" %}
|
||||||
</a>
|
</a>
|
||||||
<a href="{% url 'resource_edit' project=project.pk pk=resource.pk %}" class="icon" title="Edit">
|
<a href="{% url 'resource_edit' project=project.pk pk=resource.pk %}" title="Edit">
|
||||||
<i class="fas fa-edit"></i>
|
{% icon "edit" %}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
+2
-1
@@ -1,8 +1,9 @@
|
|||||||
{% extends "interface/project_base.html" %}
|
{% extends "interface/project_base.html" %}
|
||||||
|
{% load polyphonic %}
|
||||||
|
|
||||||
{% block admin %}
|
{% block admin %}
|
||||||
<a href="{% url 'wiki_edit' project=project.pk pk=wikipage.pk %}" class="button is-link">
|
<a href="{% url 'wiki_edit' project=project.pk pk=wikipage.pk %}" class="button is-link">
|
||||||
<span class="icon"><i class="fas fa-edit"></i></span>
|
{{ "edit"|icon }}
|
||||||
<span>Edit</span>
|
<span>Edit</span>
|
||||||
</a>
|
</a>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
from django import template
|
||||||
|
from django.utils import timesince
|
||||||
|
from django.utils.html import format_html
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter("icon", is_safe=True)
|
||||||
|
def material_icon(value):
|
||||||
|
return f'<span class="icon"><span class="material-symbols-outlined">{value}</span></span>'
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def icon(name, element="span", classes=[]):
|
||||||
|
classes = ["icon"] + classes
|
||||||
|
return format_html(
|
||||||
|
'<{} class="{}"><span class="material-symbols-outlined">{}</span></{}>',
|
||||||
|
element,
|
||||||
|
" ".join(classes),
|
||||||
|
name,
|
||||||
|
element,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def roughtimesince(value):
|
||||||
|
return timesince.timesince(value, depth=1)
|
||||||
|
|
||||||
|
|
||||||
|
register.filter("roughtimesince", roughtimesince)
|
||||||
|
|
||||||
|
|
||||||
|
def roughtimeuntil(value):
|
||||||
|
return timesince.timeuntil(value, depth=1)
|
||||||
|
|
||||||
|
|
||||||
|
register.filter("roughtimeuntil", roughtimeuntil)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from interface import models
|
from polyphonic.interface import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
|
from polyphonic.interface import models
|
||||||
from interface import models
|
|
||||||
|
|
||||||
from . import AccessTestCase
|
from . import AccessTestCase
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ from django.contrib.auth import logout
|
|||||||
from markdown2 import markdown
|
from markdown2 import markdown
|
||||||
|
|
||||||
from . import models, forms
|
from . import models, forms
|
||||||
from interface.utils import check_signed_url
|
from .utils import check_signed_url
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -2,4 +2,4 @@ from django.apps import AppConfig
|
|||||||
|
|
||||||
|
|
||||||
class LibraryConfig(AppConfig):
|
class LibraryConfig(AppConfig):
|
||||||
name = "library"
|
name = "polyphonic.library"
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from .models import Work
|
from .models import Work
|
||||||
from interface.models import Project
|
from polyphonic.interface.models import Project
|
||||||
from interface.forms import BaseForm
|
from polyphonic.interface.forms import BaseForm
|
||||||
|
|
||||||
|
|
||||||
class WorkCreateForm(forms.ModelForm, BaseForm):
|
class WorkCreateForm(forms.ModelForm, BaseForm):
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
from library.models import Collection, Work, WorkMeta, Document
|
from polyphonic.library.models import Collection, Work, WorkMeta, Document
|
||||||
|
from byostorage.models import UserStorage
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -6,21 +7,26 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def sync_work(work: Work):
|
def sync_work(work: Work):
|
||||||
logger.info("Syncing '%s'", work.name)
|
try:
|
||||||
folder_id = work.meta_info.get(name="folderid").value
|
folder_id = work.meta_info.get(name="folderid").value
|
||||||
|
except WorkMeta.DoesNotExist as err:
|
||||||
|
raise IndexError("Work not currently linked to a gdrive folder") from err
|
||||||
|
|
||||||
storage = work.collection.storage.instance()
|
logger.info("Syncing '%s' from %r", work.name, folder_id)
|
||||||
prefix = work.collection.storage.name
|
|
||||||
_, files = storage.listdir(folder_id)
|
storage = UserStorage.objects.get(name="gdrive").instance()
|
||||||
|
|
||||||
existing = set(
|
existing = set(
|
||||||
[
|
[
|
||||||
storage.parse_id(x.partition(":")[2])
|
storage.parse_resource(x.partition(":")[2]).id
|
||||||
for x in work.docs.values_list("upload", flat=True)
|
for x in work.docs.values_list("upload", flat=True)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
logger.debug("%d existing documents", len(existing))
|
logger.debug("%d existing documents", len(existing))
|
||||||
|
|
||||||
|
_, files = storage.listdir(folder_id)
|
||||||
|
logger.debug("Remote files: %r", files)
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.id in existing:
|
if file.id in existing:
|
||||||
logger.debug("%30s: Skipping existing (%s)", file.name, file.id)
|
logger.debug("%30s: Skipping existing (%s)", file.name, file.id)
|
||||||
@@ -32,21 +38,26 @@ def sync_work(work: Work):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
logger.info("%40s: Adding", file.name)
|
logger.info("%40s: Adding", file.name)
|
||||||
doc = work.docs.create(upload=f"{prefix}:{file}", doctype=Document.DOCTYPE_PDF)
|
doc = work.docs.create(upload=f"gdrive:{file}", doctype=Document.DOCTYPE_PDF)
|
||||||
doc.auto_tag()
|
doc.auto_tag()
|
||||||
|
|
||||||
for uri in existing:
|
for uri in existing:
|
||||||
logger.warning("Local entry not in folder: %s", uri)
|
logger.warning("Local entry not in folder: %s", uri)
|
||||||
|
|
||||||
|
|
||||||
|
def sync_partial_collection(collection: Collection, sync_existing: bool = True):
|
||||||
|
|
||||||
|
works = Work.objects.filter(collection=collection, meta_info__name="folderid")
|
||||||
|
|
||||||
|
for work in works:
|
||||||
|
sync_work(work)
|
||||||
|
|
||||||
|
|
||||||
def sync_collection(collection: Collection, sync_existing: bool = False):
|
def sync_collection(collection: Collection, sync_existing: bool = False):
|
||||||
logger.info("Syncing '%s'", collection)
|
logger.info("Syncing '%s'", collection)
|
||||||
|
|
||||||
if not collection.storage.storage.endswith("GDriveLinkStorage"):
|
if not collection.storage.storage.endswith("GDriveLinkStorage"):
|
||||||
raise RuntimeError("Not a gdrive storage")
|
return sync_partial_collection(collection, sync_existing)
|
||||||
|
|
||||||
if not collection.prefix:
|
|
||||||
raise KeyError("Prefix must store folder id")
|
|
||||||
|
|
||||||
existing = dict(
|
existing = dict(
|
||||||
WorkMeta.objects.filter(
|
WorkMeta.objects.filter(
|
||||||
@@ -54,10 +65,14 @@ def sync_collection(collection: Collection, sync_existing: bool = False):
|
|||||||
).values_list("value", "work_id")
|
).values_list("value", "work_id")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
folder = collection.prefix
|
||||||
storage = collection.storage.instance()
|
storage = collection.storage.instance()
|
||||||
folders, _ = storage.listdir(collection.prefix)
|
folders, _ = storage.listdir(folder)
|
||||||
|
|
||||||
for folder in folders:
|
for folder in folders:
|
||||||
|
if folder[0] == "_":
|
||||||
|
continue
|
||||||
|
|
||||||
if folder.id in existing:
|
if folder.id in existing:
|
||||||
if sync_existing:
|
if sync_existing:
|
||||||
logger.info("%40s: Syncing (%s)", folder.name, folder.id[:12])
|
logger.info("%40s: Syncing (%s)", folder.name, folder.id[:12])
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
from django.core.files.storage import Storage
|
||||||
|
from collections import namedtuple
|
||||||
|
import requests
|
||||||
|
import re
|
||||||
|
from gzip import GzipFile
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
SHARED_FOLDER = re.compile(
|
||||||
|
r"https://drive.google.com/drive[u0-9\/]+folders/([\w\-]+)(\?resourcekey=([\w\-]+))?"
|
||||||
|
)
|
||||||
|
SHARED_FILE = re.compile(
|
||||||
|
r"https://drive.google.com/file/d/([\w\-]+)(\?resourcekey=([\w\-]+))?"
|
||||||
|
)
|
||||||
|
|
||||||
|
FILES_API = "https://www.googleapis.com/drive/v3/files"
|
||||||
|
|
||||||
|
|
||||||
|
class DriveObject(namedtuple("DriveObject", ("id", "key", "name"))):
|
||||||
|
@classmethod
|
||||||
|
def from_string(cls, s: str):
|
||||||
|
resource, _, name = s.partition("/")
|
||||||
|
id, _, key = resource.partition("#")
|
||||||
|
return cls(id, key, name)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
resource = f"{self.id}#{self.key}" if self.key else self.id
|
||||||
|
return f"{resource}/{self.name}"
|
||||||
|
|
||||||
|
|
||||||
|
class GDriveLinkStorage(Storage):
|
||||||
|
is_writable = False
|
||||||
|
|
||||||
|
def __init__(self, api_key):
|
||||||
|
self.api_key = api_key
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def parse_resource(self, name) -> DriveObject:
|
||||||
|
return DriveObject.from_string(name)
|
||||||
|
|
||||||
|
def extract_resource(self, url, *patterns) -> DriveObject:
|
||||||
|
logger.debug("EXTRACT_RESOURCE: %r", url)
|
||||||
|
for pattern in patterns:
|
||||||
|
match = pattern.match(url)
|
||||||
|
if match:
|
||||||
|
groups = match.groups()
|
||||||
|
logger.debug(groups)
|
||||||
|
if len(groups) == 3:
|
||||||
|
return DriveObject(groups[0], groups[2], "")
|
||||||
|
return DriveObject(groups[0], None, "")
|
||||||
|
raise FileNotFoundError(f"Not a valid url: {url}")
|
||||||
|
|
||||||
|
def get_json(self, url, resource: DriveObject):
|
||||||
|
headers = {}
|
||||||
|
if resource.key:
|
||||||
|
headers["X-Goog-Drive-Resource-Keys"] = f"{resource.id}/{resource.key}"
|
||||||
|
|
||||||
|
logger.debug("GET_JSON: %s %r", url, headers)
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
data = response.json()
|
||||||
|
logger.debug("Data: %r", data)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def listdir(self, path) -> tuple[list[str], list[str]]:
|
||||||
|
# used to test for valid connection parameters - should do something to validate API key here
|
||||||
|
logger.debug("listdir: %s", path)
|
||||||
|
if path == "":
|
||||||
|
return [], []
|
||||||
|
|
||||||
|
folder = self.parse_resource(path)
|
||||||
|
url = f"{FILES_API}?q='{folder.id}'+in+parents&key={self.api_key}"
|
||||||
|
data = self.get_json(url, folder)
|
||||||
|
files = []
|
||||||
|
folders = []
|
||||||
|
for x in data["files"]:
|
||||||
|
if x["mimeType"] == "application/vnd.google-apps.folder":
|
||||||
|
# folders.append(f"{x['id']}/{x['name']}")
|
||||||
|
folders.append(DriveObject(x["id"], x.get("resourceKey"), x["name"]))
|
||||||
|
else:
|
||||||
|
# files.append(f"{x['id']}/{x['name']}")
|
||||||
|
files.append(DriveObject(x["id"], x.get("resourceKey"), x["name"]))
|
||||||
|
|
||||||
|
return folders, files
|
||||||
|
|
||||||
|
def get_meta(self, name):
|
||||||
|
file_resource = self.parse_resource(name)
|
||||||
|
url = f"{FILES_API}/{file_resource.id}?key={self.api_key}"
|
||||||
|
return self.get_json(url, file_resource)
|
||||||
|
|
||||||
|
def open(self, name, mode="rb"):
|
||||||
|
resource = self.parse_resource(name)
|
||||||
|
url = f"{FILES_API}/{resource.id}?alt=media&key={self.api_key}"
|
||||||
|
|
||||||
|
headers = {}
|
||||||
|
if resource.key:
|
||||||
|
headers["X-Goog-Drive-Resource-Keys"] = f"{resource.id}/{resource.key}"
|
||||||
|
logger.info("URL: %s [%r]", url, headers)
|
||||||
|
|
||||||
|
response = requests.get(url, headers=headers, stream=True)
|
||||||
|
return GzipFile(name, "rb", 9, response.raw)
|
||||||
|
|
||||||
|
def size(self, name):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def delete(self, name):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def url(self, name):
|
||||||
|
logger.debug("URL: %r", name)
|
||||||
|
resource = self.parse_resource(name)
|
||||||
|
uri = f"https://drive.usercontent.google.com/download?export=download&id={resource.id}&confirm=yes"
|
||||||
|
if resource.key:
|
||||||
|
uri += f"&resourcekey=${resource.key}"
|
||||||
|
return uri
|
||||||
|
|
||||||
|
def get_folder_id(self, url):
|
||||||
|
try:
|
||||||
|
return self.extract_resource(url, SHARED_FOLDER)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_file_id(self, url):
|
||||||
|
try:
|
||||||
|
return self.extract_resource(url, SHARED_FILE)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def import_link(self, url) -> str:
|
||||||
|
file_resource = self.extract_resource(url, SHARED_FILE)
|
||||||
|
meta = self.get_meta(file_resource)
|
||||||
|
return f"{file_resource}/{meta['name']}"
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
def folder_import(self, url) -> list[str]:
|
||||||
|
folder_id = self.extract_id(url, SHARED_FOLDER)
|
||||||
|
_, files = self.listdir(folder_id)
|
||||||
|
return files
|
||||||
|
"""
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
from django.shortcuts import resolve_url, redirect
|
from django.shortcuts import resolve_url, redirect
|
||||||
from django.views.generic import FormView
|
from django.views.generic import FormView
|
||||||
from django.views.generic.detail import SingleObjectMixin
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
from library.views import CollectionMixin
|
from polyphonic.library.views import CollectionMixin
|
||||||
from library.models import Work, Document
|
from polyphonic.library.models import Work, Document
|
||||||
from library import forms
|
from polyphonic.library import forms
|
||||||
|
from byostorage.models import UserStorage
|
||||||
|
|
||||||
|
from . import sync_work
|
||||||
|
|
||||||
|
|
||||||
class WorkGDriveView(CollectionMixin, SingleObjectMixin, FormView):
|
class WorkGDriveView(CollectionMixin, SingleObjectMixin, FormView):
|
||||||
@@ -27,31 +30,30 @@ class WorkGDriveView(CollectionMixin, SingleObjectMixin, FormView):
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
link = form.cleaned_data["link"]
|
link = form.cleaned_data["link"]
|
||||||
|
|
||||||
storage = self.collection.storage.instance()
|
# storage = self.collection.storage.instance()
|
||||||
|
storage = UserStorage.objects.get(name="gdrive").instance()
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
|
||||||
try:
|
|
||||||
folderid = storage.get_folder_id(link)
|
folderid = storage.get_folder_id(link)
|
||||||
|
if folderid:
|
||||||
self.object.meta_info.update_or_create(
|
self.object.meta_info.update_or_create(
|
||||||
name="folderid", defaults={"value": folderid}
|
name="folderid", defaults={"value": folderid}
|
||||||
)
|
)
|
||||||
return redirect("work_detail", self.collection.pk, self.kwargs["pk"])
|
sync_work(self.object)
|
||||||
except FileNotFoundError:
|
|
||||||
pass # not a folder id
|
|
||||||
|
|
||||||
try:
|
return redirect("work_detail", self.collection.pk, self.kwargs["pk"])
|
||||||
link = self.collection.storage.instance().import_link(link)
|
|
||||||
except AttributeError:
|
link = storage.import_link(link)
|
||||||
pass
|
if link is None:
|
||||||
except FileNotFoundError as e:
|
form.add_error("link", "Not a valid link")
|
||||||
form.add_error("link", str(e))
|
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
work = self.collection.works.get(pk=self.kwargs["pk"])
|
work = self.collection.works.get(pk=self.kwargs["pk"])
|
||||||
|
|
||||||
doc = Document(
|
doc = Document(
|
||||||
work=work,
|
work=work,
|
||||||
upload=f"{self.collection.storage.name}:{link}",
|
upload=f"gdrive:{link}",
|
||||||
|
# upload=f"{self.collection.storage.name}:{link}",
|
||||||
doctype=Document.DOCTYPE_PDF,
|
doctype=Document.DOCTYPE_PDF,
|
||||||
)
|
)
|
||||||
doc.save()
|
doc.save()
|
||||||
@@ -3,9 +3,9 @@ from django.conf import settings
|
|||||||
from django.utils.module_loading import import_module
|
from django.utils.module_loading import import_module
|
||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
|
|
||||||
from library.models import Work, Collection
|
from polyphonic.library.models import Work, Collection
|
||||||
|
|
||||||
instance = getattr(settings, "INDEXER", "library.indexer.whoosh")
|
instance = getattr(settings, "INDEXER", "polyphonic.library.indexer.whoosh")
|
||||||
|
|
||||||
|
|
||||||
class Indexer(Protocol):
|
class Indexer(Protocol):
|
||||||
@@ -3,7 +3,7 @@ from whoosh.analysis import StemmingAnalyzer, CharsetFilter
|
|||||||
from whoosh.support.charset import accent_map
|
from whoosh.support.charset import accent_map
|
||||||
from whoosh.fields import Schema, TEXT, KEYWORD, NUMERIC
|
from whoosh.fields import Schema, TEXT, KEYWORD, NUMERIC
|
||||||
from whoosh.qparser import QueryParser
|
from whoosh.qparser import QueryParser
|
||||||
from whoosh.query import Term, NullQuery
|
from whoosh.query import Term, NullQuery, FuzzyTerm
|
||||||
|
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@@ -24,7 +24,7 @@ schema = Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
index_path = os.path.join(os.path.dirname(settings.BASE_DIR), "index")
|
index_path = settings.WHOOSH_INDEX
|
||||||
|
|
||||||
|
|
||||||
def create_index() -> Index:
|
def create_index() -> Index:
|
||||||
@@ -61,20 +61,26 @@ def search(
|
|||||||
pagesize: int = 20,
|
pagesize: int = 20,
|
||||||
) -> tuple[list[dict], dict[str, Any]]:
|
) -> tuple[list[dict], dict[str, Any]]:
|
||||||
meta = {}
|
meta = {}
|
||||||
|
query = query.lower()
|
||||||
|
|
||||||
qp = QueryParser("text", schema=schema)
|
qp = QueryParser("text", schema=schema)
|
||||||
q = qp.parse(query.lower())
|
q = qp.parse(query)
|
||||||
meta["query"] = str(q)
|
|
||||||
|
|
||||||
terms = NullQuery
|
limit = NullQuery
|
||||||
for c in collections:
|
for c in collections:
|
||||||
terms = terms | Term("collection", c)
|
limit |= Term("collection", c)
|
||||||
q = q & terms
|
|
||||||
|
|
||||||
hits = []
|
hits = []
|
||||||
ix = get_index()
|
ix = get_index()
|
||||||
with ix.searcher() as searcher:
|
with ix.searcher() as searcher:
|
||||||
results = searcher.search_page(q, page, pagesize)
|
results = searcher.search_page(q & limit, page, pagesize)
|
||||||
|
|
||||||
|
# if no results, do a prefix search
|
||||||
|
if results.results.is_empty():
|
||||||
|
qp.termclass = FuzzyTerm
|
||||||
|
q = qp.parse(query)
|
||||||
|
results = searcher.search_page(q & limit, page, pagesize)
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
hits.append(
|
hits.append(
|
||||||
dict(
|
dict(
|
||||||
@@ -85,7 +91,7 @@ def search(
|
|||||||
collection_id=int(result["collection"]),
|
collection_id=int(result["collection"]),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
meta["query"] = str(q & limit)
|
||||||
meta["total"] = len(results)
|
meta["total"] = len(results)
|
||||||
|
|
||||||
return hits, meta
|
return hits, meta
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from library import models
|
from polyphonic.library import models
|
||||||
from library.indexer import model_search, index_works, indexer
|
from polyphonic.library.indexer import model_search, index_works, indexer
|
||||||
|
|
||||||
FORMATTER = "{w.name:50s} {w.edition:15s} {w.collection.name:15s}"
|
FORMATTER = "{w.name:50s} {w.edition:15s} {w.collection.name:15s}"
|
||||||
|
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from library.models import Work, Collection
|
from polyphonic.library.models import Work, Collection
|
||||||
from library.gdrive import sync_work, sync_collection
|
from polyphonic.library.gdrive import sync_work, sync_collection
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
+2
-2
@@ -4,7 +4,7 @@ import byostorage.user
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
import library.models
|
import polyphonic.library.models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@@ -35,7 +35,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('doctype', models.PositiveSmallIntegerField(choices=[(1, 'PDF'), (2, 'Audio'), (3, 'Video'), (4, 'Source')], default=1)),
|
('doctype', models.PositiveSmallIntegerField(choices=[(1, 'PDF'), (2, 'Audio'), (3, 'Video'), (4, 'Source')], default=1)),
|
||||||
('upload', models.FileField(storage=byostorage.user.BYOStorage(), upload_to=library.models.doc_upload_filename)),
|
('upload', models.FileField(storage=byostorage.user.BYOStorage(), upload_to=polyphonic.library.models.doc_upload_filename)),
|
||||||
('created', models.DateTimeField(auto_now_add=True)),
|
('created', models.DateTimeField(auto_now_add=True)),
|
||||||
('version', models.CharField(blank=True, max_length=30)),
|
('version', models.CharField(blank=True, max_length=30)),
|
||||||
],
|
],
|
||||||
+2
-2
@@ -3,7 +3,7 @@
|
|||||||
import byostorage.cached
|
import byostorage.cached
|
||||||
import byostorage.user
|
import byostorage.user
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import library.models
|
import polyphonic.library.models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@@ -26,7 +26,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='document',
|
model_name='document',
|
||||||
name='upload',
|
name='upload',
|
||||||
field=models.FileField(storage=byostorage.cached.CachedStorage(byostorage.user.BYOStorage()), upload_to=library.models.doc_upload_filename),
|
field=models.FileField(storage=byostorage.cached.CachedStorage(byostorage.user.BYOStorage()), upload_to=polyphonic.library.models.doc_upload_filename),
|
||||||
),
|
),
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='work',
|
model_name='work',
|
||||||
@@ -11,8 +11,8 @@ import os.path
|
|||||||
from byostorage.user import BYOStorage
|
from byostorage.user import BYOStorage
|
||||||
from byostorage.cached import CachedStorage
|
from byostorage.cached import CachedStorage
|
||||||
|
|
||||||
from library.music_tags import MusicTag, auto_tag
|
from polyphonic.library.music_tags import MusicTag, auto_tag
|
||||||
from interface.utils import sign_data
|
from polyphonic.interface.utils import sign_data
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -19,6 +19,10 @@ cb Double Bass
|
|||||||
mall Mallet Percussion
|
mall Mallet Percussion
|
||||||
vln Violin
|
vln Violin
|
||||||
vla Viola
|
vla Viola
|
||||||
|
kit Drumkit
|
||||||
|
asax Alto Sax
|
||||||
|
tsax Tenor Sax
|
||||||
|
bsax Bari Sax
|
||||||
|
|
||||||
acc Accordion
|
acc Accordion
|
||||||
afl Alto flute
|
afl Alto flute
|
||||||
+5
-1
@@ -1,4 +1,5 @@
|
|||||||
{% extends "interface/project_base.html" %}
|
{% extends "interface/project_base.html" %}
|
||||||
|
{% load polyphonic %}
|
||||||
|
|
||||||
{% block page %}
|
{% block page %}
|
||||||
<h3 class="title">Library collections for {% firstof request.user.first_name request.user.username %}</h3>
|
<h3 class="title">Library collections for {% firstof request.user.first_name request.user.username %}</h3>
|
||||||
@@ -10,7 +11,9 @@
|
|||||||
<input class="input" name="q" type="text" placeholder="Find a work" value="{{ request.GET.filter }}"/>
|
<input class="input" name="q" type="text" placeholder="Find a work" value="{{ request.GET.filter }}"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<a class="button" href="?"><i class="fas fa-times"></i></a>
|
<a class="button" href="?">
|
||||||
|
{% icon "close" %}
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -47,4 +50,5 @@
|
|||||||
<div>
|
<div>
|
||||||
<small>{{ ensemble.ensemble_code }}</small>
|
<small>{{ ensemble.ensemble_code }}</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
+23
-9
@@ -1,11 +1,13 @@
|
|||||||
{% extends "interface/project_base.html" %}
|
{% extends "interface/project_base.html" %}
|
||||||
|
{% load polyphonic %}
|
||||||
|
|
||||||
{% block admin %}
|
{% block admin %}
|
||||||
<a href="#" onclick="saveTags()" class="button is-link">
|
<a href="#" onclick="saveTags()" class="button is-link">
|
||||||
<span class="icon"><i class="fas fa-save"></i></span>
|
{% icon "save" %}
|
||||||
<span>Save</span>
|
<span>Save</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="{% url 'work_detail' collection=collection.pk pk=object.work_id %}" class="button is-link is-light">
|
<a href="{% url 'work_detail' collection=collection.pk pk=object.work_id %}" class="button is-link is-light">
|
||||||
|
{% icon "backspace" %}
|
||||||
<span>Cancel</span>
|
<span>Cancel</span>
|
||||||
</a>
|
</a>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -76,7 +78,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<ul id="unassigned-area">
|
<ul id="unassigned-area">
|
||||||
{% for tag, inst in document.work.music_tags %}
|
{% for tag, inst in document.work.music_tags %}
|
||||||
<li class="is-clickable" onclick="assignInstrument('{{tag}}', this)")>{{ inst }}</li>
|
<li>
|
||||||
|
<span class="is-clickable" onclick="assignInstrument('{{tag}}', this)")>{{ inst }}</span>
|
||||||
|
|
||||||
|
<span class="is-clickable" onclick="addNumberedInstrument('{{tag}}', this)">...</span>
|
||||||
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<a onclick="document.getElementById('add-modal').classList.add('is-active')">Add Tag</a>
|
<a onclick="document.getElementById('add-modal').classList.add('is-active')">Add Tag</a>
|
||||||
@@ -276,6 +282,16 @@
|
|||||||
document.getElementById('add-instrument-variant').value = "";
|
document.getElementById('add-instrument-variant').value = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addNumberedInstrument(tag, e) {
|
||||||
|
let modal = document.getElementById('add-modal');
|
||||||
|
|
||||||
|
document.getElementById("add-instrument-name").value = data.instruments[tag];
|
||||||
|
document.getElementById("add-instrument-variant").value = 1;
|
||||||
|
document.getElementById("add-instrument-variant").focus();
|
||||||
|
|
||||||
|
modal.classList.add('is-active');
|
||||||
|
}
|
||||||
|
|
||||||
function addInstrument() {
|
function addInstrument() {
|
||||||
let name = document.getElementById('add-instrument-name');
|
let name = document.getElementById('add-instrument-name');
|
||||||
let variant = document.getElementById('add-instrument-variant');
|
let variant = document.getElementById('add-instrument-variant');
|
||||||
@@ -326,7 +342,7 @@
|
|||||||
|
|
||||||
let setStart = document.createElement('span');
|
let setStart = document.createElement('span');
|
||||||
setStart.className = "icon is-action";
|
setStart.className = "icon is-action";
|
||||||
setStart.innerHTML = '<i class="fas fa-sort-amount-down" title="Set start page"></i>';
|
setStart.innerHTML = '<span class="material-symbols-outlined" title="Set start page">vertical_align_top</span>';
|
||||||
setStart.addEventListener('click', () => setTagStart(el));
|
setStart.addEventListener('click', () => setTagStart(el));
|
||||||
el.appendChild(setStart);
|
el.appendChild(setStart);
|
||||||
|
|
||||||
@@ -336,22 +352,20 @@
|
|||||||
let name = document.createElement('b');
|
let name = document.createElement('b');
|
||||||
name.innerHTML = get_instrument(tag);
|
name.innerHTML = get_instrument(tag);
|
||||||
label.appendChild(name);
|
label.appendChild(name);
|
||||||
|
el.appendChild(label);
|
||||||
|
|
||||||
let del = document.createElement('span');
|
let del = document.createElement('span');
|
||||||
del.className = "icon is-action";
|
del.className = "icon is-action";
|
||||||
del.innerHTML = '<i class="fas fa-trash-alt" title="Remove this tag"></i>';
|
del.innerHTML = '<span class="material-symbols-outlined" title="Remove this tag">delete</span>';
|
||||||
del.addEventListener('click', () => {
|
del.addEventListener('click', () => {
|
||||||
el.remove();
|
el.remove();
|
||||||
dirty=true;
|
dirty=true;
|
||||||
});
|
});
|
||||||
label.appendChild(del)
|
el.appendChild(del)
|
||||||
|
|
||||||
el.appendChild(label);
|
|
||||||
|
|
||||||
|
|
||||||
let setEnd = document.createElement('span');
|
let setEnd = document.createElement('span');
|
||||||
setEnd.className = "icon is-action";
|
setEnd.className = "icon is-action";
|
||||||
setEnd.innerHTML = '<i class="fas fa-sort-amount-up" title="Set end page"></i>';
|
setEnd.innerHTML = '<span class="material-symbols-outlined" title="Set end page">vertical_align_bottom</span>';
|
||||||
setEnd.addEventListener('click', () => setTagEnd(el));
|
setEnd.addEventListener('click', () => setTagEnd(el));
|
||||||
el.appendChild(setEnd);
|
el.appendChild(setEnd);
|
||||||
|
|
||||||
+11
-5
@@ -1,7 +1,10 @@
|
|||||||
{% load path_filters %}
|
{% load path_filters %}
|
||||||
|
{% load polyphonic %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ doc.upload.url }}" target="_blank">
|
<td style="white-space: nowrap">
|
||||||
{{ doc.upload.name|basename }}</a></td>
|
<a href="{{ doc.upload.url }}" target="_blank">
|
||||||
|
{{ doc.upload.name|basename }}</a>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% for section in doc.sections.all %}
|
{% for section in doc.sections.all %}
|
||||||
<a class="tag is-{{ section.bulma_class }}" target="_blank" href="{% url 'part_download' collection.pk section.pk section.filename %}">{{ section.name }}</a>
|
<a class="tag is-{{ section.bulma_class }}" target="_blank" href="{% url 'part_download' collection.pk section.pk section.filename %}">{{ section.name }}</a>
|
||||||
@@ -10,10 +13,13 @@
|
|||||||
<td class="has-text-right" style="white-space: nowrap;">
|
<td class="has-text-right" style="white-space: nowrap;">
|
||||||
{% if request.is_admin %}
|
{% if request.is_admin %}
|
||||||
{% if doc.doctype == 1 %}
|
{% if doc.doctype == 1 %}
|
||||||
<a href="{% url 'document_annotate' collection.pk doc.pk %}"><i class="fas fa-tags"
|
<a href="{% url 'document_annotate' collection.pk doc.pk %}" title="Annotate">
|
||||||
title="Manage Tags"></i></a>
|
{% icon "toc" %}
|
||||||
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{% url 'document_delete' collection.pk doc.pk %}"><i class="fas fa-trash-alt" title="Delete Document"></i></a>
|
<a href="{% url 'document_delete' collection.pk doc.pk %}" title="Delete">
|
||||||
|
{% icon "delete" %}
|
||||||
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
+15
-11
@@ -1,12 +1,18 @@
|
|||||||
{% extends "interface/project_base.html" %}
|
{% extends "interface/project_base.html" %}
|
||||||
|
{% load polyphonic %}
|
||||||
|
|
||||||
{% block admin %}
|
{% block admin %}
|
||||||
<a href="{% url 'work_detail' collection=collection.pk pk=object.pk %}" class="button is-link is-light">
|
<a href="{% url 'work_detail' collection=collection.pk pk=object.pk %}" class="button is-link is-light">
|
||||||
|
{% icon "backspace" %}
|
||||||
<span>Back to work</span>
|
<span>Back to work</span>
|
||||||
</a>
|
</a>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page %}
|
{% block page %}
|
||||||
|
<h2 class="title">
|
||||||
|
{% icon "add_to_drive" %}
|
||||||
|
<span>Google Drive - Shared Links
|
||||||
|
</h2>
|
||||||
<h3 class="subtitle"><a href="{% url 'work_detail' collection.pk object.pk %}">{{ object.name }}</a></h3>
|
<h3 class="subtitle"><a href="{% url 'work_detail' collection.pk object.pk %}">{{ object.name }}</a></h3>
|
||||||
<div class="m-3">
|
<div class="m-3">
|
||||||
<p>This page lets you link a work to a google drive folder. You can either paste a public link to a folder to enable syncing or a file to add individually</p>
|
<p>This page lets you link a work to a google drive folder. You can either paste a public link to a folder to enable syncing or a file to add individually</p>
|
||||||
@@ -14,25 +20,23 @@
|
|||||||
<div class="m-3">
|
<div class="m-3">
|
||||||
<p>
|
<p>
|
||||||
{% if meta.folderid %}
|
{% if meta.folderid %}
|
||||||
This work is currently linked to <b>{{ meta.folderid }}</b>. Pasting a new folder link will overwrite this.
|
This work is currently linked to <b>{{ meta.folderid }}</b>.<br/>
|
||||||
|
Pasting a new folder link will overwrite this.
|
||||||
{% else %}
|
{% else %}
|
||||||
There is currently no shared drive folder linked to this work - paste one here to enable syncing.
|
There is currently no shared drive folder linked to this work - paste one here to enable syncing.
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="mt-5">
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="field">
|
<div class="field has-addons mx-6">
|
||||||
<div class="control">
|
<div class="control is-expanded">
|
||||||
<input name="link" class="input is-expanded" type="text" placeholder="Shared link">
|
<input class="input" name="link" type="text" placeholder="Paste shared link">
|
||||||
</div>
|
</div>
|
||||||
{% for error in form.errors.link %}
|
|
||||||
<p class="help is-danger">{{ error }}</p>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<button class="button is-info" type="submit">Add</button>
|
<button class="button" type="submit">
|
||||||
|
Add
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
+32
-21
@@ -1,4 +1,5 @@
|
|||||||
{% extends "interface/project_base.html" %}
|
{% extends "interface/project_base.html" %}
|
||||||
|
{% load polyphonic %}
|
||||||
|
|
||||||
{% block page %}
|
{% block page %}
|
||||||
<form action="" method="post" target="_blank">
|
<form action="" method="post" target="_blank">
|
||||||
@@ -31,12 +32,6 @@
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span class="control">
|
|
||||||
<button type="submit" class="button is-primary">
|
|
||||||
<span class="icon"><i class="fas fa-copy"></i></span>
|
|
||||||
<span>Get My Parts!</span>
|
|
||||||
</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -45,6 +40,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th/>
|
<th/>
|
||||||
<th>Piece</th>
|
<th>Piece</th>
|
||||||
|
<th>Composer</th>
|
||||||
<th class="is-hidden-mobile">Running time</th>
|
<th class="is-hidden-mobile">Running time</th>
|
||||||
<th>Part</th>
|
<th>Part</th>
|
||||||
<th/>
|
<th/>
|
||||||
@@ -61,11 +57,12 @@
|
|||||||
{{ item.work.name }}
|
{{ item.work.name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
<td class="is-hidden-mobile">{{ item.work.composer }}</td>
|
||||||
<td class="is-hidden-mobile">{% firstof item.work.running_time "------" %}</td>
|
<td class="is-hidden-mobile">{% firstof item.work.running_time "------" %}</td>
|
||||||
<td class="select-cell">
|
<td class="select-cell">
|
||||||
<input type="hidden" name="works" value="{{ item.work.pk }}"/>
|
<input type="hidden" name="works" value="{{ item.work.pk }}"/>
|
||||||
<span class="select is-small" style="width: 100%">
|
<span class="select is-small" style="width: 100%">
|
||||||
<select name="instruments" id="part-{{ item.work.pk }}" style="width: 100%">
|
<select name="instrument-selection" id="part-{{ item.work.pk }}" style="width: 100%">
|
||||||
<option value='-'>None</option>
|
<option value='-'>None</option>
|
||||||
{% for tag, name in item.work.digital_parts %}
|
{% for tag, name in item.work.digital_parts %}
|
||||||
<option value='{{ tag }}'>{{ name }}</option>
|
<option value='{{ tag }}'>{{ name }}</option>
|
||||||
@@ -74,8 +71,9 @@
|
|||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="is-action" onclick="downloadPart({{ item.work.collection_id }}, {{ item.work.pk }})">
|
<span class="button is-link is-small" onclick="downloadPart({{ item.work.collection_id }}, {{ item.work.pk }})">
|
||||||
<i class="fas fa-download" title="Download Part"></i>
|
{% icon "download" %}
|
||||||
|
<span>Get</span>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -85,13 +83,17 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td/>
|
<td/>
|
||||||
<td/>
|
<td/>
|
||||||
<td>{% firstof running_time "------" %}</td>
|
|
||||||
<td/>
|
<td/>
|
||||||
<td>
|
<td>{% firstof running_time "------" %}</td>
|
||||||
<!--
|
<td colspan="2">
|
||||||
<button class="button is-link is-small" type="submit"><span class="icon"><i class="fas fa-copy"></i></span><span>Single combined PDF</span></button>
|
<button class="button is-link is-small" type="submit" name="action" value="pdf">
|
||||||
<a class="button is-link is-small"><span class="icon"><i class="fas fa-archive"></i></span><span>Individual files (zipped)</span></a>
|
{% icon "two_pager" %}
|
||||||
-->
|
<span> Single combined PDF</span>
|
||||||
|
</button>
|
||||||
|
<button class="button is-link is-small" type="submit" name="action" value="zip">
|
||||||
|
{% icon "folder_zip" %}
|
||||||
|
<span> Individual files (zipped)</span>
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
@@ -112,16 +114,23 @@
|
|||||||
const INSTRUMENTS = JSON.parse(document.getElementById('instruments').innerText);
|
const INSTRUMENTS = JSON.parse(document.getElementById('instruments').innerText);
|
||||||
|
|
||||||
function updateParts() {
|
function updateParts() {
|
||||||
var inst = document.getElementById("instrument-name").value;
|
var inst = document.getElementById("instrument-name").value.toLowerCase();
|
||||||
window.localStorage.setItem('instrument-name', inst);
|
window.localStorage.setItem('instrument-name', inst);
|
||||||
|
console.log("Changing to", inst);
|
||||||
|
|
||||||
for (let i of INSTRUMENTS) {
|
for (let i of INSTRUMENTS) {
|
||||||
if (i[1] === inst) inst = i[0];
|
if (i[1].toLowerCase() === inst) {
|
||||||
|
inst = i[0];
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
console.log("Instrument code:", inst);
|
||||||
|
|
||||||
|
|
||||||
let part = document.getElementById("part-preference").value;
|
let part = document.getElementById("part-preference").value;
|
||||||
window.localStorage.setItem('part-preference', part);
|
window.localStorage.setItem('part-preference', part);
|
||||||
|
console.log("Part preference:", part);
|
||||||
|
|
||||||
|
|
||||||
selectParts(inst, part);
|
selectParts(inst, part);
|
||||||
@@ -132,10 +141,11 @@ function selectParts(inst, part) {
|
|||||||
|
|
||||||
let prefix = inst + "-" + part;
|
let prefix = inst + "-" + part;
|
||||||
|
|
||||||
let instruments = document.getElementsByName("instruments");
|
let selections = document.getElementsByName("instrument-selection");
|
||||||
for(let i=0; i<instruments.length; i++) {
|
console.log("Updating selections:", prefix, selections);
|
||||||
|
for(let i=0; i<selections.length; i++) {
|
||||||
var result = "-"
|
var result = "-"
|
||||||
let options = instruments[i].children;
|
let options = selections[i].children;
|
||||||
for(let j=0; j<options.length; j++) {
|
for(let j=0; j<options.length; j++) {
|
||||||
let value = options[j].value;
|
let value = options[j].value;
|
||||||
if (value.startsWith(prefix)) {
|
if (value.startsWith(prefix)) {
|
||||||
@@ -146,7 +156,8 @@ function selectParts(inst, part) {
|
|||||||
result = value;
|
result = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instruments[i].value = result;
|
console.log("Selected:", result);
|
||||||
|
selections[i].value = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user