Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique basenames to collection routers #949

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sde_collections/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 24 additions & 19 deletions sde_collections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -216,25 +223,22 @@ 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)
context["segment"] = "collections"
return context



class CollectionFilterMixin:
def get_queryset(self):
if not self.request.method == "GET":
Expand Down Expand Up @@ -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:
Expand Down