|
28 | 28 | WorkflowStatusChoices,
|
29 | 29 | )
|
30 | 30 | from .models.pattern import (
|
| 31 | + DivisionPattern, |
31 | 32 | DocumentTypePattern,
|
32 | 33 | ExcludePattern,
|
33 | 34 | IncludePattern,
|
|
39 | 40 | CandidateURLSerializer,
|
40 | 41 | CollectionReadSerializer,
|
41 | 42 | CollectionSerializer,
|
| 43 | + DivisionPatternSerializer, |
42 | 44 | DocumentTypePatternSerializer,
|
43 | 45 | ExcludePatternSerializer,
|
44 | 46 | IncludePatternSerializer,
|
45 | 47 | TitlePatternSerializer,
|
46 |
| - WorkflowHistorySerializer, |
47 | 48 | )
|
48 | 49 | from .tasks import push_to_github_task
|
49 | 50 | from .utils.health_check import generate_db_github_metadata_differences
|
@@ -156,15 +157,15 @@ def get_context_data(self, **kwargs):
|
156 | 157 | timeline_history[history.workflow_status] = history
|
157 | 158 |
|
158 | 159 | # Add placeholders for stages with no workflow history
|
159 |
| - for status in WorkflowStatusChoices: |
160 |
| - if status not in timeline_history: |
161 |
| - timeline_history[status] = { |
162 |
| - "workflow_status": status, |
| 160 | + for workflow_status in WorkflowStatusChoices: |
| 161 | + if workflow_status not in timeline_history: |
| 162 | + timeline_history[workflow_status] = { |
| 163 | + "workflow_status": workflow_status, |
163 | 164 | "created_at": None,
|
164 |
| - "label": WorkflowStatusChoices(status).label, |
| 165 | + "label": WorkflowStatusChoices(workflow_status).label, |
165 | 166 | }
|
166 | 167 |
|
167 |
| - context["timeline_history"] = [timeline_history[status] for status in WorkflowStatusChoices] |
| 168 | + context["timeline_history"] = [timeline_history[workflow_status] for workflow_status in WorkflowStatusChoices] |
168 | 169 | context["required_urls"] = RequiredUrls.objects.filter(collection=self.get_object())
|
169 | 170 | context["segment"] = "collection-detail"
|
170 | 171 | context["comments"] = Comments.objects.filter(collection=self.get_object()).order_by("-created_at")
|
@@ -220,6 +221,7 @@ def get_context_data(self, **kwargs):
|
220 | 221 | ) # 2=regex patterns
|
221 | 222 | context["title_patterns"] = self.collection.titlepattern.all()
|
222 | 223 | context["workflow_status_choices"] = WorkflowStatusChoices
|
| 224 | + context["is_multi_division"] = self.collection.is_multi_division |
223 | 225 |
|
224 | 226 | return context
|
225 | 227 |
|
@@ -272,6 +274,15 @@ def get_queryset(self):
|
272 | 274 | queryset = self._filter_by_is_excluded(queryset, is_excluded)
|
273 | 275 | return queryset.order_by("url")
|
274 | 276 |
|
| 277 | + def update_division(self, request, pk=None): |
| 278 | + candidate_url = get_object_or_404(CandidateURL, pk=pk) |
| 279 | + division = request.data.get("division") |
| 280 | + if division: |
| 281 | + candidate_url.division = division |
| 282 | + candidate_url.save() |
| 283 | + return Response(status=status.HTTP_200_OK) |
| 284 | + return Response(status=status.HTTP_400_BAD_REQUEST, data={"error": "Division is required."}) |
| 285 | + |
275 | 286 |
|
276 | 287 | class CandidateURLBulkCreateView(generics.ListCreateAPIView):
|
277 | 288 | queryset = CandidateURL.objects.all()
|
@@ -386,6 +397,21 @@ def create(self, request, *args, **kwargs):
|
386 | 397 | return Response(status=status.HTTP_204_NO_CONTENT)
|
387 | 398 |
|
388 | 399 |
|
| 400 | +class DivisionPatternViewSet(CollectionFilterMixin, viewsets.ModelViewSet): |
| 401 | + queryset = DivisionPattern.objects.all() |
| 402 | + serializer_class = DivisionPatternSerializer |
| 403 | + |
| 404 | + def get_queryset(self): |
| 405 | + return super().get_queryset().order_by("match_pattern") |
| 406 | + |
| 407 | + def create(self, request, *args, **kwargs): |
| 408 | + division = request.POST.get("division") |
| 409 | + if division: |
| 410 | + return super().create(request, *args, **kwargs) |
| 411 | + else: |
| 412 | + return Response(status=status.HTTP_400_BAD_REQUEST, data={"error": "Division is required."}) |
| 413 | + |
| 414 | + |
389 | 415 | class CollectionViewSet(viewsets.ModelViewSet):
|
390 | 416 | queryset = Collection.objects.all()
|
391 | 417 | serializer_class = CollectionSerializer
|
|
0 commit comments