Got collection links working and tested
This commit is contained in:
@@ -9,6 +9,8 @@ from django.db import transaction
|
||||
from django.utils.timezone import now
|
||||
from django.urls import reverse
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.exceptions import SuspiciousOperation
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
|
||||
import json
|
||||
import os.path
|
||||
@@ -17,14 +19,10 @@ import re
|
||||
from interface.views import EnsembleMixin, ProjectMixin, AuthorizedResourceMixin
|
||||
from interface.models import Project
|
||||
from library.models import Collection, Work, Document, Section
|
||||
from library.imslp import INSTRUMENT_TAGS, INSTRUMENTS
|
||||
from library.music_tags import MUSIC_TAGS
|
||||
from library import forms, models
|
||||
from library.pdf_utils import extract_pages, extract_and_concat
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class ProjectItemListView(ProjectMixin, ListView):
|
||||
template_name = "library/item_list.html"
|
||||
@@ -72,7 +70,7 @@ class ProjectItemListView(ProjectMixin, ListView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super(ProjectItemListView, self).get_context_data(**kwargs)
|
||||
data['instruments'] = INSTRUMENTS
|
||||
data['instruments'] = MUSIC_TAGS
|
||||
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']
|
||||
@@ -129,7 +127,10 @@ class CollectionMixin(AuthorizedResourceMixin):
|
||||
if self.collection.has_administrator(self.request.user):
|
||||
self.request.is_admin = True
|
||||
return True
|
||||
|
||||
|
||||
if self.is_authorized_key('collection', collection_id, self.collection.nonce):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@@ -159,6 +160,14 @@ class CollectionListView(ListView):
|
||||
class WorkListView(CollectionMixin, ListView):
|
||||
paginate_by = 20
|
||||
|
||||
def request_denied(self):
|
||||
if 'auth' in self.request.GET:
|
||||
if self.request.GET['auth'] != self.collection.auth():
|
||||
raise SuspiciousOperation("Bad collection link")
|
||||
self.add_authorized_key('collection', self.collection.pk, self.collection.nonce)
|
||||
return HttpResponseRedirect(self.request.path)
|
||||
return super().request_denied()
|
||||
|
||||
def get_works(self):
|
||||
collections = CollectionMixin.get_queryset(self)
|
||||
return Work.objects.filter(collection__in=collections).select_related('collection')
|
||||
@@ -230,7 +239,7 @@ class WorkDetailView(CollectionMixin, DetailView):
|
||||
model = models.Work
|
||||
|
||||
class WorkUpdateView(CollectionMixin, UpdateView):
|
||||
#fields = ['name', 'composer', 'edition', 'code', 'orchestration', 'licence', 'max_projects', 'running_time', 'notes']
|
||||
model = models.Work
|
||||
form_class = forms.WorkCreateForm
|
||||
template_name = 'interface/default_form.html'
|
||||
|
||||
@@ -348,12 +357,10 @@ class DocumentMixin(CollectionMixin):
|
||||
model = models.Document
|
||||
|
||||
def get_queryset(self):
|
||||
return models.Document.objects.filter(work__collection=self.collection)
|
||||
|
||||
# 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')
|
||||
qs = models.Document.objects.select_related('work')
|
||||
if self.request.is_admin:
|
||||
return qs
|
||||
return qs.filter(work__collection=self.collection)
|
||||
|
||||
class DocumentDetailView(DocumentMixin, DetailView):
|
||||
pass
|
||||
@@ -395,7 +402,7 @@ class DocumentAnnotateView(DocumentMixin, DetailView):
|
||||
for part in data['document'].sections.all():
|
||||
pages.append((part.tag, part.start, part.end))
|
||||
|
||||
data['json_data'] = {'pageTags': pages, 'instruments': dict(INSTRUMENTS)}
|
||||
data['json_data'] = {'pageTags': pages, 'instruments': dict(MUSIC_TAGS)}
|
||||
return data
|
||||
|
||||
class DocumentDeleteView(DocumentMixin, DeleteView):
|
||||
|
||||
Reference in New Issue
Block a user