From d595fd761fae9f9287be27160ed9d3eebaded698 Mon Sep 17 00:00:00 2001 From: Tudor Amariei Date: Mon, 21 Oct 2024 12:43:29 +0300 Subject: [PATCH] Clean CandidateDetailView --- backend/hub/views.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/backend/hub/views.py b/backend/hub/views.py index 23b0285a..036645ba 100644 --- a/backend/hub/views.py +++ b/backend/hub/views.py @@ -475,17 +475,13 @@ class CandidateDetailView(HubDetailView): model = Candidate def get_queryset(self): - if ( - self.request.user - and self.request.user.groups.filter(name__in=[COMMITTEE_GROUP, STAFF_GROUP, SUPPORT_GROUP]).exists() - ): - return Candidate.objects_with_org.select_related("org").prefetch_related("domain").all() + user = self.request.user + candidat_base_queryset = Candidate.objects_with_org.select_related("org").prefetch_related("domain") - return ( - Candidate.objects_with_org.select_related("org") - .prefetch_related("domain") - .filter(org__status=Organization.STATUS.accepted, is_proposed=True) - ) + if user and self.request.user.groups.filter(name__in=[COMMITTEE_GROUP, STAFF_GROUP, SUPPORT_GROUP]).exists(): + return candidat_base_queryset.all() + + return candidat_base_queryset.filter(org__status=Organization.STATUS.accepted, is_proposed=True) @staticmethod def _get_candidate_support_context(user: User, candidate: Candidate) -> Dict[str, bool]: @@ -524,7 +520,7 @@ def _get_candidate_support_context(user: User, candidate: Candidate) -> Dict[str return context @staticmethod - def _get_candidate_approval_checks(user: User, candidate: Candidate) -> Dict[str, bool]: + def _get_candidate_approval_context(user: User, candidate: Candidate) -> Dict[str, bool]: context = { "can_approve_candidate": False, "approved_candidate": False, @@ -606,7 +602,7 @@ def get_context_data(self, **kwargs): context.update(self._get_candidate_support_context(user, candidate)) # Candidate: Approve checks - context.update(self._get_candidate_approval_checks(user, candidate)) + context.update(self._get_candidate_approval_context(user, candidate)) # Candidate: Vote checks context.update(self._get_candidate_vote_context(user, candidate))