Removing old files
This commit is contained in:
+18
-13
@@ -2,38 +2,43 @@ from django.contrib import admin
|
||||
|
||||
from . import models
|
||||
|
||||
#class OrchestrationAdmin(admin.ModelAdmin):
|
||||
# list_display = ['name', 'ensemble']
|
||||
# list_filter = ['ensemble']
|
||||
|
||||
#admin.site.register(models.Orchestration, OrchestrationAdmin)
|
||||
class EnsembleAccessInline(admin.StackedInline):
|
||||
model = models.EnsembleAccess
|
||||
extra = 0
|
||||
|
||||
class CollectionAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'location']
|
||||
list_display = ['name', 'location', 'storage', 'prefix']
|
||||
inlines = [EnsembleAccessInline]
|
||||
|
||||
admin.site.register(models.Collection, CollectionAdmin)
|
||||
|
||||
class ItemInline(admin.TabularInline):
|
||||
model = models.Item
|
||||
model = models.ProjectItem
|
||||
extra = 0
|
||||
|
||||
class DocInline(admin.TabularInline):
|
||||
model = models.Document
|
||||
extra = 0
|
||||
|
||||
class MetaInline(admin.TabularInline):
|
||||
model = models.WorkMeta
|
||||
extra = 0
|
||||
|
||||
class WorkAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'edition', 'composer', 'running_time']
|
||||
list_display = ['name', 'composer', 'edition', 'identifier', 'running_time']
|
||||
list_filter = ['collection']
|
||||
inlines = [DocInline, ItemInline]
|
||||
inlines = [MetaInline, DocInline, ItemInline]
|
||||
|
||||
admin.site.register(models.Work, WorkAdmin)
|
||||
|
||||
class PartInline(admin.TabularInline):
|
||||
model = models.Part
|
||||
class SectionInline(admin.TabularInline):
|
||||
model = models.Section
|
||||
fields = ['tag', 'start', 'end']
|
||||
|
||||
class DocumentAdmin(admin.ModelAdmin):
|
||||
list_display = ['work', '__str__']
|
||||
list_filter = ['work__collection']
|
||||
inlines = [PartInline]
|
||||
inlines = [SectionInline]
|
||||
|
||||
admin.site.register(models.Document, DocumentAdmin)
|
||||
|
||||
@@ -41,7 +46,7 @@ class ItemAdmin(admin.ModelAdmin):
|
||||
list_display = ['project', 'work', 'order']
|
||||
list_filter = ['project']
|
||||
|
||||
admin.site.register(models.Item, ItemAdmin)
|
||||
admin.site.register(models.ProjectItem, ItemAdmin)
|
||||
|
||||
class EnsembleAccessAdmin(admin.ModelAdmin):
|
||||
list_display = ['ensemble', 'collection', 'access_type']
|
||||
|
||||
+5
-3
@@ -1,15 +1,17 @@
|
||||
from django import forms
|
||||
from .models import Work
|
||||
from interface.models import Project
|
||||
from interface.widgets import DatePickerInput
|
||||
from django.db.models import Q
|
||||
from interface.forms import BaseForm
|
||||
|
||||
|
||||
class WorkCreateForm(forms.ModelForm):
|
||||
uploads = forms.FileField(label="PDFs to upload", widget=forms.ClearableFileInput(attrs={'multiple': True}), required=False)
|
||||
class WorkCreateForm(forms.ModelForm, BaseForm):
|
||||
#uploads = forms.FileField(label="PDFs to upload", widget=forms.ClearableFileInput(attrs={'multiple': True}), required=False)
|
||||
|
||||
class Meta:
|
||||
model = Work
|
||||
fields = ['uploads', 'name', 'composer', 'edition', 'collection', 'code', 'running_time', 'notes']
|
||||
fields = ['name', 'code', 'running_time', 'notes']
|
||||
|
||||
class PlaylistAddForm(forms.Form):
|
||||
work = forms.ModelChoiceField(queryset=Work.objects.all())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Generated by Django 3.1.1 on 2021-04-28 03:53
|
||||
# Generated by Django 3.2.7 on 2022-11-18 09:54
|
||||
|
||||
import byostorage.cached
|
||||
import byostorage.user
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
@@ -12,9 +12,9 @@ class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('interface', '0027_auto_20210322_1154'),
|
||||
('byostorage', '0003_auto_20210323_1047'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('byostorage', '0004_alter_userstorage_storage'),
|
||||
('interface', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@@ -22,11 +22,11 @@ class Migration(migrations.Migration):
|
||||
name='Collection',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('location', models.CharField(help_text='Physical location', max_length=100)),
|
||||
('notes', models.TextField(blank=True)),
|
||||
('name', models.CharField(help_text='Name of the collection', max_length=255)),
|
||||
('prefix', models.SlugField(default='default', max_length=30)),
|
||||
('location', models.CharField(help_text='Physical location (institution, town...)', max_length=100)),
|
||||
('notes', models.TextField(blank=True, help_text='Publicly visible notes about collection and loans policy')),
|
||||
('administrators', models.ManyToManyField(help_text='Administrators for this collection', related_name='collections', to=settings.AUTH_USER_MODEL)),
|
||||
('ensembles', models.ManyToManyField(related_name='collections', to='interface.Ensemble')),
|
||||
('storage', models.ForeignKey(blank=True, help_text='Storage for documents', null=True, on_delete=django.db.models.deletion.CASCADE, to='byostorage.userstorage')),
|
||||
],
|
||||
),
|
||||
@@ -35,65 +35,71 @@ class Migration(migrations.Migration):
|
||||
fields=[
|
||||
('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)),
|
||||
('upload', models.FileField(storage=byostorage.cached.CachedStorage(), upload_to=library.models.doc_upload_filename)),
|
||||
('upload', models.FileField(storage=byostorage.user.BYOStorage(), upload_to=library.models.doc_upload_filename)),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('version', models.CharField(blank=True, max_length=30)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Item',
|
||||
name='ProjectItem',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('checkout', models.DateTimeField()),
|
||||
('due', models.DateTimeField(blank=True, null=True)),
|
||||
('returned', models.DateTimeField(blank=True, null=True)),
|
||||
('order', models.SmallIntegerField(default=0)),
|
||||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='interface.project')),
|
||||
('approved_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='interface.project')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['order', 'work'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Orchestration',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('instruments', models.TextField()),
|
||||
('ensemble', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='orchestrations', to='interface.ensemble')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Work',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('slug', models.SlugField(editable=False, max_length=100)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('version', models.CharField(blank=True, help_text='Version or edition details', max_length=100)),
|
||||
('composer', models.CharField(blank=True, help_text='Use Composer / Arranger format', max_length=255)),
|
||||
('edition', models.CharField(blank=True, help_text='Edition details', max_length=255)),
|
||||
('composer', models.CharField(blank=True, max_length=255)),
|
||||
('orchestration', models.CharField(blank=True, help_text='IMDB format instrumentation', max_length=255)),
|
||||
('original_parts', models.JSONField(blank=True, help_text='Original printed parts', null=True)),
|
||||
('code', models.CharField(blank=True, help_text='Collection specific code or number', max_length=100)),
|
||||
('licence', models.PositiveSmallIntegerField(choices=[(2, 'Public Domain'), (4, 'Copyright Expired'), (6, 'Copyrighted'), (10, 'Internal use only')], default=6, help_text='Copyright status')),
|
||||
('max_loans', models.BooleanField(default=1, help_text='How many projects can this work be attached to')),
|
||||
('running_time', models.IntegerField(blank=True, help_text='Running time in seconds', null=True)),
|
||||
('max_projects', models.IntegerField(default=1, help_text='How many projects can this work be attached to')),
|
||||
('running_time', models.DurationField(blank=True, help_text='Running time in seconds', null=True)),
|
||||
('notes', models.TextField(blank=True)),
|
||||
('tag_list', models.CharField(blank=True, help_text='Multiple tags for the work', max_length=255)),
|
||||
('collection', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='works', to='library.collection')),
|
||||
('orchestration', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='works', to='library.orchestration')),
|
||||
('collection', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='works', to='library.collection')),
|
||||
('parent', models.ForeignKey(blank=True, help_text='Arrangement of another work or part of an anthology', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='related_works', to='library.work')),
|
||||
('projects', models.ManyToManyField(help_text='Current usage', related_name='works', through='library.Item', to='interface.Project')),
|
||||
('projects', models.ManyToManyField(help_text='Current usage', related_name='works', through='library.ProjectItem', to='interface.Project')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Part',
|
||||
name='WorkMeta',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.SlugField(choices=[('tag', 'Tag'), ('arr', 'Arranger'), ('lyrics', 'Lyracist'), ('genre', 'Genre'), ('style', 'Style')], max_length=20)),
|
||||
('value', models.CharField(max_length=255)),
|
||||
('work', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='meta_info', to='library.work')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Section',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('tag', models.SlugField(max_length=20)),
|
||||
('start', models.SmallIntegerField(blank=True, null=True)),
|
||||
('end', models.SmallIntegerField(blank=True, null=True)),
|
||||
('notes', models.TextField(blank=True)),
|
||||
('doc', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='parts', to='library.document')),
|
||||
('doc', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sections', to='library.document')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['doc', 'start', 'pk'],
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='item',
|
||||
model_name='projectitem',
|
||||
name='work',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='project_items', to='library.work'),
|
||||
),
|
||||
@@ -102,9 +108,12 @@ class Migration(migrations.Migration):
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('access_type', models.PositiveSmallIntegerField(choices=[(1, 'Unlimited'), (2, 'Approval required')], default=2)),
|
||||
('collection', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='library.collection')),
|
||||
('ensemble', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='interface.ensemble')),
|
||||
('collection', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allowed_ensembles', to='library.collection')),
|
||||
('ensemble', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allowed_collections', to='interface.ensemble')),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'Ensemble access',
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='document',
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
# Generated by Django 3.1.1 on 2021-05-04 08:30
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('library', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='item',
|
||||
name='approved_by',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='auth.user'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='item',
|
||||
name='checkin',
|
||||
field=models.DateTimeField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='item',
|
||||
name='checkout',
|
||||
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
@@ -1,24 +0,0 @@
|
||||
# Generated by Django 3.1.1 on 2021-05-04 08:45
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('library', '0002_auto_20210504_1830'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='work',
|
||||
name='max_loans',
|
||||
field=models.IntegerField(default=1, help_text='How many projects can this work be attached to'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='work',
|
||||
name='orchestration',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='works', to='library.orchestration'),
|
||||
),
|
||||
]
|
||||
@@ -1,44 +0,0 @@
|
||||
# Generated by Django 3.1.1 on 2021-05-04 23:27
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('library', '0003_auto_20210504_1845'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='item',
|
||||
old_name='checkin',
|
||||
new_name='due',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='item',
|
||||
name='returned',
|
||||
field=models.DateTimeField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='collection',
|
||||
name='location',
|
||||
field=models.CharField(help_text='Physical location (institution, town...)', max_length=100),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='collection',
|
||||
name='name',
|
||||
field=models.CharField(help_text='Often just the name of the owning ensemble', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='collection',
|
||||
name='notes',
|
||||
field=models.TextField(blank=True, help_text='Publicly visible notes about collection and loans policy'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='work',
|
||||
name='collection',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='works', to='library.collection'),
|
||||
),
|
||||
]
|
||||
@@ -1,18 +0,0 @@
|
||||
# Generated by Django 3.1.1 on 2021-05-06 02:41
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('library', '0004_auto_20210505_0927'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='work',
|
||||
name='parts',
|
||||
field=models.JSONField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
@@ -1,48 +0,0 @@
|
||||
# Generated by Django 3.2.7 on 2021-09-02 03:55
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('interface', '0028_ensemble_details'),
|
||||
('library', '0005_work_parts'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='ensembleaccess',
|
||||
options={'verbose_name_plural': 'Ensemble access'},
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='collection',
|
||||
name='ensembles',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='document',
|
||||
name='version',
|
||||
field=models.CharField(blank=True, max_length=30),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='item',
|
||||
name='version',
|
||||
field=models.CharField(blank=True, help_text='Limited to specific version tag', max_length=30),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='collection',
|
||||
name='name',
|
||||
field=models.CharField(help_text='Name of the collection', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='ensembleaccess',
|
||||
name='collection',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allowed_ensembles', to='library.collection'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='ensembleaccess',
|
||||
name='ensemble',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allowed_collections', to='interface.ensemble'),
|
||||
),
|
||||
]
|
||||
@@ -1,33 +0,0 @@
|
||||
# Generated by Django 3.2.7 on 2021-09-02 04:07
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('library', '0006_auto_20210902_1355'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='work',
|
||||
name='orchestration',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='work',
|
||||
name='version',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='document',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_created=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='work',
|
||||
name='edition',
|
||||
field=models.CharField(blank=True, help_text='Edition details', max_length=100),
|
||||
),
|
||||
]
|
||||
@@ -1,18 +0,0 @@
|
||||
# Generated by Django 3.2.7 on 2021-09-02 04:11
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('library', '0007_auto_20210902_1407'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='work',
|
||||
name='orchestration',
|
||||
field=models.CharField(blank=True, help_text='IMDB format instrumentation', max_length=255),
|
||||
),
|
||||
]
|
||||
+100
-214
@@ -5,162 +5,23 @@ from django.utils.text import slugify
|
||||
from django.utils.timezone import now
|
||||
from django.utils.functional import cached_property
|
||||
from django.core.files.storage import get_storage_class
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Count, Min, Max
|
||||
|
||||
import re
|
||||
from byostorage.user import BYOStorage
|
||||
from .imslp import Instrument
|
||||
|
||||
import logging
|
||||
|
||||
#from polyphonic.settings import LIBRARY_STORAGE
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
library_storage = get_storage_class(settings.LIBRARY_STORAGE)()
|
||||
except (ImportError, AttributeError):
|
||||
library_storage = get_storage_class()()
|
||||
logger.info("Library storage: %s", library_storage.__class__.__name__)
|
||||
#try:
|
||||
# library_storage = get_storage_class(settings.LIBRARY_STORAGE)()
|
||||
#except (ImportError, AttributeError):
|
||||
# logger.exception("Failed to load library storage")
|
||||
# library_storage = get_storage_class()()
|
||||
#logger.info("Library storage: %s", library_storage.__class__.__name__)
|
||||
|
||||
# taken from https://imslp.org/wiki/IMSLP:Abbreviations_for_Instruments
|
||||
ABBREVIATIONS = """
|
||||
score Score
|
||||
acc Accordion
|
||||
afl Alto flute
|
||||
alt Alto (voice) (contralto)
|
||||
arp Arpeggione
|
||||
bag Bagpipe
|
||||
bar Baritone (voice)
|
||||
bass Bass (voice)
|
||||
bbar Bass baritone (voice)
|
||||
bc Continuo (Basso continuo)
|
||||
bcl Bass clarinet
|
||||
bell Bell (Chimes)
|
||||
bfl Bass flute
|
||||
bgtr Bass guitar
|
||||
bjo Banjo
|
||||
bn Bassoon
|
||||
bob Bass oboe (Baritone oboe)
|
||||
br Brass instruments
|
||||
bryt Baryton
|
||||
bstcl Basset clarinet
|
||||
bsthn Basset horn
|
||||
bug Bugle
|
||||
cbcl Contrabass clarinet
|
||||
cbn Contrabassoon
|
||||
cch Children's chorus
|
||||
cel Celesta
|
||||
ch Mixed chorus
|
||||
cimb Cimbalom
|
||||
cit Cittern
|
||||
cl Clarinet
|
||||
clvd Clavichord
|
||||
cm Chalumeau
|
||||
conc Concertina
|
||||
crh Crumhorn
|
||||
crt Cornet
|
||||
crtt Cornett (Zink)
|
||||
cv Child's voice
|
||||
db Double Bass
|
||||
dlcn Dulcian
|
||||
dom Domra
|
||||
dulc Dulcimer
|
||||
egtr Electric guitar
|
||||
eh English horn (Cor anglais)
|
||||
elec Electronic Instruments
|
||||
epf Electric piano
|
||||
eq Equal voices
|
||||
erhu Erhu
|
||||
euph Euphonium
|
||||
fch Female chorus
|
||||
fda Flute d'amore (Tenor flute)
|
||||
fgh Flugelhorn
|
||||
fife Fife
|
||||
fl Flute
|
||||
flag Flageolet
|
||||
ghca Glass harmonica (Bowl organ)
|
||||
gl Glockenspiel
|
||||
gtr Guitar
|
||||
harm Harmonium
|
||||
hca Harmonica (Mouth Organ)
|
||||
heck Heckelphone
|
||||
hn Horn
|
||||
hp Harp
|
||||
hpd Harpsichord
|
||||
kbd Keyboard instrument
|
||||
lute Lute
|
||||
lyre Lyre
|
||||
mand Mandolin
|
||||
mar Marimba
|
||||
mch Male chorus
|
||||
mez Mezzo-soprano
|
||||
mus Musette
|
||||
nar Narrator (Reciter)
|
||||
ob Oboe
|
||||
oca Ocarina
|
||||
oda Oboe d'amore
|
||||
om Ondes Martenot
|
||||
oph Ophicleide
|
||||
orch Orchestra
|
||||
org Organ
|
||||
oud Oud
|
||||
pan Pan flute (Pan-pipes)
|
||||
perc Percussion
|
||||
pf Piano
|
||||
pf3h Piano 3 hands
|
||||
pf4h Piano 4 hands
|
||||
pf5h Piano 5 hands
|
||||
pf6h Piano 6 hands
|
||||
pflh Piano left hand
|
||||
pfped Pedal piano
|
||||
pfrh Piano right hand
|
||||
picc Piccolo
|
||||
pipa Pipa
|
||||
pk Timpani
|
||||
ptpt Piccolo trumpet
|
||||
reb Rebec
|
||||
rec Recorder
|
||||
sar Sarrusophone
|
||||
sax Saxophone
|
||||
sheng Sheng
|
||||
shw Shawm
|
||||
sit Sitar
|
||||
skbt Sackbut
|
||||
sop Soprano (voice)
|
||||
srp Serpent
|
||||
stpt Slide trumpet
|
||||
str String instruments
|
||||
sxh Saxhorn
|
||||
syn Synthesizer
|
||||
tba Tuba
|
||||
tbn Trombone
|
||||
ten Tenor
|
||||
thrm Theremin
|
||||
timp Timpani
|
||||
tpt Trumpet
|
||||
uch Unison chorus
|
||||
uke Ukelele (Ukulele)
|
||||
v Voice (solo)
|
||||
va Viola
|
||||
vap Viola pomposa
|
||||
vc Cello
|
||||
vda Viola d'amore
|
||||
vib Vibraphone
|
||||
vie Vielle (Hurdy-Gurdy)
|
||||
viol Viol (Viola da gamba)
|
||||
vlne Violone
|
||||
vn Violin
|
||||
vuv Vuvuzela
|
||||
vv Voices (multiple soloists)
|
||||
wag Wagner tuba
|
||||
ww Woodwind instruments
|
||||
xiao Xiao
|
||||
xyl Xylophone
|
||||
zith Zither
|
||||
"""
|
||||
|
||||
INSTRUMENTS = []
|
||||
for line in ABBREVIATIONS.split('\n'):
|
||||
parts = line.strip().split(maxsplit=1)
|
||||
if len(parts) < 2: continue
|
||||
name, _, _ = parts[1].partition('(')
|
||||
INSTRUMENTS.append((parts[0], name))
|
||||
|
||||
'''
|
||||
ORCHESTRATIONS = {
|
||||
@@ -194,12 +55,6 @@ ACCESS_TYPES = [
|
||||
(2, 'Approval required'),
|
||||
]
|
||||
|
||||
def tag_to_instrument(tag):
|
||||
m = re.match(r'([A-Za-z]+)(\d*)', tag)
|
||||
if not m:
|
||||
return tag
|
||||
l = m.groups()
|
||||
return "{0} {1}".format(dict(INSTRUMENTS).get(l[0],l[0]), l[1]).strip()
|
||||
|
||||
'''
|
||||
class Orchestration(models.Model):
|
||||
@@ -223,37 +78,44 @@ class Orchestration(models.Model):
|
||||
return self.name
|
||||
'''
|
||||
|
||||
class Item(models.Model):
|
||||
class ProjectItem(models.Model):
|
||||
"""
|
||||
Item represents a specic version of a Work in a Project e.g. item in set list or programme
|
||||
ProjectItem represents a Work attached to a Project e.g. item in set list or programme
|
||||
It also allows works to be shared from one ensemble to another on a per-project basis.
|
||||
"""
|
||||
project = models.ForeignKey('interface.Project', on_delete=models.CASCADE)
|
||||
project = models.ForeignKey('interface.Project', on_delete=models.CASCADE, related_name='items')
|
||||
work = models.ForeignKey('Work', on_delete=models.CASCADE, related_name='project_items')
|
||||
checkout = models.DateTimeField()
|
||||
due = models.DateTimeField(null=True, blank=True)
|
||||
returned = models.DateTimeField(null=True, blank=True)
|
||||
approved_by = models.ForeignKey('auth.User', on_delete=models.CASCADE)
|
||||
order = models.SmallIntegerField(default=0)
|
||||
version = models.CharField(max_length=30, blank=True, help_text="Limited to specific version tag")
|
||||
section = models.SlugField
|
||||
#version = models.CharField(max_length=30, blank=True, help_text="Limited to specific version tag")
|
||||
|
||||
class Meta:
|
||||
ordering = ['order', 'work']
|
||||
|
||||
def __str__(self):
|
||||
return f"<{self.project.slug}:{self.work.slug}>"
|
||||
return f"<{self.project_id}:{self.work.slug}>"
|
||||
|
||||
class Collection(models.Model):
|
||||
"""
|
||||
Storage location for works (physical or virtual)
|
||||
A logical collection of works, typically owned by an organisation or person (physical or virtual)
|
||||
"""
|
||||
name = models.CharField(max_length=255, help_text="Name of the collection")
|
||||
administrators = models.ManyToManyField('auth.User', related_name="collections", help_text="Administrators for this collection")
|
||||
location = models.CharField(max_length=100, help_text="Physical location (institution, town...)")
|
||||
storage = models.ForeignKey('byostorage.UserStorage', on_delete=models.CASCADE, null=True, blank=True, help_text="Storage for documents")
|
||||
notes = models.TextField(blank=True, help_text="Publicly visible notes about collection and loans policy")
|
||||
#ensembles = models.ManyToManyField('interface.Ensemble', related_name="collections", through='EnsembleAccess')
|
||||
|
||||
name = models.CharField(max_length=255,
|
||||
help_text="Name of the collection")
|
||||
prefix = models.SlugField(max_length=30, default="default",
|
||||
help_text="Folder to store works in")
|
||||
administrators = models.ManyToManyField('auth.User', related_name="collections",
|
||||
help_text="Administrators for this collection")
|
||||
location = models.CharField(max_length=100,
|
||||
help_text="Physical location (institution, town...)", blank=True)
|
||||
storage = models.ForeignKey('byostorage.UserStorage', on_delete=models.CASCADE, null=True, blank=True,
|
||||
help_text="User storage for documents")
|
||||
notes = models.TextField(blank=True,
|
||||
help_text="Publicly visible notes about collection and loans policy (markdown format)")
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@@ -268,61 +130,69 @@ class EnsembleAccess(models.Model):
|
||||
class Meta:
|
||||
verbose_name_plural = "Ensemble access"
|
||||
|
||||
META_TAGS = (
|
||||
('tag', 'Tag'),
|
||||
('arr', 'Arranger'),
|
||||
('lyrics', 'Lyracist'),
|
||||
('genre', 'Genre'),
|
||||
('style', 'Style'),
|
||||
('orchestration', 'Orchestration'),
|
||||
)
|
||||
|
||||
class Work(models.Model):
|
||||
"""
|
||||
A musical work 'owned' by a collection from a licencing perspective.
|
||||
"""
|
||||
collection = models.ForeignKey(Collection, on_delete=models.CASCADE, related_name="works", help_text="Owner")
|
||||
slug = models.SlugField(max_length=100, editable=False)
|
||||
name = models.CharField(max_length=255)
|
||||
edition = models.CharField(max_length=100, blank=True, help_text="Edition details")
|
||||
slug = models.SlugField(max_length=100, editable=False,
|
||||
help_text="Used as folder name")
|
||||
name = models.CharField(max_length=255, help_text="Original name of the work")
|
||||
edition = models.CharField(max_length=255, blank=True,
|
||||
help_text="Edition details to distinguish multiple versions")
|
||||
parent = models.ForeignKey('Work', null=True, blank=True, on_delete=models.SET_NULL, related_name="related_works",
|
||||
help_text="Arrangement of another work or part of an anthology")
|
||||
composer = models.CharField(max_length=255, blank=True, help_text="Use Composer / Arranger format")
|
||||
#orchestration = models.ForeignKey(Orchestration, null=True, on_delete=models.SET_NULL, related_name='works', blank=True)
|
||||
orchestration = models.CharField(max_length=255, blank=True, help_text="IMDB format instrumentation")
|
||||
parts = models.JSONField(null=True, blank=True)
|
||||
composer = models.CharField(max_length=255, blank=True,
|
||||
help_text="Surname, First Name/Initials")
|
||||
|
||||
original_parts = models.JSONField(default=dict, blank=True, help_text="Original printed parts (IMSLP format)")
|
||||
|
||||
# Collection details
|
||||
collection = models.ForeignKey(Collection, on_delete=models.CASCADE, related_name="works")
|
||||
code = models.CharField(max_length=100, blank=True, help_text="Collection specific code or number")
|
||||
licence = models.PositiveSmallIntegerField(choices=LICENCE_TYPES, default=6, help_text="Copyright status")
|
||||
max_loans = models.IntegerField(default=1, help_text="How many projects can this work be attached to")
|
||||
max_projects = models.IntegerField(default=1, help_text="How many active projects can this work be attached to")
|
||||
|
||||
# Extra info
|
||||
running_time = models.IntegerField(null=True, blank=True, help_text="Running time in seconds")
|
||||
running_time = models.DurationField(null=True, blank=True, help_text="Running time in seconds")
|
||||
notes = models.TextField(blank=True)
|
||||
tag_list = models.CharField(max_length=255, blank=True, help_text="Multiple tags for the work")
|
||||
|
||||
projects = models.ManyToManyField('interface.Project', through='Item', related_name="works", help_text="Current usage")
|
||||
|
||||
@property
|
||||
def duration(self):
|
||||
if self.running_time is None:
|
||||
return "-:--"
|
||||
return "{0:d}:{1:02d}".format(int(self.running_time / 60), self.running_time % 60)
|
||||
# Allocation to projects
|
||||
projects = models.ManyToManyField('interface.Project', through='ProjectItem', related_name="works", help_text="Current usage")
|
||||
|
||||
@property
|
||||
def tags(self):
|
||||
return self.tag_list.split(';') if self.tag_list else []
|
||||
def extract(self, *tags):
|
||||
|
||||
@tags.setter
|
||||
def set_tags(self, tags):
|
||||
self.tag_list = ";".join(tags)
|
||||
qs = self.docs.filter(sections__tag__in=tags)
|
||||
qs = qs.annotate(Count('sections'), end=Min('sections__end'), start=Max('sections__start')) \
|
||||
.filter(sections__count=len(tags))
|
||||
|
||||
return list(qs.values_list('upload', 'start', 'end'))
|
||||
|
||||
@property
|
||||
def digital_parts(self):
|
||||
return Part.objects.filter(doc__work=self.pk)
|
||||
return Section.objects.filter(doc__work=self.pk)
|
||||
|
||||
@property
|
||||
def physical_parts(self):
|
||||
if not self.parts:
|
||||
if not self.original_parts:
|
||||
return []
|
||||
return [ (tag_to_instrument(k), v) for (k, v) in self.parts.items() ]
|
||||
return [ (Instrument.from_tag(k), v) for (k, v) in self.original_parts.items() ]
|
||||
|
||||
#@property
|
||||
#def instruments(self):
|
||||
# return self.orchestration.as_list()
|
||||
@property
|
||||
def tags(self):
|
||||
return self.meta_info.filter(name='tag').values_list('value', flat=True)
|
||||
|
||||
@property
|
||||
def meta(self):
|
||||
return self.meta_info.exclude(name='tag')
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
@@ -346,30 +216,47 @@ class Work(models.Model):
|
||||
|
||||
@property
|
||||
def is_available(self):
|
||||
if self.max_loans < 0:
|
||||
if self.max_projects < 0:
|
||||
return True
|
||||
return self.max_loans > self.loans
|
||||
return self.max_projects > self.loans
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
if self.max_loans < 0:
|
||||
if self.max_projects < 0:
|
||||
return 'Unlimited'
|
||||
a = self.max_loans - self.loans
|
||||
return '{0} of {1}'.format(max(a, 0), self.max_loans)
|
||||
a = self.max_projects - self.loans
|
||||
return '{0} of {1}'.format(max(a, 0), self.max_projects)
|
||||
|
||||
@property
|
||||
def identifier(self):
|
||||
return f"{self.collection.pk:03d}-{self.pk:03d}"
|
||||
|
||||
if self.code:
|
||||
return self.code;
|
||||
|
||||
composer = self.composer or "Anon"
|
||||
words = self.name.split()
|
||||
if len(words) > 2:
|
||||
work = ''.join([ x[0] for x in self.name.split() ])
|
||||
else:
|
||||
work = words[0][:3]
|
||||
|
||||
return f"{composer[:4]}-{work}-{self.pk:03d}".upper()
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.composer})"
|
||||
|
||||
class WorkMeta(models.Model):
|
||||
work = models.ForeignKey(Work, on_delete=models.CASCADE, related_name='meta_info')
|
||||
name = models.SlugField(max_length=20, choices=META_TAGS)
|
||||
value = models.CharField(max_length=255)
|
||||
|
||||
def doc_upload_filename(doc, filename):
|
||||
storage = doc.work.collection.storage
|
||||
collection = doc.work.collection
|
||||
storage = collection.storage
|
||||
if not storage:
|
||||
raise RuntimeError("Collection has no storage attached")
|
||||
return f'{storage}:works/{doc.work.slug}-{doc.work.pk}/{filename}'
|
||||
return f'{storage}:library/{collection.prefix}/{doc.work.slug}-{doc.work.pk}/{filename}'
|
||||
|
||||
class Document(models.Model):
|
||||
"""
|
||||
@@ -377,29 +264,28 @@ class Document(models.Model):
|
||||
"""
|
||||
work = models.ForeignKey('Work', on_delete=models.CASCADE, related_name="docs")
|
||||
doctype = models.PositiveSmallIntegerField(choices=DOCTYPES, default=1)
|
||||
upload = models.FileField(upload_to=doc_upload_filename, storage=library_storage)
|
||||
upload = models.FileField(upload_to=doc_upload_filename, storage=BYOStorage())
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
version = models.CharField(max_length=30, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.upload.name
|
||||
|
||||
class Part(models.Model):
|
||||
class Section(models.Model):
|
||||
"""
|
||||
Part is a tagged portion of a Document
|
||||
Section is a tagged portion of a Document
|
||||
"""
|
||||
doc = models.ForeignKey(Document, on_delete=models.CASCADE, related_name="parts")
|
||||
tag = models.SlugField(max_length=20)
|
||||
doc = models.ForeignKey(Document, on_delete=models.CASCADE, related_name="sections")
|
||||
tag = models.CharField(max_length=50)
|
||||
start = models.SmallIntegerField(null=True, blank=True)
|
||||
end = models.SmallIntegerField(null=True, blank=True)
|
||||
notes = models.TextField(blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['doc', 'start', 'pk']
|
||||
|
||||
@property
|
||||
def instrument(self):
|
||||
return tag_to_instrument(self.tag)
|
||||
return Instrument.from_tag(self.tag)
|
||||
|
||||
@property
|
||||
def filename(self):
|
||||
|
||||
@@ -1,57 +1,131 @@
|
||||
{% extends "interface/project_base.html" %}
|
||||
|
||||
{% block admin %}
|
||||
<a href="#" onclick="saveTags()"><i class="fas fa-save"></i> Save</a>
|
||||
<a href="#" onclick="saveTags()" class="button is-link">
|
||||
<span class="icon"><i class="fas fa-save"></i></span>
|
||||
<span>Save</span>
|
||||
</a>
|
||||
<a href="{% url 'work_detail' pk=object.work.pk %}" class="button is-link is-light">
|
||||
<span>Cancel</span>
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block media %}
|
||||
<style>
|
||||
.tag-grid {
|
||||
display: flex;
|
||||
}
|
||||
.grid-column {
|
||||
margin-left: 1em;
|
||||
margin-right: 1em;
|
||||
}
|
||||
.grid-page {
|
||||
height: 25px;
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid #999;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
width: 50px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.grid-page.is-active {
|
||||
background-color: var(--primary);
|
||||
color: white;
|
||||
}
|
||||
.grid-tag {
|
||||
border: 2px solid var(--primary);
|
||||
background-color: rgba(240, 240, 240, 0.5);
|
||||
border-radius: 5px;
|
||||
padding-left: 1em;
|
||||
padding-right: 1em;
|
||||
margin-bottom: 5px;
|
||||
min-width: 200px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
#tag-area {
|
||||
min-width: 220px;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<h2><a href="{% url 'work_list' %}">Works</a> / <a href="{% url 'work_detail' document.work.pk %}">{{ document.work.name }}</a></h2>
|
||||
<div id="annotation-area">
|
||||
<div style="display: flex">
|
||||
<canvas id="inline-viewer" style="width: 600px;"></canvas>
|
||||
<div style="margin: 0px 20px">
|
||||
<div>
|
||||
<div style="text-align: center;">
|
||||
<p>Page: <span id="page_num"></span> / <span id="page_count"></span></p>
|
||||
</div>
|
||||
<button id="prev"><i class="fas fa-backward"></i></button>
|
||||
<button id="next"><i class="fas fa-forward"></i></button>
|
||||
</div>
|
||||
<div id="tag-list" style="cursor: pointer; margin-top: 20px;">
|
||||
<div id="tag-None" data-tag="None">No tag</div>
|
||||
<div id="tag-Score" data-tag="Score">Score</div>
|
||||
{% for instrument in document.work.instruments %}
|
||||
<div id="tag-{{ instrument.0 }}" data-tag="{{ instrument.0 }}">{{ instrument.1 }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<h3 class="subtitle"><a href="{% url 'work_detail' document.work.pk %}">{{ document.work.name }}</a></h3>
|
||||
<div id="annotation-area" class="columns is-centered">
|
||||
<div class="column is-narrow">
|
||||
<div class="has-text-centered">
|
||||
<div class="level">
|
||||
<div class="level-left">
|
||||
<div class="level-item">
|
||||
<p>Page <span id="page-num">-</span> / <span id="page-count">-</span></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-right">
|
||||
<div class="level-item">
|
||||
<div class="field has-addons">
|
||||
<span class="control">
|
||||
<input type="text" class="input" list="instrument-list" id="add-instrument-name"/>
|
||||
<datalist id="instrument-list">
|
||||
{% for inst in json_data.instruments.values %}
|
||||
<option value="{{inst}}"/>
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
</span>
|
||||
<span class="control">
|
||||
<input type="number" class="input" max="4" min="1" size="3" id="add-instrument-variant"/>
|
||||
</span>
|
||||
<span class="control">
|
||||
<button class="button is-primary" onclick="addInstrument()">Add</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box" style="display: inline-block;">
|
||||
<canvas id="inline-viewer" style="width: 500px;"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
|
||||
<div class="tag-grid">
|
||||
<div class="grid-column" id="page-list">
|
||||
</div>
|
||||
<div class="grid-column" id="tag-area">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<p>{{ document.upload.name }}</p>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.7.570/pdf.min.js" integrity="sha512-g4FwCPWM/fZB1Eie86ZwKjOP+yBIxSBM/b2gQAiSVqCgkyvZ0XxYPDEcN2qqaKKEvK6a05+IPL1raO96RrhYDQ==" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.7.570/pdf.min.js"
|
||||
integrity="sha512-g4FwCPWM/fZB1Eie86ZwKjOP+yBIxSBM/b2gQAiSVqCgkyvZ0XxYPDEcN2qqaKKEvK6a05+IPL1raO96RrhYDQ=="
|
||||
crossorigin="anonymous"></script>
|
||||
{{ json_data|json_script:"data" }}
|
||||
<script type="text/javascript">
|
||||
let url = "{{ document.upload.url|safe }}";
|
||||
let url = "{{ document.upload.url|safe }}";
|
||||
|
||||
// Loaded via <script> tag, create shortcut to access PDF.js exports.
|
||||
let pdfjsLib = window['pdfjs-dist/build/pdf'];
|
||||
// Loaded via <script> tag, create shortcut to access PDF.js exports.
|
||||
let pdfjsLib = window['pdfjs-dist/build/pdf'];
|
||||
|
||||
// The workerSrc property shall be specified.
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.7.570/pdf.worker.min.js';
|
||||
// The workerSrc property shall be specified.
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.7.570/pdf.worker.min.js';
|
||||
|
||||
// get current page tags
|
||||
let data = JSON.parse(document.getElementById('data').textContent);
|
||||
let currentTags = document.getElementById('current-tags');
|
||||
var selectedTag = document.getElementById('tag-None');
|
||||
var dirty = false;
|
||||
// get current page tags
|
||||
let data = JSON.parse(document.getElementById('data').textContent);
|
||||
let tagArea = document.getElementById('tag-area');
|
||||
var dirty = false;
|
||||
|
||||
document.getElementById('tag-list').onclick = (e) => setTag(e.target.dataset.tag);
|
||||
//document.getElementById('tag-list').onclick = (e) => setTag(e.target.dataset.tag);
|
||||
|
||||
var pdfDoc = null,
|
||||
var pdfDoc = null,
|
||||
pageNum = 1,
|
||||
pageRendering = false,
|
||||
pageNumPending = null,
|
||||
@@ -59,135 +133,257 @@ var pdfDoc = null,
|
||||
canvas = document.getElementById('inline-viewer'),
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
/**
|
||||
* Get page info from document, resize canvas accordingly, and render page.
|
||||
* @param num Page number.
|
||||
*/
|
||||
function renderPage(num) {
|
||||
pageRendering = true;
|
||||
// Using promise to fetch the page
|
||||
pdfDoc.getPage(num).then(function(page) {
|
||||
var viewport = page.getViewport({scale: scale});
|
||||
canvas.height = viewport.height;
|
||||
canvas.width = viewport.width;
|
||||
/**
|
||||
* Get page info from document, resize canvas accordingly, and render page.
|
||||
* @param num Page number.
|
||||
*/
|
||||
function renderPage(num) {
|
||||
pageRendering = true;
|
||||
// Using promise to fetch the page
|
||||
pdfDoc.getPage(num).then(function (page) {
|
||||
var viewport = page.getViewport({ scale: scale });
|
||||
canvas.height = viewport.height;
|
||||
canvas.width = viewport.width;
|
||||
|
||||
// Render PDF page into canvas context
|
||||
var renderContext = {
|
||||
canvasContext: ctx,
|
||||
viewport: viewport
|
||||
};
|
||||
var renderTask = page.render(renderContext);
|
||||
// Render PDF page into canvas context
|
||||
var renderContext = {
|
||||
canvasContext: ctx,
|
||||
viewport: viewport
|
||||
};
|
||||
var renderTask = page.render(renderContext);
|
||||
|
||||
// Wait for rendering to finish
|
||||
renderTask.promise.then(function() {
|
||||
pageRendering = false;
|
||||
if (pageNumPending !== null) {
|
||||
// New page rendering is pending
|
||||
renderPage(pageNumPending);
|
||||
pageNumPending = null;
|
||||
}
|
||||
try {
|
||||
document.getElementById('grid-page-' + pageNum).classList.remove('is-active');
|
||||
} catch(e) {}
|
||||
|
||||
pageNum = num;
|
||||
document.getElementById('grid-page-' + pageNum).classList.add('is-active');
|
||||
|
||||
// Wait for rendering to finish
|
||||
renderTask.promise.then(function () {
|
||||
pageRendering = false;
|
||||
if (pageNumPending !== null) {
|
||||
// New page rendering is pending
|
||||
renderPage(pageNumPending);
|
||||
pageNumPending = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Update page counters
|
||||
document.getElementById('page-num').textContent = num;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If another page rendering in progress, waits until the rendering is
|
||||
* finised. Otherwise, executes rendering immediately.
|
||||
*/
|
||||
function queueRenderPage(num) {
|
||||
if (pageRendering) {
|
||||
pageNumPending = num;
|
||||
} else {
|
||||
renderPage(num);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays previous page.
|
||||
*/
|
||||
function onPrevPage() {
|
||||
if (pageNum <= 1) {
|
||||
return;
|
||||
}
|
||||
pageNum--;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
//document.getElementById('prev').addEventListener('click', onPrevPage);
|
||||
|
||||
/**
|
||||
* Displays next page.
|
||||
*/
|
||||
function onNextPage() {
|
||||
if (pageNum >= pdfDoc.numPages) {
|
||||
return;
|
||||
}
|
||||
pageNum++;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
//document.getElementById('next').addEventListener('click', onNextPage);
|
||||
|
||||
/**
|
||||
* Asynchronously downloads PDF.
|
||||
*/
|
||||
pdfjsLib.getDocument(url).promise.then(function (pdfDoc_) {
|
||||
pdfDoc = pdfDoc_;
|
||||
|
||||
const pageList = document.getElementById('page-list');
|
||||
pageList.innerHTML = '';
|
||||
for (var i=0; i<pdfDoc.numPages; i++) {
|
||||
let page = i+1;
|
||||
let el = document.createElement('div');
|
||||
el.className = 'grid-page';
|
||||
el.id = 'grid-page-' + page;
|
||||
el.innerHTML = page;
|
||||
el.addEventListener('click', (evt) => {
|
||||
queueRenderPage(page);
|
||||
});
|
||||
pageList.appendChild(el);
|
||||
}
|
||||
|
||||
document.getElementById('page-count').textContent = pdfDoc.numPages;
|
||||
|
||||
// Initial/first page rendering
|
||||
renderPage(pageNum);
|
||||
|
||||
tagArea.innerHTML = '';
|
||||
for (let pageTag of data.pageTags) {
|
||||
addTag(pageTag[0], pageTag[1], pageTag[2]);
|
||||
}
|
||||
dirty = false;
|
||||
});
|
||||
|
||||
// Update page counters
|
||||
document.getElementById('page_num').textContent = num;
|
||||
function addInstrument() {
|
||||
let name = document.getElementById('add-instrument-name');
|
||||
let variant = document.getElementById('add-instrument-variant');
|
||||
|
||||
// get the page tags
|
||||
let tag = data.pageTags[num];
|
||||
if(tag) {
|
||||
selectTag(tag);
|
||||
} else {
|
||||
if (selectedTag) {
|
||||
setTag(selectedTag.dataset.tag);
|
||||
let inst_name = name.value;
|
||||
var tag = null;
|
||||
for (let key in data.instruments) {
|
||||
if (data.instruments[key] == inst_name) {
|
||||
tag = key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tag) {
|
||||
alert("Unknown tag: " + name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (variant.value) {
|
||||
tag += "-" + variant.value;
|
||||
}
|
||||
|
||||
variant.value = '';
|
||||
name.value = '';
|
||||
|
||||
addTag(tag, pageNum, pageNum);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If another page rendering in progress, waits until the rendering is
|
||||
* finised. Otherwise, executes rendering immediately.
|
||||
*/
|
||||
function queueRenderPage(num) {
|
||||
if (pageRendering) {
|
||||
pageNumPending = num;
|
||||
} else {
|
||||
renderPage(num);
|
||||
function addTag(tag, start, end) {
|
||||
console.log("addTag", tag, start, end);
|
||||
const el = document.createElement('div');
|
||||
el.className = 'grid-tag';
|
||||
el.dataset.tag = tag;
|
||||
el.dataset.start = start;
|
||||
el.dataset.end = end;
|
||||
|
||||
let setStart = document.createElement('span');
|
||||
setStart.className = "icon is-action";
|
||||
setStart.innerHTML = '<i class="fas fa-sort-amount-down" title="Set start page"></i>';
|
||||
setStart.addEventListener('click', () => setTagStart(el));
|
||||
el.appendChild(setStart);
|
||||
|
||||
|
||||
let label = document.createElement('span');
|
||||
|
||||
let name = document.createElement('b');
|
||||
name.innerHTML = get_instrument(tag);
|
||||
label.appendChild(name);
|
||||
|
||||
let del = document.createElement('span');
|
||||
del.className = "icon is-action";
|
||||
del.innerHTML = '<i class="fas fa-trash-alt" title="Remove this tag"></i>';
|
||||
del.addEventListener('click', () => {el.remove(), dirty=true});
|
||||
label.appendChild(del)
|
||||
|
||||
el.appendChild(label);
|
||||
|
||||
|
||||
let setEnd = document.createElement('span');
|
||||
setEnd.className = "icon is-action";
|
||||
setEnd.innerHTML = '<i class="fas fa-sort-amount-up" title="Set end page"></i>';
|
||||
setEnd.addEventListener('click', () => setTagEnd(el));
|
||||
el.appendChild(setEnd);
|
||||
|
||||
updateTag(el);
|
||||
tagArea.appendChild(el);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays previous page.
|
||||
*/
|
||||
function onPrevPage() {
|
||||
if (pageNum <= 1) {
|
||||
return;
|
||||
}
|
||||
pageNum--;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
document.getElementById('prev').addEventListener('click', onPrevPage);
|
||||
|
||||
/**
|
||||
* Displays next page.
|
||||
*/
|
||||
function onNextPage() {
|
||||
if (pageNum >= pdfDoc.numPages) {
|
||||
return;
|
||||
}
|
||||
pageNum++;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
document.getElementById('next').addEventListener('click', onNextPage);
|
||||
|
||||
/**
|
||||
* Asynchronously downloads PDF.
|
||||
*/
|
||||
pdfjsLib.getDocument(url).promise.then(function(pdfDoc_) {
|
||||
pdfDoc = pdfDoc_;
|
||||
document.getElementById('page_count').textContent = pdfDoc.numPages;
|
||||
|
||||
// Initial/first page rendering
|
||||
renderPage(pageNum);
|
||||
});
|
||||
|
||||
function setTag(tag) {
|
||||
data.pageTags[pageNum] = tag;
|
||||
function updateTag(tag) {
|
||||
let start = tag.dataset.start;
|
||||
let end = tag.dataset.end;
|
||||
let span = end-start+1;
|
||||
let height = span * 25 + (span-1) * 10;
|
||||
let top = (start-1) * 35;
|
||||
|
||||
tag.style.height = height + 'px';
|
||||
tag.style.marginTop = top + 'px';
|
||||
dirty = true;
|
||||
selectTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
function selectTag(tag) {
|
||||
if( selectedTag ) {
|
||||
selectedTag.classList.remove('selected');
|
||||
function setTagStart(el) {
|
||||
if (pageNum > el.dataset.end) {
|
||||
alert("Select the first page and click extend");
|
||||
return;
|
||||
}
|
||||
selectedTag = document.getElementById('tag-' + tag);
|
||||
if( selectedTag) {
|
||||
selectedTag.classList.add('selected');
|
||||
el.dataset.start = pageNum;
|
||||
updateTag(el);
|
||||
}
|
||||
|
||||
function setTagEnd(el) {
|
||||
if (pageNum < el.dataset.start) {
|
||||
alert("Select the last page and click extend");
|
||||
return;
|
||||
}
|
||||
}
|
||||
el.dataset.end = pageNum;
|
||||
updateTag(el);
|
||||
}
|
||||
|
||||
function saveTags() {
|
||||
console.log(data.pageTags);
|
||||
function saveTags() {
|
||||
const pageTags = [];
|
||||
for (let pageTag of tagArea.children ) {
|
||||
let start = pageTag.dataset.start;
|
||||
let end = pageTag.dataset.end;
|
||||
if (start == 1 && end == pdfDoc.numPages) {
|
||||
start = null;
|
||||
end = null;
|
||||
}
|
||||
pageTags.push([pageTag.dataset.tag, start, end])
|
||||
}
|
||||
|
||||
console.log(pageTags);
|
||||
fetch("", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json", "X-CSRFToken": "{{ csrf_token }}"},
|
||||
body: JSON.stringify(data.pageTags)}
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", "X-CSRFToken": "{{ csrf_token }}" },
|
||||
body: JSON.stringify(pageTags)
|
||||
}
|
||||
).then((response) => {
|
||||
if(response.ok) {
|
||||
window.location = "{% url 'work_detail' document.work.pk %}"
|
||||
} else {
|
||||
alert("Failed: " + response.statusText)
|
||||
}
|
||||
if (response.ok) {
|
||||
window.location = "{% url 'work_detail' document.work.pk %}"
|
||||
} else {
|
||||
alert("Failed: " + response.statusText)
|
||||
}
|
||||
});
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
function checkSaved(e) {
|
||||
if (dirty) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
window.addEventListener('beforeunload', checkSaved);
|
||||
|
||||
function get_instrument(s) {
|
||||
let parts = s.split('-');
|
||||
let instrument = data.instruments[parts[0]];
|
||||
if (parts.length == 2) {
|
||||
return instrument + " " + parts[1];
|
||||
}
|
||||
return instrument;
|
||||
}
|
||||
|
||||
function checkSaved(e) {
|
||||
if (dirty) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
window.addEventListener('beforeunload', checkSaved);
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,34 +1,60 @@
|
||||
{% extends "interface/project_base.html" %}
|
||||
|
||||
{% block admin %}
|
||||
<a href="{% url 'item_list_manage' project.pk %}"><i class="fas fa-list"></i><span class="smhide admin"> Change items</span></a>
|
||||
<a class="button is-link" href="{% url 'item_list_manage' project.pk %}">
|
||||
<span class="icon"><i class="fas fa-list"></i></span>
|
||||
<span>Change items</span>
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<p>
|
||||
This page lets you download a complete set of music for your part by selecting your instrument
|
||||
and optionally a part (e.g. Flute 1 or 2).<br/>
|
||||
You can also tweak which parts you get for each piece, or click on a piece for more download options.
|
||||
</p>
|
||||
<form action="" method="post" target="_blank" style="display: flex;">
|
||||
<form action="" method="post" target="_blank">
|
||||
{% csrf_token %}
|
||||
<div style="margin: 0px 20px; text-align: right;">
|
||||
<label for="instrument-select">Pick your instrument</label>
|
||||
<select id="instrument-select" name="instrument" onchange="updateParts()">
|
||||
{% for tag, instrument in instruments %}
|
||||
<option value="{{ tag }}">{{ instrument }}</option>
|
||||
{% endfor %}
|
||||
</select><br/><br/>
|
||||
<label for="part-preference">Part preference</label>
|
||||
<input id="part-preference" name="part" type="number" value="0" min="0" max="4" onchange="updateParts()" size="1"/><br/><br/>
|
||||
<button type="submit" style="height: 32px;"><i class="fas fa-copy"></i> Get My Parts!</button>
|
||||
<div>
|
||||
<div class="field is-grouped is-grouped-centered">
|
||||
<div class="field has-addons control">
|
||||
|
||||
<span class="control">
|
||||
<a class="button is-static">Your Instrument</a>
|
||||
</span>
|
||||
|
||||
<span class="control">
|
||||
<input type="text" class="input" list="instrument-list" id="instrument-name" onchange="updateParts()"/>
|
||||
<datalist id="instrument-list">
|
||||
{% for inst in instruments %}
|
||||
<option value="{{inst.1}}"/>
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
</span>
|
||||
<span class="control">
|
||||
<span class="select" onchange="updateParts()">
|
||||
<select id="part-preference">
|
||||
<option value="0">Any</option>
|
||||
<option value="1">1st</option>
|
||||
<option value="2">2nd</option>
|
||||
<option value="3">3rd</option>
|
||||
<option value="4">4th</option>
|
||||
</select>
|
||||
</span>
|
||||
</span>
|
||||
</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>
|
||||
<table style="max-width: 600px; margin: 10pt auto;" class="zebra">
|
||||
|
||||
<table class="table is-striped is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th/>
|
||||
<th>Piece</th>
|
||||
<th>Running time</th>
|
||||
<th>Part</th>
|
||||
<th/>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -36,33 +62,79 @@
|
||||
<tr>
|
||||
<td>{{ forloop.counter }}.</td>
|
||||
<td>
|
||||
{% if request.is_admin %}
|
||||
<a href="{% url 'work_detail' item.work.pk %}">{{ item.work.name }}</a>
|
||||
{% else %}
|
||||
{{ item.work.name }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{% firstof item.work.running_time "------" %}</td>
|
||||
<td class="select-cell">
|
||||
<input type="hidden" name="works" value="{{ item.work.pk }}"/>
|
||||
<span class="select is-small">
|
||||
<select name="instruments">
|
||||
<option value='-'>None</option>
|
||||
{% for part in item.work.parts %}
|
||||
{% for part in item.work.digital_parts %}
|
||||
<option value='{{ part.tag }}'>{{ part.instrument }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<a href=""><i class="fas fa-download"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td/>
|
||||
<td/>
|
||||
<td>{{ running_time }}</td>
|
||||
<td/>
|
||||
<td>
|
||||
<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>
|
||||
<a class="button is-link is-small"><span class="icon"><i class="fas fa-archive"></i></span><span>Individual files (zipped)</span></a>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<p class="content">
|
||||
This page lets you download a complete set of music for your part by selecting your instrument
|
||||
and optionally a part (e.g. Flute 1 or 2).<br/>
|
||||
You can also tweak which parts you get for each piece, or click on a piece for more download options.
|
||||
</p>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
{{ instruments|json_script:'instruments' }}
|
||||
<script type="text/javascript">
|
||||
|
||||
const INSTRUMENTS = JSON.parse(document.getElementById('instruments').innerText);
|
||||
|
||||
function updateParts() {
|
||||
let inst = document.getElementById("instrument-select").value;
|
||||
var inst = document.getElementById("instrument-name").value;
|
||||
window.localStorage.setItem('instrument-name', inst);
|
||||
|
||||
for (let i of INSTRUMENTS) {
|
||||
if (i[1] === inst) inst = i[0];
|
||||
}
|
||||
|
||||
|
||||
let part = document.getElementById("part-preference").value;
|
||||
let prefix = inst + part;
|
||||
|
||||
window.localStorage.setItem('part-preference', part);
|
||||
|
||||
|
||||
selectParts(inst, part);
|
||||
|
||||
}
|
||||
|
||||
function selectParts(inst, part) {
|
||||
|
||||
let prefix = inst + "-" + part;
|
||||
|
||||
let instruments = document.getElementsByName("instruments");
|
||||
for(let i=0; i<instruments.length; i++) {
|
||||
var result = "-"
|
||||
@@ -82,9 +154,10 @@ function updateParts() {
|
||||
|
||||
}
|
||||
|
||||
document.getElementById("instrument-select").value="{{instrument}}";
|
||||
document.getElementById("part-preference").value="{{part}}";
|
||||
document.getElementById("instrument-name").value = localStorage.getItem('instrument-name', 'All');
|
||||
document.getElementById("part-preference").value = localStorage.getItem('part-preference', 'Any');
|
||||
updateParts();
|
||||
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,8 +1,14 @@
|
||||
{% extends "interface/project_base.html" %}
|
||||
|
||||
{% block admin %}
|
||||
<a href="#" onclick="save()"><i class="fas fa-save"></i><span class="smhide action">Save</span></a>
|
||||
<a href="{% url 'item_list_append' project.pk %}"><i class="fas fa-plus-circle"></i><span class="smhide action">Add</a></a>
|
||||
<a href="{% url 'item_list_append' project.pk %}" class="button is-link">
|
||||
<span class="icon"><i class="fas fa-plus-circle"></i></span>
|
||||
<span>Add</span>
|
||||
</a>
|
||||
<a href="#" onclick="save()" class="button is-link">
|
||||
<span class="icon"><i class="fas fa-save"></i></span>
|
||||
<span>Save</span>
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
|
||||
@@ -1 +1,12 @@
|
||||
<p>Click the '<a href="{% url 'item_list' project=project.pk %}">My Music</a>' button below to access your parts...</p>
|
||||
{% with project.items.count as items %}
|
||||
{% if items %}
|
||||
<p>
|
||||
There {{ items|pluralize:"is,are" }} currently {{ items}} item{{ items|pluralize }} for this project.<br/>
|
||||
Click the '<a href="{% url 'item_list' project=project.pk %}">My Music</a>' button below to access your parts...
|
||||
</p>
|
||||
{% else %}
|
||||
<p>
|
||||
There are no items listed yet for this project - please check back later...
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
@@ -1,6 +1,9 @@
|
||||
<p class='menu-label'>Library</p>
|
||||
<ul class="menu-list">
|
||||
{% if project %}
|
||||
<a href="{% url 'item_list' project=project.pk %}">My Music</a>
|
||||
<li><a href="{% url 'item_list' project=project.pk %}">My Music</a></li>
|
||||
{% endif %}
|
||||
{% if request.is_admin %}
|
||||
<a href="{% url 'work_list' %}">Library</a>
|
||||
{% endif %}
|
||||
<li><a href="{% url 'work_list' %}">Library</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
@@ -1,93 +1,211 @@
|
||||
{% extends 'interface/project_base.html' %}
|
||||
{% load path_filters %}
|
||||
|
||||
{% block media %}
|
||||
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
|
||||
<link rel="stylesheet" href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" type="text/css" />
|
||||
{% endblock %}
|
||||
|
||||
{% block admin %}
|
||||
<a href="{% url 'document_add' work.pk %}"><i class="fas fa-plus-circle"></i> Upload file</a>
|
||||
<a href="{% url 'work_edit' work.pk %}" class="button is-link">
|
||||
<span class="icon"><i class="fas fa-edit"></i></span>
|
||||
<span>Edit</span>
|
||||
</a>
|
||||
<a href="{% url 'work_add_to_project' work.pk %}" class="button is-link">
|
||||
<span class="icon"><i class="fas fa-plus-circle"></i></span>
|
||||
<span>Add to project</span>
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<h2>{{ work.name }} {% if work.running_time %}({{ work.duration }}){% endif %} <small>[{{ work.identifier }}]</small></h2>
|
||||
<h4>{{ work.composer }}{% if work.version %} - {{ work.version }}{% endif %}</h4>
|
||||
<p>{{ work.notes }}</p>
|
||||
{% if work.collection %}
|
||||
<p>Location: {{ work.collection }} [{{ work.collection_index }}]</p>
|
||||
{% endif %}
|
||||
|
||||
{% if work.parent %}
|
||||
<p>From <a href="{% url 'work_detail' work.parent.pk %}">{{ work.parent.name }} - {{ work.parent.composer }}</a></p>
|
||||
{% endif %}
|
||||
|
||||
{% if work.related_works.count %}
|
||||
<h3>Related</h3>
|
||||
<ul>
|
||||
{% for related in work.related_works.all %}
|
||||
<li><a href="{% url 'work_detail' related.pk %}">{{ related.name }} - {{ related.composer }}</a></li>
|
||||
<h3 class="title">
|
||||
{{ work.name }}
|
||||
{% for tag in work.tags %}
|
||||
<span class="tag is-success">{{ tag }}</span>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</h3>
|
||||
<p class="subtitle">{% firstof work.composer "Unattributed" %}{% if work.edition %} - {{ work.edition }}{% endif %}</p>
|
||||
<section class="block">
|
||||
<p class="block">{{ work.notes }}</p>
|
||||
|
||||
<h4>Loans
|
||||
<p class="block">
|
||||
Location: <a href="{% url 'collection_work_list' work.collection.pk %}">{{ work.collection }}</a> [{{ work.identifier }}]<br/>
|
||||
Running time: {{ work.duration }}<br/>
|
||||
Licence: {{ work.get_licence_display }}<br/>
|
||||
{% for meta in work.meta %}
|
||||
{{ meta.get_name_display }}: {{ meta.value }}<br/>
|
||||
{% endfor %}
|
||||
</p>
|
||||
|
||||
{% if work.parent %}
|
||||
<p>From <a href="{% url 'work_detail' work.parent.pk %}">{{ work.parent.name }} - {{ work.parent.composer }}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if work.related_works.count %}
|
||||
<h3>Related</h3>
|
||||
<ul>
|
||||
{% for related in work.related_works.all %}
|
||||
<li><a href="{% url 'work_detail' related.pk %}">{{ related.name }} - {{ related.composer }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</section>
|
||||
<section class="block">
|
||||
|
||||
<div class="columns">
|
||||
<div class="column is-half">
|
||||
<div class="box">
|
||||
<h4 class="subtitle is-size-4">
|
||||
<span class="icon"><i class="fas fa-book"></i></span>
|
||||
Printed Parts
|
||||
</h4>
|
||||
<div class="tags">
|
||||
{% for inst, c in work.physical_parts %}
|
||||
<span class="tag is-warning">{{ inst }} ({{ c }})</span>
|
||||
{% empty %}
|
||||
<p class="is-italic">No printed parts listed</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-half">
|
||||
<div class="box">
|
||||
<h4 class="subtitle is-size-4">
|
||||
<span class="icon"><i class="fas fa-print"></i></span>
|
||||
Digital Parts
|
||||
</h4>
|
||||
<div class="tags">
|
||||
{% if work.digital_parts %}
|
||||
<a class="tag is-danger" href="{% url 'work_partset' pk=work.pk %}">Full Set</a>
|
||||
{% endif %}
|
||||
{% for part in work.digital_parts %}
|
||||
<a class="tag is-info" href="{% url 'part_download' pk=part.pk filename=part.filename %}"
|
||||
target="part_{{ part.pk }}" rel="">{{ part.instrument }}</a>
|
||||
{% empty %}
|
||||
<p class="is-italic">No digital parts available</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="block">
|
||||
<div class="box">
|
||||
<div class="level">
|
||||
<h4 class="subtitle is-size-4">
|
||||
<span class="icon"><i class="fas fa-file"></i></span>
|
||||
Files
|
||||
</h4>
|
||||
</div>
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<table class="table is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filename</th>
|
||||
<th>Sections</th>
|
||||
<th/>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="doc-list">
|
||||
{% for doc in work.docs.all %}
|
||||
<tr>
|
||||
<td><a href="{% url 'document_download' pk=doc.pk %}" target="_blank">
|
||||
{{ doc.upload.name|basename }}</a></td>
|
||||
<td>
|
||||
{% for part in doc.sections.all %}
|
||||
<a class="tag is-info" href="{% url 'part_download' pk=part.pk filename=part.filename %}">{{ part.instrument }}</a>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="has-text-right">
|
||||
{% if request.is_admin %}
|
||||
<a href="{% url 'document_annotate' pk=doc.pk %}"><i class="fas fa-tags"
|
||||
title="Manage Tags"></i></a>
|
||||
<a href=""><i class="fas fa-trash-alt" title="Delete Document"></i></a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% if request.is_admin %}
|
||||
<div class="column is-one-quarter">
|
||||
<h4 class="is-size-5">Upload files</h4>
|
||||
<form action="{% url 'document_add' object.pk %}" class="dropzone" id="doc-upload">
|
||||
{% csrf_token %}
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% if request.is_admin %}
|
||||
<a href="{% url 'work_add_to_project' work.pk %}"><i class="fas fa-plus-circle"></i></a>
|
||||
<section class="block">
|
||||
<div class="box">
|
||||
<div class="level">
|
||||
<h4 class="is-size-4">
|
||||
<span class="icon"><i class="fas fa-book-reader"></i></span>
|
||||
Loans
|
||||
</h4>
|
||||
<span class="level-right">
|
||||
<a class="icon-text" href="{% url 'work_add_to_project' work.pk %}"><span class="icon"><i
|
||||
class="fas fa-plus-circle"></i></span> Checkout</a>
|
||||
</span>
|
||||
</div>
|
||||
<table class="table is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Ensemble</th>
|
||||
<th>Project</th>
|
||||
<th>Checked Out</th>
|
||||
<th>Due Back</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in work.current_loans %}
|
||||
<tr>
|
||||
<td><a href="{% url 'ensemble_detail' item.project.ensemble_id %}">
|
||||
{{ item.project.ensemble.name }}
|
||||
</a></td>
|
||||
<td><a href="{% url 'project_detail' item.project.pk %}">{{ item.project.name }}</a></td>
|
||||
<td>{{ item.checkout.date|date:"d/m/Y" }}</td>
|
||||
<td>{{ item.due.date|date:"d/m/Y" }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td>No current loans</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
</h4>
|
||||
<table style="margin: 10px auto">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Ensemble</th>
|
||||
<th>Project</th>
|
||||
<th>Checked Out</th>
|
||||
<th>Due Back</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in work.current_loans %}
|
||||
<tr>
|
||||
<td><a href="{% url 'ensemble_detail' item.project.ensemble_id %}">{{ item.project.ensemble.name }}</a></td>
|
||||
<td><a href="{% url 'project_detail' item.project.pk %}">{{ item.project.name }}</a></td>
|
||||
<td>{{ item.checkout.date|date:"d/m/Y" }}</td>
|
||||
<td>{{ item.due.date|date:"d/m/Y" }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr><td>No current loans</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h4>Printed Parts</h4>
|
||||
<p>
|
||||
{% for inst, c in work.physical_parts %}
|
||||
<span class="badge">{{ inst }} ({{ c }})</span>
|
||||
{% empty %}
|
||||
No physical parts available
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% block scripts %}
|
||||
<script>
|
||||
Dropzone.options.docUpload = { // camelized version of the `id`
|
||||
paramName: "upload", // The name that will be used to transfer the file
|
||||
maxFilesize: 12, // MB
|
||||
createImageThumbnails: false,
|
||||
thumbnailWidth: 60,
|
||||
thumbnailHeight: 60,
|
||||
init: function () {
|
||||
this.on("complete", file => {
|
||||
console.log(file);
|
||||
let data = JSON.parse(file.xhr.response);
|
||||
console.log(data);
|
||||
let tbody = document.getElementById('doc-list');
|
||||
let tr = document.createElement('tr');
|
||||
tr.innerHTML = data.entry;
|
||||
tbody.appendChild(tr);
|
||||
this.removeFile(file);
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
<h4>Digital Parts
|
||||
<a href="{% url 'work_partset' pk=work.pk %}" title="Print part set"><i class="fas fa-print"></i></a>
|
||||
</h4>
|
||||
<p>
|
||||
{% for part in work.digital_parts %}
|
||||
<a class="badge" href="{% url 'part_download' pk=part.pk filename=part.filename %}"
|
||||
target="part_{{ part.pk }}" rel="">{{ part.instrument }}</a>
|
||||
{% empty %}
|
||||
No digital parts available
|
||||
{% endfor %}
|
||||
</p>
|
||||
|
||||
<h4>Documents</h4>
|
||||
<ul>
|
||||
{% for doc in work.docs.all %}
|
||||
<li>
|
||||
<a href="{% url 'document_download' pk=doc.pk %}" target="_blank">{{ doc.upload.name|basename }}</a>
|
||||
|
||||
{% with parts=doc.parts.count %}
|
||||
{% if parts %}[{{ parts }} parts]{% endif %}
|
||||
{% endwith %}
|
||||
{% if request.is_admin %}
|
||||
<a href="{% url 'document_annotate' pk=doc.pk %}"><i class="fas fa-tags"></i></a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
@@ -2,26 +2,37 @@
|
||||
{% load url_tools %}
|
||||
|
||||
{% block admin %}
|
||||
<a href="{% url 'work_add' %}"><i class="fas fa-plus-circle"></i> Add new</a>
|
||||
{% if collection_id %}
|
||||
<a href="{% url 'work_add' pk=collection_id %}" class="button is-link">
|
||||
<span class="icon"><i class="fas fa-plus-circle"></i></span>
|
||||
<span>Add a work</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<h2>Library for {{ view.ensemble }}</h2>
|
||||
<div style="margin-bottom: 1em;">
|
||||
<form method="GET">
|
||||
<input name="filter" type="text" placeholder="Filter" value="{{ request.GET.filter }}"/>
|
||||
<a href="?">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
<table class="zebra wide">
|
||||
<h3 class="title">{{ title }}</h3>
|
||||
<form method="GET">
|
||||
<div class="field has-addons">
|
||||
<div class="control is-expanded">
|
||||
<input class="input" name="filter" type="text" placeholder="Filter" value="{{ request.GET.filter }}"/>
|
||||
</div>
|
||||
<div class="control">
|
||||
<a class="button" href="?"><i class="fas fa-times"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<table class="table is-striped is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Work</th>
|
||||
<th>Composer</th>
|
||||
<th class="smhide">Edition</th>
|
||||
<th class="smhide">Orchestration</th>
|
||||
<th class="smhide">Collection</th>
|
||||
<th>Copies</th>
|
||||
<th class="is-hidden-mobile">Edition</th>
|
||||
{% if request.is_admin %}
|
||||
<th class="is-hidden-touch">Collection</th>
|
||||
<th class="is-hidden-mobile">Copies</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -29,10 +40,11 @@
|
||||
<tr>
|
||||
<td><a href="{% url 'work_detail' pk=work.pk %}">{{ work.name }}</a></td>
|
||||
<td title="{{ work.composer }}">{{ work.composer|truncatewords:3 }}</td>
|
||||
<td class="smhide" title="{{ work.edition }}">{{ work.edition|truncatewords:2 }}</td>
|
||||
<td class="smhid" title="{{ work.orchestration }}">{{ work.orchestration|truncatewords:2}}</td>
|
||||
<td class="smhide">{{ work.collection.name }}</td>
|
||||
<td style="color: {{ work.is_available|yesno:'green,red' }};">{{ work.available }}</td>
|
||||
<td class="is-hidden-mobile" title="{{ work.edition }}">{{ work.edition|truncatewords:2 }}</td>
|
||||
{% if request.is_admin %}
|
||||
<td class="is-hidden-touch">{{ work.collection.name }}</td>
|
||||
<td class="is-hidden-mobile {{ work.is_available|yesno:'has-text-success,has-text-danger' }}">{{ work.available }}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr><td colspan="4">No works found</td></tr>
|
||||
@@ -40,22 +52,20 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="pagination" style="text-align: right;">
|
||||
<span class="step-links">
|
||||
{% if page_obj.has_previous %}
|
||||
<a href="{% url_update page=1 %}" title="First">«</a>
|
||||
<a href="{% url_update page=page_obj.previous_page_number %}" title="Previous">‹</a>
|
||||
{% endif %}
|
||||
|
||||
<span class="current">
|
||||
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
|
||||
</span>
|
||||
|
||||
{% if page_obj.has_next %}
|
||||
<a href="{% url_update page=page_obj.next_page_number %}" title="Next">›</a>
|
||||
<a href="{% url_update page=page_obj.paginator.num_pages %}" title="Last">»</a>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
|
||||
{% if page_obj.has_previous %}
|
||||
<a class="pagination-previous" href="{% url_update page=page_obj.prev_page_number %}">Previous</a>
|
||||
{% endif %}
|
||||
{% if page_obj.has_next %}
|
||||
<a class="pagination-next" href="{% url_update page=page_obj.next_page_number %}">Next page</a>
|
||||
{% endif %}
|
||||
<ul class="pagination-list">
|
||||
{% for page in page_obj.paginator.page_range %}
|
||||
<li>
|
||||
<a class="pagination-link {% if forloop.counter == page_obj.number %}is-current{% endif %}" href="{% url_update page=forloop.counter %}" aria-label="Goto page {{ forloop.counter }}">{{ forloop.counter }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
{% endblock %}
|
||||
@@ -1,31 +1,37 @@
|
||||
{% extends "interface/project_base.html" %}
|
||||
|
||||
|
||||
|
||||
{% block page %}
|
||||
<h2><a href="{% url 'work_list' %}">Works</a> / <a href="{% url 'work_detail' pk=work.pk %}">{{ work.name }}</a></h2>
|
||||
|
||||
<form action="" method="post" target="_blank">
|
||||
{% csrf_token %}
|
||||
<table style="margin: 0px auto">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Part</th>
|
||||
<th>Copies</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for part in work.parts %}
|
||||
<tr>
|
||||
<td>{{ part.instrument }}</td>
|
||||
<td>
|
||||
<input name="parts" type="hidden" value="{{ part.tag }}">
|
||||
<input name="copies" type="number" value="{% if part.tag == 'Score' %}0{% else %}1{% endif %}" size="1">
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
<td colspan="2" style="text-align: center;"><button type="submit"><i class="fas fa-print"></i> Print</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="admin-tools is-pulled-right">
|
||||
<button type="submit" class="button is-link">
|
||||
<span class="icon"><i class="fas fa-print"></i></span>
|
||||
<span>Print Set</span>
|
||||
</button>
|
||||
<a class="button is-link is-light" href="{% url 'work_detail' pk=object.pk %}">
|
||||
<span>Cancel</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<h3 class="subtitle"><a href="{% url 'work_detail' pk=work.pk %}">{{ work.name }}</a></h3>
|
||||
|
||||
<p class="block">
|
||||
You can generate a custom partset for printing - select the number of copies of each you want...
|
||||
</p>
|
||||
|
||||
<div class="columns is-multiline is-mobile">
|
||||
{% for part in work.digital_parts %}
|
||||
<div class="column is-3 has-text-right">
|
||||
<span style="white-space: nowrap">{{ part.instrument }}</span>
|
||||
<input name="parts" type="hidden" value="{{ part.tag }}">
|
||||
<input name="copies" type="number" value="{% if part.tag == 'Score' %}0{% else %}1{% endif %}" size="1">
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -20,3 +20,31 @@ class IntegrationTestCase(TestCase):
|
||||
|
||||
def test_integration(self):
|
||||
pass
|
||||
|
||||
def test_movement_from_large_work(self):
|
||||
'''
|
||||
Will be common to store a work which has several movements, but the project is only going to play one.
|
||||
This also should give us the ability to store an anthology as one Work have Project reference 'no:23'
|
||||
'''
|
||||
|
||||
work = self.sel.works.create(name="Some Quartet", composer="Beethoven")
|
||||
for g in ('vl1', 'vl2', 'vla', 'vc'):
|
||||
doc = work.docs.create(upload=f'sel/beethoven/some_quartet/some_quartet_{g}.pdf')
|
||||
doc.sections.create(tag='mvmt:1', start=1, end=3)
|
||||
doc.sections.create(tag='mvmt:2', start=4, end=8)
|
||||
doc.sections.create(tag='mvmt:3', start=9, end=12)
|
||||
doc.sections.create(tag=f'inst:{g}')
|
||||
|
||||
# no tags - get nothing (should it be everything?)
|
||||
self.assertEqual(work.extract(), [])
|
||||
|
||||
# single tag - should get just that range
|
||||
self.assertEqual(work.extract('inst:vl1'), [('sel/beethoven/some_quartet/some_quartet_vl1.pdf', None, None)])
|
||||
|
||||
# single tag - returns all documents with that range
|
||||
result = work.extract('mvmt:2')
|
||||
self.assertEqual(len(result), 4)
|
||||
|
||||
# multiple tags - returns the overlapping portion of all documents that have all tags
|
||||
self.assertEqual(work.extract('inst:vl1', 'mvmt:2'), [('sel/beethoven/some_quartet/some_quartet_vl1.pdf', 4, 8)])
|
||||
self.assertEqual(work.extract('inst:vl1', 'inst:vl2'), [])
|
||||
+8
-3
@@ -8,17 +8,22 @@ urlpatterns = [
|
||||
path('projects/<int:project>/items', views.ProjectItemListView.as_view(), name="item_list"),
|
||||
path('projects/<int:project>/items/manage', views.ProjectItemManageView.as_view(), name="item_list_manage"),
|
||||
path('projects/<int:project>/items/append', views.ProjectItemAddView.as_view(), name="item_list_append"),
|
||||
|
||||
path('library/collections', views.CollectionListView.as_view(), name="collection_list"),
|
||||
path('library/collections/<int:pk>', views.CollectionWorkListView.as_view(), name="collection_work_list"),
|
||||
path('library/collection/<int:pk>/create', views.WorkAddView.as_view(), name="work_add"),
|
||||
|
||||
path('library/works', views.WorkListView.as_view(), name="work_list"),
|
||||
path('library/works/create', views.WorkAddView.as_view(), name="work_add"),
|
||||
path('library/works/<int:pk>', views.WorkDetailView.as_view(), name="work_detail"),
|
||||
path('library/works/<int:pk>/edit', views.WorkUpdateView.as_view(), name="work_edit"),
|
||||
path('library/works/<int:pk>/partset', views.WorkPartSetView.as_view(), name="work_partset"),
|
||||
path('library/works/<int:pk>/add_to_project', views.WorkAddToProject.as_view(), name="work_add_to_project"),
|
||||
path('library/documents/<int:pk>/upload', views.DocumentAddView.as_view(), name="document_add"),
|
||||
path('library/works/<int:pk>/upload', views.WorkAddDocumentView.as_view(), name="document_add"),
|
||||
|
||||
path('library/documents/<int:pk>/download', views.DocumentDownloadView.as_view(), name="document_download"),
|
||||
path('library/documents/<int:pk>/annotate', views.DocumentAnnotateView.as_view(), name="document_annotate"),
|
||||
path('library/parts/<int:pk>/<str:filename>', views.PartDownloadView.as_view(), name="part_download"),
|
||||
]
|
||||
|
||||
from django.views.static import serve
|
||||
urlpatterns.append(path('localstorage/<path:path>', serve, {'document_root': 'local_storage'}))
|
||||
urlpatterns.append(path('docs/<path:path>', serve, {'document_root': 'local_storage'}))
|
||||
+128
-59
@@ -2,22 +2,25 @@ from django.shortcuts import render, redirect, resolve_url
|
||||
from django.views.generic.detail import DetailView, SingleObjectMixin, View
|
||||
from django.views.generic.list import ListView, MultipleObjectMixin
|
||||
from django.views.generic.edit import CreateView, FormView, UpdateView
|
||||
from django.http import FileResponse, HttpResponse
|
||||
from django.http import FileResponse, HttpResponse, JsonResponse
|
||||
from django.db import IntegrityError
|
||||
from django.db.models import Q, Count
|
||||
from django.db.models import Q, Count, Sum
|
||||
from django.utils.timezone import now
|
||||
from django.urls import reverse
|
||||
|
||||
import json
|
||||
import os.path
|
||||
|
||||
from interface.views import EnsembleMixin, ProjectMixin
|
||||
from interface.models import Project
|
||||
from .models import Work, Document, Part, INSTRUMENTS
|
||||
from .models import Collection, Work, Document, Section
|
||||
from .imslp import INSTRUMENTS
|
||||
from . import forms, models
|
||||
from .pdf_utils import extract_pages, extract_and_concat
|
||||
|
||||
class ProjectItemListView(ProjectMixin, ListView):
|
||||
template_name = "library/item_list.html"
|
||||
model = models.Item
|
||||
model = models.ProjectItem
|
||||
|
||||
def post(self, request, **kwargs):
|
||||
|
||||
@@ -44,7 +47,7 @@ class ProjectItemListView(ProjectMixin, ListView):
|
||||
if tag == '-':
|
||||
continue
|
||||
|
||||
part = Part.objects.filter(tag=tag, doc__work=pk).select_related('doc').get()
|
||||
part = Section.objects.filter(tag=tag, doc__work=pk).select_related('doc').get()
|
||||
sections.append((part.doc.upload.path, part.doc.work.name, part.start, part.end, 1))
|
||||
|
||||
result = extract_and_concat(sections)
|
||||
@@ -64,11 +67,16 @@ class ProjectItemListView(ProjectMixin, ListView):
|
||||
data['instruments'] = INSTRUMENTS
|
||||
data['instrument'] = self.request.session.get('instrument', 'Score')
|
||||
data['part'] = self.request.session.get('part', '0')
|
||||
data['running_time'] = self.get_queryset().aggregate(Sum('work__running_time'))['work__running_time__sum']
|
||||
#if running_time:
|
||||
# data['running_time'] = "{0:d}:{1:02d}".format(int(running_time / 60), running_time % 60)
|
||||
#else:
|
||||
# data['running_time'] = "-:--"
|
||||
return data
|
||||
|
||||
class ProjectItemManageView(ProjectMixin, ListView):
|
||||
template_name = "library/item_list_manage.html"
|
||||
model = models.Item
|
||||
model = models.ProjectItem
|
||||
|
||||
def post(self, request, **kwargs):
|
||||
self.request = request
|
||||
@@ -99,38 +107,61 @@ class ProjectItemAddView(ProjectMixin, UpdateView):
|
||||
def get_object(self):
|
||||
return self.get_project()
|
||||
|
||||
class CollectionListView(EnsembleMixin, ListView):
|
||||
|
||||
def get_queryset(self):
|
||||
return Collection.objects.filter(administrators=self.request.user)
|
||||
|
||||
|
||||
class WorkListView(EnsembleMixin, ListView):
|
||||
paginate_by = 20
|
||||
|
||||
def get_queryset(self):
|
||||
#works = Work.objects.filter(collection__ensembles=self.request.ensemble_id).order_by('name').select_related('collection')
|
||||
works = Work.objects.filter(collection__allowed_ensembles__ensemble=self.request.ensemble_id).order_by('name').select_related('collection')
|
||||
def get_works(self):
|
||||
return Work.objects.filter(collection__allowed_ensembles__ensemble=self.request.ensemble_id).order_by('name').distinct().select_related('collection')
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
data = super(WorkListView, self).get_context_data(*args, **kwargs)
|
||||
data['title'] = f'Music available to {self.ensemble.name}'
|
||||
return data
|
||||
|
||||
loan_count = Count('project_items', Q(project_items__checkout__lte=now(), project_items__returned=None))
|
||||
works = works.annotate(loan_count=loan_count)
|
||||
def get_queryset(self):
|
||||
works = self.get_works().order_by('name')
|
||||
|
||||
q = self.request.GET.get('filter')
|
||||
if q:
|
||||
works = works.filter(Q(name__contains=q) | Q(composer__contains=q) | Q(tag_list__contains=q))
|
||||
if ":" in q:
|
||||
name, _, value = q.partition(":")
|
||||
works = works.filter(meta_info__name=name, meta_info__value__contains=value)
|
||||
else:
|
||||
works = works.filter(Q(name__contains=q) | Q(composer__contains=q) | Q(meta_info__value__contains=q))
|
||||
|
||||
return works
|
||||
|
||||
class CollectionWorkListView(WorkListView):
|
||||
|
||||
def get_works(self):
|
||||
works = Work.objects.filter(collection=self.kwargs['pk']).distinct()
|
||||
|
||||
loan_count = Count('project_items', Q(project_items__checkout__lte=now(), project_items__returned=None))
|
||||
works = works.annotate(loan_count=loan_count)
|
||||
return works
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
data = super(CollectionWorkListView, self).get_context_data(*args, **kwargs)
|
||||
data['title'] = Collection.objects.get(pk=self.kwargs['pk']).name
|
||||
data['collection_id'] = self.kwargs['pk']
|
||||
return data
|
||||
|
||||
class WorkAddView(EnsembleMixin, FormView):
|
||||
template_name = "interface/default_form.html"
|
||||
form_class = forms.WorkCreateForm
|
||||
|
||||
def get_form(self):
|
||||
f = super(WorkAddView, self).get_form()
|
||||
#qs = f.fields['orchestration'].queryset
|
||||
#f.fields['orchestration'].queryset = qs.filter(ensemble_id__isnull=True) | qs.filter(ensemble_id=self.request.ensemble_id)
|
||||
qs = f.fields['collection'].queryset
|
||||
qs = qs.filter(administrators=self.request.user)
|
||||
f.fields['collection'].queryset = qs
|
||||
return f
|
||||
title = "Add a new work"
|
||||
|
||||
def form_valid(self, form):
|
||||
work = form.save(commit=False)
|
||||
work.ensemble_id = self.request.ensemble_id
|
||||
work.collection_id = self.kwargs['pk']
|
||||
work.save()
|
||||
|
||||
# handle the files
|
||||
@@ -144,12 +175,26 @@ class WorkAddView(EnsembleMixin, FormView):
|
||||
else:
|
||||
return redirect('work_detail', pk=work.pk)
|
||||
|
||||
class WorkDetailView(EnsembleMixin, DetailView):
|
||||
class WorkMixin(object):
|
||||
|
||||
def get_queryset(self):
|
||||
if self.request.is_admin:
|
||||
return Work.objects.all()
|
||||
|
||||
return Work.objects.filter(collection__allowed_ensembles__ensemble=self.request.ensemble_id)
|
||||
|
||||
class WorkDetailView(EnsembleMixin, WorkMixin, DetailView):
|
||||
pass
|
||||
|
||||
class WorkUpdateView(EnsembleMixin, WorkMixin, UpdateView):
|
||||
fields = ['name', 'composer', 'edition', 'code', 'licence', 'max_projects', 'running_time', 'notes']
|
||||
template_name = 'interface/default_form.html'
|
||||
|
||||
def get_success_url(self):
|
||||
return resolve_url('work_detail', self.kwargs['pk'])
|
||||
|
||||
class WorkAddToProject(EnsembleMixin, FormView):
|
||||
admin_required = True
|
||||
form_class = forms.ProjectSelectForm
|
||||
template_name = "interface/default_form.html"
|
||||
title = "Select project to add work to"
|
||||
@@ -188,7 +233,7 @@ class WorkPartSetView(EnsembleMixin, DetailView):
|
||||
sections = []
|
||||
|
||||
for i, tag in enumerate(parts):
|
||||
part = work.parts.select_related('doc').get(tag=tag)
|
||||
part = work.digital_parts.select_related('doc').get(tag=tag)
|
||||
sections.append((part.doc.upload.path, part.instrument, part.start, part.end, int(copies[i])))
|
||||
|
||||
result = extract_and_concat(sections)
|
||||
@@ -200,25 +245,59 @@ class WorkPartSetView(EnsembleMixin, DetailView):
|
||||
return response
|
||||
|
||||
def get_queryset(self):
|
||||
return Version.objects.filter(work__ensemble_id=self.request.ensemble_id)
|
||||
works = Work.objects.all()
|
||||
|
||||
class DocumentDetailView(EnsembleMixin, DetailView):
|
||||
if not self.request.is_admin:
|
||||
works = works.filter(collection__allowed_ensembles__ensemble=self.request.ensemble_id)
|
||||
return works
|
||||
|
||||
def get_queryset(self):
|
||||
return Document.objects.filter(work__ensemble=self.request.ensemble_id).select_related('work')
|
||||
|
||||
class DocumentAddView(EnsembleMixin, CreateView):
|
||||
class WorkAddDocumentView(EnsembleMixin, CreateView):
|
||||
template_name = "interface/default_form.html"
|
||||
model = Document
|
||||
fields = ['upload']
|
||||
|
||||
def title(self):
|
||||
work = Work.objects.get(pk=self.kwargs['pk'])
|
||||
return f"Add a document to {work.name}"
|
||||
|
||||
def form_invalid(self, form):
|
||||
if self.request.headers['Accept'] == 'application/json':
|
||||
return HttpResponse(status=400)
|
||||
return super().form_invalid(form)
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save(commit=False)
|
||||
self.object.work_id = self.kwargs['pk']
|
||||
self.object.save()
|
||||
return redirect('document_annotate', self.object.pk)
|
||||
doc = form.save(commit=False)
|
||||
doc.work_id = self.kwargs['pk']
|
||||
doc.save()
|
||||
if self.request.headers['Accept'] == 'application/json':
|
||||
filename = os.path.basename(doc.upload.name)
|
||||
return JsonResponse({
|
||||
"message": "created",
|
||||
"id": doc.pk,
|
||||
"entry": f"""
|
||||
<td><a href="{reverse('document_download', args=[doc.pk])}">{filename}</a></td>
|
||||
<td/>
|
||||
<td class="has-text-right">
|
||||
<a href="{reverse('document_annotate', args=[doc.pk])}"><i class="fas fa-tags"
|
||||
title="Manage Tags"></i></a>
|
||||
<a href=""><i class="fas fa-trash-alt" title="Delete Document"></i></a>
|
||||
</td>
|
||||
"""
|
||||
}, status=201)
|
||||
|
||||
class DocumentDownloadView(EnsembleMixin, SingleObjectMixin, View):
|
||||
return redirect('document_annotate', doc.pk)
|
||||
|
||||
class DocumentMixin(object):
|
||||
|
||||
def get_queryset(self):
|
||||
if self.request.is_admin:
|
||||
return Document.objects.select_related('work')
|
||||
return Document.objects.filter(work__ensemble=self.request.ensemble_id).select_related('work')
|
||||
|
||||
class DocumentDetailView(EnsembleMixin, DocumentMixin, DetailView):
|
||||
pass
|
||||
|
||||
class DocumentDownloadView(EnsembleMixin, DocumentMixin, SingleObjectMixin, View):
|
||||
|
||||
def get(self, request, **args):
|
||||
self.request = request
|
||||
@@ -229,10 +308,7 @@ class DocumentDownloadView(EnsembleMixin, SingleObjectMixin, View):
|
||||
#return response
|
||||
return redirect(self.object.upload.url)
|
||||
|
||||
def get_queryset(self):
|
||||
return Document.objects.filter(work__collection__allowed_ensembles__ensemble=self.request.ensemble_id)
|
||||
|
||||
class DocumentAnnotateView(EnsembleMixin, DetailView):
|
||||
class DocumentAnnotateView(EnsembleMixin, DocumentMixin, DetailView):
|
||||
template_name = 'library/document_annotate.html'
|
||||
|
||||
def post(self, request, **args):
|
||||
@@ -242,36 +318,24 @@ class DocumentAnnotateView(EnsembleMixin, DetailView):
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
tags = {}
|
||||
for page, tag in data.items():
|
||||
tags.setdefault(tag, []).append(int(page))
|
||||
try:
|
||||
del(tags['None'])
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
self.object.parts.all().delete()
|
||||
for tag, pages in tags.items():
|
||||
pages.sort()
|
||||
end = pages[-1] if len(pages) > 1 else None
|
||||
o = self.object.parts.create(tag=tag, start=pages[0], end=end)
|
||||
self.object.sections.all().delete()
|
||||
for tag, start, end in data:
|
||||
#pages.sort()
|
||||
#end = pages[-1] if len(pages) > 1 else None
|
||||
o = self.object.sections.create(tag=tag, start=start, end=end)
|
||||
|
||||
return HttpResponse(status=204)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super(DocumentAnnotateView, self).get_context_data(**kwargs)
|
||||
|
||||
pages = {}
|
||||
for part in data['document'].parts.all():
|
||||
for i in range(part.start, (part.end or part.start)+1):
|
||||
pages[i] = part.tag
|
||||
pages = []
|
||||
for part in data['document'].sections.all():
|
||||
pages.append((part.tag, part.start, part.end))
|
||||
|
||||
data['json_data'] = {'pageTags': pages, 'instruments': data['document'].work.orchestration}
|
||||
data['json_data'] = {'pageTags': pages, 'instruments': dict(INSTRUMENTS)}
|
||||
return data
|
||||
|
||||
def get_queryset(self):
|
||||
return Document.objects.filter(work__collection__allowed_ensembles__ensemble=self.request.ensemble_id).select_related('work')
|
||||
|
||||
|
||||
class PartDownloadView(EnsembleMixin, SingleObjectMixin, View):
|
||||
|
||||
@@ -289,4 +353,9 @@ class PartDownloadView(EnsembleMixin, SingleObjectMixin, View):
|
||||
return response
|
||||
|
||||
def get_queryset(self):
|
||||
return Part.objects.filter(doc__work__collection__allowed_ensembles__ensemble=self.request.ensemble_id).select_related('doc', 'doc__work')
|
||||
|
||||
if self.request.is_admin:
|
||||
parts = Section.objects.all()
|
||||
else:
|
||||
parts = Section.objects.filter(doc__work__collection__allowed_ensembles__ensemble=self.request.ensemble_id)
|
||||
return parts.select_related('doc', 'doc__work')
|
||||
Reference in New Issue
Block a user