Music tag fixes
This commit is contained in:
parent
965fc49501
commit
471e465133
@ -292,7 +292,11 @@ class Work(models.Model):
|
||||
|
||||
@property
|
||||
def digital_parts(self):
|
||||
sections = [(s.tag, s.name) for s in Section.objects.filter(doc__work=self.pk)]
|
||||
sections = [
|
||||
(s.tag, s.name)
|
||||
for s in Section.objects.filter(doc__work=self.pk)
|
||||
if ":" not in s.tag
|
||||
]
|
||||
sections.sort(key=self.orchestration.sorter())
|
||||
# return [ s[1] for s in sections ]
|
||||
sections = list(dict(sections).items()) # primitive unique()
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
from collections import namedtuple
|
||||
from dataclasses import dataclass
|
||||
import re
|
||||
|
||||
GENERAL = """
|
||||
mvmt Movement
|
||||
ex Excerpt
|
||||
sect Section
|
||||
pce Piece
|
||||
no No.
|
||||
page Page
|
||||
"""
|
||||
|
||||
TAG_PREFIXES = {
|
||||
"mvmt": "Movement",
|
||||
"ex": "Excerpt",
|
||||
"sect": "Section",
|
||||
"name": "Name",
|
||||
"no": "Number",
|
||||
"page": "Page",
|
||||
}
|
||||
|
||||
# taken from https://imslp.org/wiki/IMSLP:Abbreviations_for_MusicTags
|
||||
# Include any aliases at the top
|
||||
@ -160,71 +161,110 @@ xyl Xylophone
|
||||
zith Zither
|
||||
"""
|
||||
|
||||
MUSIC_TAG = re.compile(r"((?P<prefix>\w+):)?(?P<name>.*?)(\-(?P<number>[0-9]+))?")
|
||||
|
||||
MUSIC_TAGS = []
|
||||
GENERAL_TAGS = set()
|
||||
for i, abbreviations in enumerate((GENERAL, INSTRUMENTS)):
|
||||
for line in abbreviations.split("\n"):
|
||||
TAG_ALIASES = {}
|
||||
# GENERAL_TAGS = set()
|
||||
for line in INSTRUMENTS.split("\n"):
|
||||
parts = line.strip().split(maxsplit=1)
|
||||
if len(parts) < 2:
|
||||
continue
|
||||
name, _, _ = parts[1].partition("(")
|
||||
MUSIC_TAGS.append((parts[0], name))
|
||||
if i == 0:
|
||||
GENERAL_TAGS.add(parts[0])
|
||||
|
||||
MUSIC_TAGS.append((parts[0], name.strip()))
|
||||
# if i == 0:
|
||||
# GENERAL_TAGS.add(parts[0])
|
||||
TAG_ALIASES.setdefault(name, []).append(parts[0])
|
||||
|
||||
MUSIC_NAME_BY_TAG = dict(MUSIC_TAGS)
|
||||
MUSIC_TAG_BY_NAME = dict(((x[1].lower(), x[0]) for x in MUSIC_TAGS))
|
||||
|
||||
|
||||
class MusicTag(namedtuple("MusicTag", ("name", "variant"), defaults=[None])):
|
||||
def slug(s):
|
||||
"""
|
||||
>>> slug("This is a test")
|
||||
'This_is_a_test'
|
||||
"""
|
||||
return str(s).replace(" ", "_")
|
||||
|
||||
|
||||
def deslug(s):
|
||||
return s.replace("_", " ")
|
||||
|
||||
|
||||
@dataclass
|
||||
class MusicTag:
|
||||
name: str
|
||||
number: int | None = None
|
||||
prefix: str = ""
|
||||
|
||||
@classmethod
|
||||
def from_tag(cls, tag):
|
||||
"""
|
||||
>>> MusicTag.from_tag('vn-1')
|
||||
MusicTag(name='Violin', variant='1')
|
||||
MusicTag(name='Violin', number=1, prefix='')
|
||||
>>> MusicTag.from_tag('db')
|
||||
MusicTag(name='Double Bass', variant=None)
|
||||
MusicTag(name='Double Bass', number=None, prefix='')
|
||||
>>> MusicTag.from_tag('Jaws Harp')
|
||||
MusicTag(name='Jaws Harp', variant=None)
|
||||
>>> MusicTag.from_tag('mvmt-2')
|
||||
MusicTag(name='Movement', variant='2')
|
||||
>>> MusicTag.from_tag('pce-A2')
|
||||
MusicTag(name='Piece', variant='A2')
|
||||
MusicTag(name='Jaws Harp', number=None, prefix='')
|
||||
>>> MusicTag.from_tag('mvmt:Largo-2')
|
||||
MusicTag(name='Largo', number=2, prefix='mvmt')
|
||||
>>> MusicTag.from_tag('name:A2')
|
||||
MusicTag(name='A2', number=None, prefix='name')
|
||||
>>> MusicTag.from_tag('name:Ode_to_Joy')
|
||||
MusicTag(name='Ode to Joy', number=None, prefix='name')
|
||||
>>> MusicTag.from_tag('no:-2')
|
||||
MusicTag(name='', number=2, prefix='no')
|
||||
"""
|
||||
abbr, _, variant = tag.partition("-")
|
||||
name = MUSIC_NAME_BY_TAG.get(abbr.lower(), abbr)
|
||||
|
||||
if variant:
|
||||
return cls(name, variant)
|
||||
return cls(name, None)
|
||||
match = MUSIC_TAG.fullmatch(tag)
|
||||
|
||||
@property
|
||||
def tag(self):
|
||||
lc = self.name.lower()
|
||||
return MUSIC_TAG_BY_NAME.get(lc, lc)
|
||||
if match is None:
|
||||
raise ValueError("Not a valid tag")
|
||||
|
||||
result = match.groupdict()
|
||||
|
||||
if result["prefix"] is None:
|
||||
result["name"] = MUSIC_NAME_BY_TAG.get(
|
||||
result["name"].lower(), deslug(result["name"])
|
||||
)
|
||||
result["prefix"] = ""
|
||||
else:
|
||||
result["name"] = deslug(result["name"])
|
||||
|
||||
result["number"] = int(result["number"]) if result["number"] else None
|
||||
|
||||
return cls(**result)
|
||||
|
||||
@property
|
||||
def is_general(self):
|
||||
"""
|
||||
>>> MusicTag('Piece', 'A3').is_general
|
||||
>>> MusicTag('A3', prefix="name").is_general
|
||||
True
|
||||
>>> MusicTag('Violin', 2).is_general
|
||||
False
|
||||
"""
|
||||
return self.tag in GENERAL_TAGS
|
||||
return self.prefix in TAG_PREFIXES
|
||||
|
||||
def abbreviate(self):
|
||||
@property
|
||||
def tag(self):
|
||||
"""
|
||||
>>> MusicTag('Violin', 1).abbreviate()
|
||||
>>> MusicTag('Violin', 1).tag
|
||||
'vn-1'
|
||||
>>> MusicTag('Double Bass').abbreviate()
|
||||
>>> MusicTag('Double Bass').tag
|
||||
'db'
|
||||
>>> MusicTag('left', prefix="page:").tag
|
||||
'page:left'
|
||||
>>> MusicTag("Ode to Joy", prefix="name:").tag
|
||||
'name:Ode_to_Joy'
|
||||
>>> MusicTag('Unknown Instrument').tag
|
||||
'Unknown_Instrument'
|
||||
"""
|
||||
tag = MUSIC_TAG_BY_NAME.get(self.name.lower())
|
||||
if self.variant:
|
||||
tag = f"{tag}-{self.variant}"
|
||||
return tag
|
||||
parts = [self.prefix]
|
||||
parts.append(MUSIC_TAG_BY_NAME.get(self.name.lower(), slug(self.name)))
|
||||
if self.number:
|
||||
parts.extend(["-", str(self.number)])
|
||||
return "".join(parts)
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
@ -232,15 +272,17 @@ class MusicTag(namedtuple("MusicTag", ("name", "variant"), defaults=[None])):
|
||||
'Violin 1'
|
||||
>>> str(MusicTag('Double Bass'))
|
||||
'Double Bass'
|
||||
>>> str(MusicTag('Unknown Instrument'))
|
||||
'Unknown Instrument'
|
||||
"""
|
||||
if self.variant:
|
||||
return f"{self.name} {self.variant}"
|
||||
if self.number:
|
||||
return f"{self.name} {self.number}"
|
||||
return self.name
|
||||
|
||||
|
||||
PATTERNS = [
|
||||
re.compile(r"(?P<inst>[A-Za-z]+)[_\- ]*(?P<ord>\d+)"),
|
||||
re.compile(r"(?P<ord>\d+)(st|nd|rd|th)[_\- ]*(?P<inst>[A-Za-z]+)"),
|
||||
re.compile(r"(?P<inst>[A-Za-z]+)[_\- ]*(?P<number>\d+)"),
|
||||
re.compile(r"(?P<number>\d+)(st|nd|rd|th)[_\- ]*(?P<inst>[A-Za-z]+)"),
|
||||
re.compile(r"(?P<inst>[A-Za-z]+)()"),
|
||||
]
|
||||
|
||||
@ -248,34 +290,33 @@ PATTERNS = [
|
||||
def auto_tag(filename):
|
||||
"""
|
||||
|
||||
>>> auto_tag('Ode to Joy - Violin 1.pdf')
|
||||
MusicTag(name='Violin', variant=1)
|
||||
>>> auto_tag('Ode to Joy_Cello.pdf')
|
||||
MusicTag(name='Cello', variant=None)
|
||||
>>> auto_tag('Ode to Joy violin - 1.pdf')
|
||||
MusicTag(name='Violin', variant=1)
|
||||
>>> auto_tag('Ode to Joy - vla.pdf')
|
||||
MusicTag(name='Viola', variant=None)
|
||||
>>> auto_tag('Ode to Joy - fl-2 (piccolo).pdf')
|
||||
MusicTag(name='Flute', variant=2)
|
||||
>>> auto_tag('1st Violin - Ode to Joy.pdf')
|
||||
MusicTag(name='Violin', variant=1)
|
||||
>>> auto_tag('Ode to Joy - 2nd Violin.pdf')
|
||||
MusicTag(name='Violin', variant=2)
|
||||
|
||||
>>> auto_tag('Ode to Joy - Violin 1.pdf').tag
|
||||
'vn-1'
|
||||
>>> auto_tag('Ode to Joy_Cello.pdf').tag
|
||||
'vc'
|
||||
>>> auto_tag('Ode to Joy violin - 1.pdf').tag
|
||||
'vn-1'
|
||||
>>> auto_tag('Ode to Joy - vla.pdf').tag
|
||||
'va'
|
||||
>>> auto_tag('Ode to Joy - fl-2 (piccolo).pdf').tag
|
||||
'fl-2'
|
||||
>>> auto_tag('1st Violin - Ode to Joy.pdf').tag
|
||||
'vn-1'
|
||||
>>> auto_tag('Ode to Joy - 2nd Violin.pdf').tag
|
||||
'vn-2'
|
||||
"""
|
||||
|
||||
for pattern in PATTERNS:
|
||||
for m in pattern.finditer(filename):
|
||||
inst = m["inst"].lower()
|
||||
try:
|
||||
ordinal = int(m["ord"])
|
||||
number = int(m["number"])
|
||||
except IndexError:
|
||||
ordinal = None
|
||||
number = None
|
||||
if inst in MUSIC_TAG_BY_NAME:
|
||||
return MusicTag(inst.title(), ordinal)
|
||||
return MusicTag(inst.title(), number)
|
||||
if inst in MUSIC_NAME_BY_TAG:
|
||||
return MusicTag(MUSIC_NAME_BY_TAG[inst], ordinal)
|
||||
return MusicTag(MUSIC_NAME_BY_TAG[inst], number)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@ -80,6 +80,7 @@
|
||||
.tag-name {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tag-handle-resize {
|
||||
position: absolute;
|
||||
@ -140,7 +141,7 @@
|
||||
</ul>
|
||||
<h3>Actions</h3>
|
||||
<div>
|
||||
<a class="button is-small is-primary" onclick="showAddModal()">New Tag</a>
|
||||
<a class="button is-small is-primary" onclick="showTagModal(createNewTag)">New Tag</a>
|
||||
<button class="button is-small is-primary" onclick="expandEntries()">Expand Tags</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -163,18 +164,19 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal" id="add-modal">
|
||||
<div class="modal-background" onclick="closeAddModal()"></div>
|
||||
<div class="modal" id="tag-modal">
|
||||
<div class="modal-background" onclick="closeTagModal()"></div>
|
||||
<div class="modal-card">
|
||||
<header class="modal-card-head">
|
||||
<p class="modal-card-title">Add Tag</p>
|
||||
<button class="delete" aria-label="close" onclick="closeAddModal()"></button>
|
||||
<p class="modal-card-title">Tag Editor</p>
|
||||
<button class="delete" aria-label="close" onclick="closeTagModal()"></button>
|
||||
</header>
|
||||
<section class="modal-card-body">
|
||||
<form>
|
||||
<div class="field has-addons is-justify-content-center">
|
||||
<span class="control">
|
||||
<span class="select">
|
||||
<select onChange="changeTagType()" id="tag-type-selection">
|
||||
<select onChange="onChangeTagType()" id="tag-prefix">
|
||||
<option value="inst">Instrument</option>
|
||||
<option value="mvmt">Movement</option>
|
||||
<option value="sect">Section</option>
|
||||
@ -183,32 +185,34 @@
|
||||
</select>
|
||||
</span>
|
||||
</span>
|
||||
<span class="control add-tag-option enable-page">
|
||||
<span class="select">
|
||||
<select id="add-tag-page">
|
||||
<option>Left</option>
|
||||
<option>Right</option>
|
||||
<span class="control tag-option enable-page">
|
||||
<span class="select tag-name">
|
||||
<select id="tag-name-page">
|
||||
<option value="left">Left</option>
|
||||
<option value="right">Right</option>
|
||||
<option value="blank">Add Blank</option>
|
||||
</select>
|
||||
</span>
|
||||
</span>
|
||||
<span class="control add-tag-option enable-sect">
|
||||
<input type="text" class="input" id="add-tag-name"/>
|
||||
<span class="control tag-option enable-sect enable-mvmt">
|
||||
<input type="text" class="input tag-name" id="tag-name" />
|
||||
</span>
|
||||
<span class="control add-tag-option enable-inst">
|
||||
<input type="text" class="input" list="instrument-list" id="add-tag-inst"/>
|
||||
<span class="control tag-option enable-inst">
|
||||
<input type="text" class="input tag-name" list="instrument-list" id="tag-name-inst"/>
|
||||
<datalist id="instrument-list">
|
||||
{% for inst in json_data.instruments.values %}
|
||||
{% for inst in json_data.instrumentNames %}
|
||||
<option value="{{inst}}"/>
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
</span>
|
||||
<span class="control add-tag-option enable-inst enable-mvmt enable-no">
|
||||
<input type="number" class="input" min="1" size="3" id="add-tag-ordinal"/>
|
||||
<span class="control tag-option enable-inst enable-mvmt enable-no">
|
||||
<input type="number" class="input tag-number" min="1" size="3" id="tag-number"/>
|
||||
</span>
|
||||
<span class="control">
|
||||
<button class="button is-primary" onclick="createNewTag();">Add</button>
|
||||
<button type="submit" class="button is-primary" onclick="event.preventDefault(); confirmTagModal(); ">Save</button>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
@ -244,6 +248,7 @@
|
||||
let data = JSON.parse(document.getElementById('data').textContent);
|
||||
let tagArea = document.getElementById('tag-area');
|
||||
var dirty = false;
|
||||
var tagModalCallback = null;
|
||||
|
||||
//document.getElementById('tag-list').onclick = (e) => setTag(e.target.dataset.tag);
|
||||
|
||||
@ -405,13 +410,25 @@
|
||||
dirty = false;
|
||||
});
|
||||
|
||||
function showAddModal() {
|
||||
document.getElementById("add-modal").classList.add("is-active");
|
||||
changeTagType();
|
||||
function showTagModal(callback, tag) {
|
||||
document.getElementById("tag-modal").classList.add("is-active");
|
||||
|
||||
tagModalCallback = callback;
|
||||
|
||||
if(tag) {
|
||||
const parts = parseTag(tag);
|
||||
console.log(parts);
|
||||
document.querySelector("#tag-prefix").value = parts.prefix;
|
||||
onChangeTagType();
|
||||
document.querySelectorAll(".tag-name").forEach(el => el.value = parts.name);
|
||||
document.querySelector(".tag-number").value = parts.number;
|
||||
} else {
|
||||
onChangeTagType();
|
||||
}
|
||||
}
|
||||
|
||||
function closeAddModal() {
|
||||
document.getElementById('add-modal').classList.remove('is-active');
|
||||
function closeTagModal() {
|
||||
document.getElementById('tag-modal').classList.remove('is-active');
|
||||
}
|
||||
|
||||
function addNumberedInstrument(tag, e) {
|
||||
@ -424,55 +441,48 @@
|
||||
modal.classList.add('is-active');
|
||||
}
|
||||
|
||||
function changeTagType() {
|
||||
const tag_select = document.querySelector("#tag-type-selection");
|
||||
const selected = tag_select.value;
|
||||
document.querySelectorAll(".add-tag-option").forEach((x) => {x.classList.add("is-hidden")});
|
||||
document.querySelectorAll(".add-tag-option input").forEach((x) => {x.value=""});
|
||||
function onChangeTagType() {
|
||||
const tag_prefix = document.querySelector("#tag-prefix");
|
||||
const selected = tag_prefix.value;
|
||||
document.querySelectorAll(".tag-option").forEach((x) => {x.classList.add("is-hidden")});
|
||||
document.querySelectorAll(".tag-option input").forEach((x) => {x.value=""});
|
||||
document.querySelectorAll(".enable-" + selected).forEach((x) => {x.classList.remove("is-hidden")});
|
||||
tag_select.focus();
|
||||
tag_prefix.focus();
|
||||
|
||||
}
|
||||
|
||||
function generateNewTag() {
|
||||
const selected = document.querySelector("#tag-type-selection").value;
|
||||
const n = document.querySelector("#add-tag-ordinal").value;
|
||||
function confirmTagModal() {
|
||||
const selected = document.querySelector("#tag-prefix").value;
|
||||
let name = document.querySelector("#tag-name").value;
|
||||
const n = document.querySelector("#tag-number").value;
|
||||
switch (selected) {
|
||||
case "mvmt":
|
||||
case "no":
|
||||
return selected + "-" + n;
|
||||
case "sect":
|
||||
return "sect-" + document.querySelector("#add-tag-name").value;
|
||||
if (!n) throw new Error("Missing number");
|
||||
case "page":
|
||||
name = document.querySelector("#tag-name-page").value;
|
||||
case "inst":
|
||||
const inst_name = document.querySelector("#add-tag-inst").value;
|
||||
var tag = null;
|
||||
name = document.querySelector("#tag-name-inst").value;
|
||||
for (let key in data.instruments) {
|
||||
if (data.instruments[key] == inst_name) {
|
||||
tag = key;
|
||||
if (data.instruments[key] == name) {
|
||||
name = key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
name = name.replace(" ", "_");
|
||||
|
||||
if (!tag) {
|
||||
tag = inst_name;
|
||||
}
|
||||
const prefix = (selected == "inst") ? "" : selected + ":";
|
||||
|
||||
if (n) {
|
||||
tag += "-" + n;
|
||||
}
|
||||
return tag;
|
||||
case "page":
|
||||
return "page-" + document.querySelector("#add-tag-page").value;
|
||||
}
|
||||
const tag = (n) ? prefix + name + "-" + n : prefix + name;
|
||||
|
||||
closeTagModal();
|
||||
tagModalCallback(tag);
|
||||
}
|
||||
|
||||
|
||||
function createNewTag() {
|
||||
|
||||
const tag = generateNewTag()
|
||||
|
||||
function createNewTag(tag) {
|
||||
addTag(tag, pageNum, pageNum);
|
||||
closeAddModal();
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
function assignTag(tag, el) {
|
||||
@ -480,6 +490,16 @@
|
||||
//el.remove();
|
||||
}
|
||||
|
||||
function editTag(e) {
|
||||
console.log("EDIT", e.target);
|
||||
showTagModal((tag) => {
|
||||
console.log("Updating to " + tag);
|
||||
e.target.innerHTML = get_tag_name(tag);
|
||||
e.target.parentNode.dataset["tag"] = tag;
|
||||
dirty = true;
|
||||
}, e.target.parentNode.dataset["tag"]);
|
||||
}
|
||||
|
||||
function addTag(tag, start, end) {
|
||||
|
||||
|
||||
@ -489,13 +509,15 @@
|
||||
const tagName = el.querySelector(".tag-name");
|
||||
tagName.innerHTML=get_tag_name(tag);
|
||||
|
||||
tagName.addEventListener('dblclick', editTag);
|
||||
|
||||
//el.className = 'grid-tag';
|
||||
el.dataset.start = start;
|
||||
el.dataset.end = end;
|
||||
el.dataset.tag = tag;
|
||||
|
||||
const parts = tag.split("-")
|
||||
el.classList.add("tag-type-" + parts[0]);
|
||||
const parts = parseTag(tag)
|
||||
el.classList.add("tag-type-" + parts.prefix);
|
||||
|
||||
|
||||
const handle = el.querySelector('.tag-handle');
|
||||
@ -674,7 +696,7 @@
|
||||
onPrevPage();
|
||||
break;
|
||||
case "n":
|
||||
showAddModal();
|
||||
showTagModal(createNewTag);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@ -712,13 +734,43 @@
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
function get_tag_name(s) {
|
||||
let parts = s.split('-');
|
||||
let instrument = data.instruments[parts[0]] || parts[0];
|
||||
function parseTag(tag) {
|
||||
const result = {
|
||||
prefix: "inst",
|
||||
name: "",
|
||||
number: "",
|
||||
};
|
||||
|
||||
let parts = tag.split(":");
|
||||
if(parts.length == 2) {
|
||||
return instrument + " " + parts[1];
|
||||
result.prefix = parts[0];
|
||||
tag = parts[1];
|
||||
}
|
||||
return instrument;
|
||||
|
||||
parts = tag.split('-');
|
||||
if(parts.length == 2) {
|
||||
result.number = parts[1];
|
||||
}
|
||||
result.name = parts[0];
|
||||
|
||||
if(result.prefix == "inst") {
|
||||
result.name = data.instruments[result.name] || result.name;
|
||||
}
|
||||
|
||||
result.name = result.name.replace("_", " ");
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
function get_tag_name(s) {
|
||||
|
||||
tag = parseTag(s);
|
||||
console.log(tag);
|
||||
|
||||
let prefix = (tag.prefix == "inst") ? "" : data.prefixes[tag.prefix] + " ";
|
||||
|
||||
return (tag.number) ? prefix + tag.name + " " + tag.number : prefix + tag.name;
|
||||
}
|
||||
|
||||
function checkSaved(e) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from doctest import DocTestSuite
|
||||
|
||||
from library import music_tags
|
||||
from polyphonic.library import music_tags
|
||||
|
||||
|
||||
def load_tests(loader, tests, ignore):
|
||||
|
||||
@ -20,7 +20,13 @@ import string
|
||||
from polyphonic.interface.views import ProjectMixin, AuthorizedResourceMixin
|
||||
from polyphonic.interface.utils import signed_url
|
||||
from polyphonic.library.models import Collection, Work, Document, Section
|
||||
from polyphonic.library.music_tags import MUSIC_TAGS, MusicTag
|
||||
from polyphonic.library.music_tags import (
|
||||
MUSIC_TAGS,
|
||||
MUSIC_NAME_BY_TAG,
|
||||
TAG_PREFIXES,
|
||||
TAG_ALIASES,
|
||||
MusicTag,
|
||||
)
|
||||
from polyphonic.library import forms, models
|
||||
from polyphonic.library.pdf_utils import extract_pages, extract_and_concat
|
||||
from polyphonic.library.indexer import index_works, model_search
|
||||
@ -85,7 +91,7 @@ class ProjectItemListView(ProjectMixin, ListView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super(ProjectItemListView, self).get_context_data(**kwargs)
|
||||
data["instruments"] = MUSIC_TAGS
|
||||
data["instruments"] = TAG_ALIASES
|
||||
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"))[
|
||||
@ -281,6 +287,26 @@ class CollectionWorkListView(WorkListView):
|
||||
return data
|
||||
|
||||
|
||||
class ProjectWorkListView(WorkListView, ProjectMixin):
|
||||
def is_authorized(self):
|
||||
return ProjectMixin.is_authorized(self)
|
||||
|
||||
def get_works(self):
|
||||
collections = self.get_collections() or []
|
||||
print(collections)
|
||||
return Work.objects.filter(collection_id__in=collections)
|
||||
|
||||
def get_collections(self):
|
||||
return self.project.ensemble.allowed_collections.values_list(
|
||||
"collection_id", flat=True
|
||||
)
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
data = super(ProjectWorkListView, self).get_context_data(*args, **kwargs)
|
||||
data["title"] = f"Library for {self.project.ensemble}"
|
||||
return data
|
||||
|
||||
|
||||
class WorkAddView(CollectionMixin, FormView):
|
||||
template_name = "interface/default_form.html"
|
||||
form_class = forms.WorkCreateForm
|
||||
@ -603,7 +629,12 @@ class DocumentAnnotateView(DocumentMixin, DetailView):
|
||||
("sect", "success"),
|
||||
]
|
||||
|
||||
data["json_data"] = {"pageTags": pages, "instruments": dict(MUSIC_TAGS)}
|
||||
data["json_data"] = {
|
||||
"pageTags": pages,
|
||||
"instruments": MUSIC_NAME_BY_TAG,
|
||||
"instrumentNames": list({x[1] for x in MUSIC_TAGS}),
|
||||
"prefixes": TAG_PREFIXES,
|
||||
}
|
||||
return data
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user