From 1646bac2cb87f45f2e864e16d45e65f31249c0a5 Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 2 Apr 2022 22:34:14 +0100 Subject: [PATCH] . --- atlas/filters.py | 31 +++++++++++++++++++++++++ atlas/tables.py | 40 +++++++++++++++++++++++++++++++++ atlas/templates/atlas/base.html | 2 +- atlas/urls.py | 2 +- atlas/views.py | 20 ++++++++++++----- 5 files changed, 87 insertions(+), 8 deletions(-) diff --git a/atlas/filters.py b/atlas/filters.py index 29d2ffb3..17072095 100755 --- a/atlas/filters.py +++ b/atlas/filters.py @@ -46,6 +46,37 @@ def get_series(request): return queryset +class CaseCollectionFilter(django_filters.FilterSet): + author = django_filters.ModelMultipleChoiceFilter( + queryset=get_authors, null_label="No author" + ) + cases = django_filters.ModelMultipleChoiceFilter( + queryset=get_cases, null_label="No cases" + ) + + class Meta: + model = Case + fields = ( + "archive", + "author", + ) # "site", + + def __init__( + self, + data=None, + queryset=None, + prefix=None, + strict=None, + user=None, + request=None, + ): + if not request.user.groups.filter(name="atlas_editor").exists(): + queryset = queryset.prefetch_related("author").filter(author__id=request.user.id) + super(CaseCollectionFilter, self).__init__( + data=data, queryset=queryset, prefix=prefix, request=request + ) + pass + class CaseFilter(django_filters.FilterSet): author = django_filters.ModelMultipleChoiceFilter( queryset=get_authors, null_label="No author" diff --git a/atlas/tables.py b/atlas/tables.py index 577bb5bc..82a7cf9f 100755 --- a/atlas/tables.py +++ b/atlas/tables.py @@ -313,3 +313,43 @@ class SubspecialtyTable(tables.Table): def render_synonym(self, value, record): return format_html(record.get_synonym_link()) return f"{record.get_synonym_link()}" + +class CaseCollectionTable(tables.Table): + edit = tables.LinkColumn( + "atlas:collection_update", text="Edit", args=[A("pk")], orderable=False + ) + view = tables.LinkColumn( + "atlas:collection_view", text="View", args=[A("pk")], orderable=False + ) + #clone = tables.LinkColumn( + # "atlas:case_clone", text="Clone", args=[A("pk")], orderable=False + #) + delete = tables.LinkColumn( + "atlas:collection_delete", text="Delete", args=[A("pk")], orderable=False + ) + #series = AtlasImageColumn("Images", orderable=False) + + #differential = tables.ManyToManyColumn(verbose_name="Differential") + + selection = tables.CheckBoxColumn(accessor="pk", orderable=False) + + class Meta: + model = Case + template_name = "django_tables2/bootstrap4.html" + fields = ( + "name", + "collection_type", + "publish_results", + "active", + "author", + ) + sequence = ("view", )#, "series") + + def __init__(self, data=None, *args, **kwargs): + super().__init__( + data.prefetch_related( + #"condition", "condition__synonym" + ), + *args, + **kwargs, + ) \ No newline at end of file diff --git a/atlas/templates/atlas/base.html b/atlas/templates/atlas/base.html index a2f7d33e..81ea8489 100755 --- a/atlas/templates/atlas/base.html +++ b/atlas/templates/atlas/base.html @@ -19,7 +19,7 @@ Atlas: {% if request.user.is_authenticated %} Cases / Series / -Collections / +Collections / Categories / Create Case / Create Series diff --git a/atlas/urls.py b/atlas/urls.py index 81a6207b..f8bcf72a 100755 --- a/atlas/urls.py +++ b/atlas/urls.py @@ -13,7 +13,7 @@ urlpatterns = [ path("author//", views.author_detail, name="author_detail"), path("author/", views.author_list, name="author_list"), path("case/", views.CaseView.as_view(), name="case_view"), - path("collection/", views.collection_index_view, name="collection_index_view"), + path("collection/", views.CollectionView.as_view(), name="collection_view"), path("collection/create", views.CaseCollectionCreate.as_view(), name="collection_create"), path("collection//delete", views.CaseCollectionDelete.as_view(), name="collection_delete"), path("collection//update", views.CaseCollectionUpdate.as_view(), name="collection_update"), diff --git a/atlas/views.py b/atlas/views.py index 440b7303..ee14f8b1 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -60,7 +60,9 @@ from .models import ( SeriesImage, ) from .tables import ( + CaseCollectionTable, CaseTable, + CollectionTable, ConditionTable, FindingTable, PathologicalProcessTable, @@ -308,7 +310,7 @@ class SeriesDelete(RevisionMixin, AuthorOrCheckerRequiredMixin, DeleteView): class CaseCollectionDelete(RevisionMixin, AuthorOrCheckerRequiredMixin, DeleteView): model = CaseCollection template_name = "confirm_delete.html" - success_url = reverse_lazy("atlas:collection_index_view") + success_url = reverse_lazy("atlas:collection_view") class ConditionDelete(RevisionMixin, AuthorOrCheckerRequiredMixin, DeleteView): model = Condition @@ -1041,12 +1043,18 @@ def categories_list(request): ) -def collection_index_view(request): - collections = CaseCollection.objects.all() +#def collection_view(request): +# collections = CaseCollection.objects.all() +# +# return render( +# request, "atlas/collection_view.html", {"collections": collections} +# ) +class CollectionView(LoginRequiredMixin, SingleTableMixin, FilterView): + model = CaseCollection + table_class = CaseCollectionTable + template_name = "atlas/view.html" - return render( - request, "atlas/collection_index_view.html", {"collections": collections} - ) + filterset_class = CollectionFilter def collection_detail_view(request, pk):