Skip to content

Commit 126148c

Browse files
made views for division patterns
1 parent a89e3f5 commit 126148c

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

sde_collections/views.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
WorkflowStatusChoices,
2929
)
3030
from .models.pattern import (
31+
DivisionPattern,
3132
DocumentTypePattern,
3233
ExcludePattern,
3334
IncludePattern,
@@ -39,11 +40,11 @@
3940
CandidateURLSerializer,
4041
CollectionReadSerializer,
4142
CollectionSerializer,
43+
DivisionPatternSerializer,
4244
DocumentTypePatternSerializer,
4345
ExcludePatternSerializer,
4446
IncludePatternSerializer,
4547
TitlePatternSerializer,
46-
WorkflowHistorySerializer,
4748
)
4849
from .tasks import push_to_github_task
4950
from .utils.health_check import generate_db_github_metadata_differences
@@ -156,15 +157,15 @@ def get_context_data(self, **kwargs):
156157
timeline_history[history.workflow_status] = history
157158

158159
# 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,
163164
"created_at": None,
164-
"label": WorkflowStatusChoices(status).label,
165+
"label": WorkflowStatusChoices(workflow_status).label,
165166
}
166167

167-
context["timeline_history"] = [timeline_history[status] for status in WorkflowStatusChoices]
168+
context["timeline_history"] = [timeline_history[workflow_status] for workflow_status in WorkflowStatusChoices]
168169
context["required_urls"] = RequiredUrls.objects.filter(collection=self.get_object())
169170
context["segment"] = "collection-detail"
170171
context["comments"] = Comments.objects.filter(collection=self.get_object()).order_by("-created_at")
@@ -220,12 +221,12 @@ def get_context_data(self, **kwargs):
220221
) # 2=regex patterns
221222
context["title_patterns"] = self.collection.titlepattern.all()
222223
context["workflow_status_choices"] = WorkflowStatusChoices
224+
context["is_multi_division"] = self.collection.is_multi_division
223225

224226
return context
225227

226228

227229
class SdeDashboardView(LoginRequiredMixin, ListView):
228-
229230
model = Collection
230231
template_name = "sde_collections/sde_dashboard.html"
231232
context_object_name = "collections"
@@ -273,6 +274,15 @@ def get_queryset(self):
273274
queryset = self._filter_by_is_excluded(queryset, is_excluded)
274275
return queryset.order_by("url")
275276

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+
276286

277287
class CandidateURLBulkCreateView(generics.ListCreateAPIView):
278288
queryset = CandidateURL.objects.all()
@@ -387,6 +397,21 @@ def create(self, request, *args, **kwargs):
387397
return Response(status=status.HTTP_204_NO_CONTENT)
388398

389399

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+
390415
class CollectionViewSet(viewsets.ModelViewSet):
391416
queryset = Collection.objects.all()
392417
serializer_class = CollectionSerializer

0 commit comments

Comments
 (0)