Fixed reference to section type
This commit is contained in:
parent
f840ee3d8b
commit
70aa7ae3a3
@ -232,12 +232,11 @@ class EnsembleDetailView(EnsembleMixin, DetailView):
|
|||||||
if inactive:
|
if inactive:
|
||||||
projects = projects.order_by('-pk')
|
projects = projects.order_by('-pk')
|
||||||
else:
|
else:
|
||||||
projects = projects.filter(active=True, event_date__gte=timezone.now()-timezone.timedelta(7))
|
projects = projects.active().current()
|
||||||
|
|
||||||
data['inactive'] = inactive
|
data['inactive'] = inactive
|
||||||
data['object_list'] = projects
|
data['object_list'] = projects
|
||||||
if self.request.is_admin:
|
if self.request.is_admin:
|
||||||
#data['ensemble_link'] = signed_url(f'{self.request.path}?nonce={self.ensemble.nonce}')
|
|
||||||
data['ensemble_link'] = self.request.path + "?auth=" + self.ensemble.auth()
|
data['ensemble_link'] = self.request.path + "?auth=" + self.ensemble.auth()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
@ -276,7 +276,7 @@ class Work(models.Model):
|
|||||||
return f"{composer[:4]}-{work}-{self.pk:05d}".upper()
|
return f"{composer[:4]}-{work}-{self.pk:05d}".upper()
|
||||||
|
|
||||||
def assigned_instruments(self):
|
def assigned_instruments(self):
|
||||||
return Section.objects.filter(doc__work_id=self.pk, type=Section.TYPE_INSTRUMENT).values_list('tag', flat=True)
|
return Section.objects.filter(doc__work_id=self.pk).values_list('tag', flat=True)
|
||||||
|
|
||||||
def unassigned_instruments(self):
|
def unassigned_instruments(self):
|
||||||
assigned = set(self.assigned_instruments())
|
assigned = set(self.assigned_instruments())
|
||||||
|
|||||||
@ -3,6 +3,7 @@ from interface.tests import AccessTestCase
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from interface.models import Ensemble, Project
|
from interface.models import Ensemble, Project
|
||||||
from . import models
|
from . import models
|
||||||
|
from .views.api import WorkSerializer
|
||||||
|
|
||||||
class LibraryTestCase(AccessTestCase):
|
class LibraryTestCase(AccessTestCase):
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ class LibraryTestCase(AccessTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
WORKS = (
|
WORKS = (
|
||||||
{'name': 'Baby on Board', 'collection': 'ned'},
|
{'name': 'Baby on Board', 'collection': 'ned', 'docs': [{'upload': 'local:baby_on_board.pdf'}]},
|
||||||
)
|
)
|
||||||
|
|
||||||
PROTECTED_URLS = (
|
PROTECTED_URLS = (
|
||||||
@ -41,6 +42,7 @@ class LibraryTestCase(AccessTestCase):
|
|||||||
'/collections/2/works/1/partset',
|
'/collections/2/works/1/partset',
|
||||||
'/collections/2/works/1/add_to_project',
|
'/collections/2/works/1/add_to_project',
|
||||||
'/collections/2/works/1/upload',
|
'/collections/2/works/1/upload',
|
||||||
|
'/collections/2/docs/1/annotate',
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -57,8 +59,20 @@ class LibraryTestCase(AccessTestCase):
|
|||||||
|
|
||||||
cls.works = {}
|
cls.works = {}
|
||||||
for details in cls.WORKS:
|
for details in cls.WORKS:
|
||||||
collection = details.pop('collection')
|
collection = cls.collections[details.pop('collection')]
|
||||||
cls.works[details['name']] = models.Work.objects.create(collection=cls.collections[collection], **details)
|
#details.setdefault('docs', [])
|
||||||
|
#details.setdefault('meta_info', [])
|
||||||
|
#s = WorkSerializer(data=details)
|
||||||
|
#assert s.is_valid(), s.errors
|
||||||
|
#s.save(collection_id=collection.pk)
|
||||||
|
docs = details.pop('docs', [])
|
||||||
|
obj = models.Work.objects.create(collection=collection, **details)
|
||||||
|
for doc in docs:
|
||||||
|
obj.docs.create(**doc)
|
||||||
|
cls.works[details['name']] = obj
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def oldSetUp(self):
|
def oldSetUp(self):
|
||||||
self.homer = User.objects.create(username='homer')
|
self.homer = User.objects.create(username='homer')
|
||||||
|
|||||||
@ -35,8 +35,8 @@ urlpatterns = [
|
|||||||
path('collections/<int:collection>/download/<int:section>/<str:filename>', views.PartDownloadView.as_view(), name="part_download"),
|
path('collections/<int:collection>/download/<int:section>/<str:filename>', views.PartDownloadView.as_view(), name="part_download"),
|
||||||
|
|
||||||
#path('api/', include(router.urls))
|
#path('api/', include(router.urls))
|
||||||
path('api/library/collections/<int:pk>/export', api.CollectionExportView.as_view(), name="collection_export"),
|
path('api/collections/<int:collection>', api.CollectionExportView.as_view(), name="collection_export"),
|
||||||
path('api/library/works/<int:pk>/export', api.WorkExportView.as_view(), name="work_export"),
|
path('api/collections/<int:collection>/works/<int:pk>', api.WorkExportView.as_view(), name="work_export"),
|
||||||
path('api/library/collections/<int:pk>/import', api.WorkImportView.as_view(), name="work_import"),
|
path('api/collections/<int:collection>/import', api.WorkImportView.as_view(), name="work_import"),
|
||||||
path('api/library/collections/<int:pk>/bulk_import', api.CollectionImportView.as_view(), name="collection_import"),
|
path('api/collections/<int:collection>/bulk_import', api.CollectionImportView.as_view(), name="collection_import"),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -83,9 +83,8 @@ class SectionSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class DocumentSerializer(serializers.ModelSerializer):
|
class DocumentSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
upload = serializers.URLField()
|
upload = serializers.CharField()
|
||||||
sections = SectionSerializer(many=True)
|
sections = SectionSerializer(many=True)
|
||||||
#doctype = serializers.CharField(source='get_doctype_display')
|
|
||||||
|
|
||||||
#def to_internal_value(self, data):
|
#def to_internal_value(self, data):
|
||||||
# r = requests.get(data['upload'], stream=True)
|
# r = requests.get(data['upload'], stream=True)
|
||||||
@ -97,8 +96,7 @@ class DocumentSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
data = super().to_representation(instance)
|
data = super().to_representation(instance)
|
||||||
if data['upload'][0] == '/':
|
data['upload'] = instance.upload.url
|
||||||
data['upload'] = 'http://localhost:8000' + (data['upload'])
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
@ -169,6 +167,7 @@ from rest_framework import generics
|
|||||||
|
|
||||||
class CollectionExportView(AuthorizedResourceMixin, generics.RetrieveAPIView):
|
class CollectionExportView(AuthorizedResourceMixin, generics.RetrieveAPIView):
|
||||||
serializer_class = CollectionSerializer
|
serializer_class = CollectionSerializer
|
||||||
|
lookup_url_kwarg = 'collection'
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Collection.objects.filter(administrators=self.request.user)
|
return Collection.objects.filter(administrators=self.request.user)
|
||||||
@ -177,7 +176,7 @@ class WorkExportView(AuthorizedResourceMixin, generics.RetrieveAPIView):
|
|||||||
serializer_class = WorkSerializer
|
serializer_class = WorkSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Work.objects.filter(collection__administrators=self.request.user)
|
return Work.objects.filter(collection__administrators=self.request.user, collection=self.kwargs['collection'])
|
||||||
|
|
||||||
class WorkImportView(AuthorizedResourceMixin, generics.CreateAPIView):
|
class WorkImportView(AuthorizedResourceMixin, generics.CreateAPIView):
|
||||||
serializer_class = WorkSerializer
|
serializer_class = WorkSerializer
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user