diff --git a/atlas/templates/atlas/collection_view.html b/atlas/templates/atlas/collection_view.html new file mode 100644 index 00000000..ae5116cb --- /dev/null +++ b/atlas/templates/atlas/collection_view.html @@ -0,0 +1,22 @@ +{% extends 'atlas/base.html' %} + +{% load render_table from django_tables2 %} + +{% block content %} + +
+
+

Collections

+ {% if request.user.is_staff %} + Create collection + {% endif %} +
+ +

Manage and browse case collections. Use filters to narrow results.

+ + {% render_table table %} + + {% include "generic/partials/filter_bar.html" with filter=filter app_name=app_name collapse_id="bottom-filter-body" %} +
+ +{% endblock %} diff --git a/atlas/templates/atlas/view.html b/atlas/templates/atlas/view.html index 1858a25c..35ce4933 100755 --- a/atlas/templates/atlas/view.html +++ b/atlas/templates/atlas/view.html @@ -7,7 +7,14 @@ {% block content %}
-

My Collections

+
+

{{ model_verbose_name_plural|capfirst }}

+ {% if request.user.is_staff and create_url %} +
+ Add new {{ model_verbose_name }} +
+ {% endif %} +
{% comment %}

Filter

@@ -19,7 +26,6 @@
{% endcomment %} - View my cases. {% render_table table %} {% include "generic/partials/filter_bar.html" with filter=filter app_name=app_name collapse_id="bottom-filter-body" %} diff --git a/atlas/views.py b/atlas/views.py index 6954c550..d9574abd 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -40,6 +40,7 @@ from .tables import ResourceTable from django.views.decorators.csrf import csrf_exempt from django.urls import reverse_lazy, reverse +from django.urls.exceptions import NoReverseMatch from django.http import Http404, JsonResponse from django.http import HttpResponseRedirect, HttpResponse @@ -2119,6 +2120,17 @@ class ConditionView(LoginRequiredMixin, UserConfigurablePaginationMixin, SingleT filterset_class = ConditionFilter + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + try: + ctx["create_url"] = reverse(f"atlas:{self.model._meta.model_name}_create") + except NoReverseMatch: + ctx["create_url"] = None + # Provide verbose names to templates without accessing _meta in templates + ctx["model_verbose_name"] = getattr(self.model._meta, "verbose_name", None) + ctx["model_verbose_name_plural"] = getattr(self.model._meta, "verbose_name_plural", None) + return ctx + class QuestionSchemaView(LoginRequiredMixin, UserConfigurablePaginationMixin, SingleTableMixin, FilterView): model = QuestionSchema @@ -2135,6 +2147,16 @@ class SubspecialtyView(LoginRequiredMixin, UserConfigurablePaginationMixin, Sing filterset_class = SubspecialtyFilter + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + try: + ctx["create_url"] = reverse(f"atlas:{self.model._meta.model_name}_create") + except NoReverseMatch: + ctx["create_url"] = None + ctx["model_verbose_name"] = getattr(self.model._meta, "verbose_name", None) + ctx["model_verbose_name_plural"] = getattr(self.model._meta, "verbose_name_plural", None) + return ctx + class PresentationView(LoginRequiredMixin, UserConfigurablePaginationMixin, SingleTableMixin, FilterView): model = Presentation @@ -2143,6 +2165,16 @@ class PresentationView(LoginRequiredMixin, UserConfigurablePaginationMixin, Sing filterset_class = PresentationFilter + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + try: + ctx["create_url"] = reverse(f"atlas:{self.model._meta.model_name}_create") + except NoReverseMatch: + ctx["create_url"] = None + ctx["model_verbose_name"] = getattr(self.model._meta, "verbose_name", None) + ctx["model_verbose_name_plural"] = getattr(self.model._meta, "verbose_name_plural", None) + return ctx + class PathologicalProcessView(LoginRequiredMixin, UserConfigurablePaginationMixin, SingleTableMixin, FilterView): model = PathologicalProcess @@ -2151,6 +2183,16 @@ class PathologicalProcessView(LoginRequiredMixin, UserConfigurablePaginationMixi filterset_class = PathologicalProcessFilter + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + try: + ctx["create_url"] = reverse(f"atlas:{self.model._meta.model_name}_create") + except NoReverseMatch: + ctx["create_url"] = None + ctx["model_verbose_name"] = getattr(self.model._meta, "verbose_name", None) + ctx["model_verbose_name_plural"] = getattr(self.model._meta, "verbose_name_plural", None) + return ctx + class StructureView(LoginRequiredMixin, UserConfigurablePaginationMixin, SingleTableMixin, FilterView): model = Structure @@ -2159,6 +2201,16 @@ class StructureView(LoginRequiredMixin, UserConfigurablePaginationMixin, SingleT filterset_class = StructureFilter + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + try: + ctx["create_url"] = reverse(f"atlas:{self.model._meta.model_name}_create") + except NoReverseMatch: + ctx["create_url"] = None + ctx["model_verbose_name"] = getattr(self.model._meta, "verbose_name", None) + ctx["model_verbose_name_plural"] = getattr(self.model._meta, "verbose_name_plural", None) + return ctx + class FindingView(LoginRequiredMixin, UserConfigurablePaginationMixin, SingleTableMixin, FilterView): model = Finding @@ -2167,6 +2219,14 @@ class FindingView(LoginRequiredMixin, UserConfigurablePaginationMixin, SingleTab filterset_class = FindingFilter + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + try: + ctx["create_url"] = reverse(f"atlas:{self.model._meta.model_name}_create") + except NoReverseMatch: + ctx["create_url"] = None + return ctx + @login_required def case_order_dicom(request, pk): @@ -2527,7 +2587,7 @@ def categories_search_partial(request): class CollectionView(LoginRequiredMixin, SingleTableMixin, FilterView): model = CaseCollection table_class = CaseCollectionTable - template_name = "atlas/view.html" + template_name = "atlas/collection_view.html" filterset_class = CaseCollectionFilter