From b003aa6abb2c81d8eac70fbe3e8f8c8b36bdc0a9 Mon Sep 17 00:00:00 2001 From: Ashish Acharya Date: Fri, 16 Aug 2024 11:53:26 -0500 Subject: [PATCH 1/2] Add unique basenames to collection routers --- sde_collections/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sde_collections/urls.py b/sde_collections/urls.py index 7c17feb1..c2965c83 100644 --- a/sde_collections/urls.py +++ b/sde_collections/urls.py @@ -6,8 +6,8 @@ from . import views router = routers.DefaultRouter() -router.register(r"collections", views.CollectionViewSet) -router.register(r"collections-read", views.CollectionReadViewSet) +router.register(r"collections", views.CollectionViewSet, basename="collection") +router.register(r"collections-read", views.CollectionReadViewSet, basename="collection-read") router.register(r"candidate-urls", views.CandidateURLViewSet) router.register(r"exclude-patterns", views.ExcludePatternViewSet) router.register(r"include-patterns", views.IncludePatternViewSet) From 5156c4423a6a0120830c1b151e5e3f64b6cd266b Mon Sep 17 00:00:00 2001 From: Ashish Acharya Date: Fri, 16 Aug 2024 11:53:50 -0500 Subject: [PATCH 2/2] Fix linting --- sde_collections/views.py | 43 ++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/sde_collections/views.py b/sde_collections/views.py index 770ee78d..1a939140 100644 --- a/sde_collections/views.py +++ b/sde_collections/views.py @@ -19,7 +19,7 @@ from .forms import CollectionGithubIssueForm, CommentsForm, RequiredUrlForm from .models.candidate_url import CandidateURL, ResolvedTitle, ResolvedTitleError -from .models.collection import Collection, Comments, RequiredUrls,WorkflowHistory +from .models.collection import Collection, Comments, RequiredUrls, WorkflowHistory from .models.collection_choice_fields import ( ConnectorChoices, CurationStatusChoices, @@ -140,13 +140,17 @@ def get_context_data(self, **kwargs): ) if "comments_form" not in context: context["comments_form"] = CommentsForm() - + # Initialize a dictionary to hold the most recent history for each workflow status timeline_history = {} - + # Get the most recent history for each workflow status - recent_histories = WorkflowHistory.objects.filter(collection=self.get_object()).order_by('workflow_status', '-created_at').distinct('workflow_status') - + recent_histories = ( + WorkflowHistory.objects.filter(collection=self.get_object()) + .order_by("workflow_status", "-created_at") + .distinct("workflow_status") + ) + # Populate the dictionary with the actual history objects for history in recent_histories: timeline_history[history.workflow_status] = history @@ -155,20 +159,23 @@ def get_context_data(self, **kwargs): for status in WorkflowStatusChoices: if status not in timeline_history: timeline_history[status] = { - 'workflow_status': status, - 'created_at': None, - 'label': WorkflowStatusChoices(status).label, + "workflow_status": status, + "created_at": None, + "label": WorkflowStatusChoices(status).label, } - - context['timeline_history'] = [timeline_history[status] for status in WorkflowStatusChoices] + + context["timeline_history"] = [timeline_history[status] for status in WorkflowStatusChoices] context["required_urls"] = RequiredUrls.objects.filter(collection=self.get_object()) context["segment"] = "collection-detail" context["comments"] = Comments.objects.filter(collection=self.get_object()).order_by("-created_at") - context["workflow_history"] = WorkflowHistory.objects.filter(collection=self.get_object()).order_by('-created_at') + context["workflow_history"] = WorkflowHistory.objects.filter(collection=self.get_object()).order_by( + "-created_at" + ) context["workflow_status_choices"] = WorkflowStatusChoices return context + class RequiredUrlsDeleteView(LoginRequiredMixin, DeleteView): model = RequiredUrls @@ -216,17 +223,15 @@ def get_context_data(self, **kwargs): return context -class SdeDashboardView(LoginRequiredMixin,ListView ): - + +class SdeDashboardView(LoginRequiredMixin, ListView): + model = Collection template_name = "sde_collections/sde_dashboard.html" context_object_name = "collections" def get_queryset(self): - return ( - super() - .get_queryset() - ) + return super().get_queryset() def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -234,7 +239,6 @@ def get_context_data(self, **kwargs): return context - class CollectionFilterMixin: def get_queryset(self): if not self.request.method == "GET": @@ -387,12 +391,13 @@ class CollectionViewSet(viewsets.ModelViewSet): queryset = Collection.objects.all() serializer_class = CollectionSerializer + class CollectionReadViewSet(viewsets.ReadOnlyModelViewSet): queryset = Collection.objects.all() serializer_class = CollectionReadSerializer -class PushToGithubView(APIView): +class PushToGithubView(APIView): def post(self, request): collection_ids = request.POST.getlist("collection_ids[]", []) if len(collection_ids) == 0: