diff --git a/app/library/templates/library/collection_list.html b/app/library/templates/library/collection_list.html index 8ba768c..59f15e7 100644 --- a/app/library/templates/library/collection_list.html +++ b/app/library/templates/library/collection_list.html @@ -3,6 +3,19 @@ {% block page %}

Library collections for {% firstof request.user.first_name request.user.username %}

+
+
+
+
+ +
+
+ +
+
+
+
+
{% for collection in object_list %}
diff --git a/app/library/templates/library/work_list.html b/app/library/templates/library/work_list.html index 1c61060..4117cef 100644 --- a/app/library/templates/library/work_list.html +++ b/app/library/templates/library/work_list.html @@ -29,7 +29,7 @@ Work Composer Edition - Collection + {% if not collection %}Collection{% endif %} {% if request.is_admin %} Copies {% endif %} @@ -41,7 +41,7 @@ {{ work.name }} {{ work.composer|truncatewords:3 }} {{ work.edition|truncatewords:2 }} - {{ work.collection.name }} + {% if not collection %}{{ work.collection.name }}{% endif %} {% if request.is_admin %} {{ work.available }} {% endif %} diff --git a/app/library/urls.py b/app/library/urls.py index 1a00ba8..3e2cb82 100644 --- a/app/library/urls.py +++ b/app/library/urls.py @@ -16,7 +16,7 @@ urlpatterns = [ path('projects//items/manage', views.ProjectItemManageView.as_view(), name="item_list_manage"), path('projects//items/append', views.ProjectItemAddView.as_view(), name="item_list_append"), - path('library', views.WorkListView.as_view(), name="work_list"), + path('library', views.LibraryWorkListView.as_view(), name="work_list"), path('collections', views.CollectionListView.as_view(), name="collection_list"), path('collections/', views.CollectionWorkListView.as_view(), name="collection_work_list"), diff --git a/app/library/views/__init__.py b/app/library/views/__init__.py index b069f44..a1b16ee 100644 --- a/app/library/views/__init__.py +++ b/app/library/views/__init__.py @@ -113,6 +113,9 @@ class ProjectItemAddView(ProjectMixin, UpdateView): """ COLLECTION VIEWS """ class CollectionMixin(AuthorizedResourceMixin): + + collection = None + def is_authorized(self): collection_id = self.kwargs['collection'] self.collection = get_object_or_404(models.Collection, pk=collection_id) @@ -155,18 +158,6 @@ 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') def get_context_data(self, *args, **kwargs): data = super(WorkListView, self).get_context_data(*args, **kwargs) @@ -185,10 +176,27 @@ class WorkListView(CollectionMixin, ListView): else: works = works.filter(Q(name__contains=q) | Q(composer__contains=q) | Q(meta_info__value__contains=q)) - return works.order_by('name', 'composer', 'edition', 'pk') + return works.order_by('name', 'composer', 'edition', 'pk').distinct() + +class LibraryWorkListView(WorkListView): + + def is_authorized(self): + return True + + def get_works(self): + collections = models.Collection.objects.filter(administrators=self.request.user) + return Work.objects.filter(collection__in=collections).select_related('collection') class CollectionWorkListView(WorkListView): + 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): works = Work.objects.filter(collection=self.kwargs['collection'])