Skip to content

Commit

Permalink
Update the admin to show more candidate information to staff
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Nov 15, 2024
1 parent 3a488f1 commit 3f9b2b3
Show file tree
Hide file tree
Showing 4 changed files with 513 additions and 440 deletions.
60 changes: 49 additions & 11 deletions backend/hub/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,45 @@ class CandidateAdmin(BasePermissionsAdmin):
actions = [accept_candidates, reject_candidates, pending_candidates]
list_per_page = 20

fieldsets = (
(
_("Status Information"),
{
"fields": (
"status",
"org",
"initial_org",
"domain",
"is_proposed",
)
},
),
(
_("Candidate Information"),
{
"fields": (
"name",
"role",
"photo",
),
},
),
(
_("Candidate Files"),
{
"fields": (
"statement",
"mandate",
"letter_of_intent",
"cv",
"declaration_of_interests",
"fiscal_record",
"criminal_record",
),
},
),
)

# def get_queryset(self, request):
# queryset = super().get_queryset(request)
# if get_feature_flag(FLAG_CHOICES.global_support_round):
Expand All @@ -463,6 +502,16 @@ class CandidateAdmin(BasePermissionsAdmin):
# )
# return queryset

def get_readonly_fields(self, request, obj=None):
readonly_fields = self.readonly_fields

if request.user.is_superuser:
return readonly_fields

readonly_fields.extend(["org", "initial_org", "domain", "is_proposed", "name", "role"])

return readonly_fields

def get_inline_instances(self, request, obj=None):
if get_feature_flag(FLAG_CHOICES.global_support_round):
inlines = [CandidateConfirmationInline, CandidateSupporterInline, CandidateVoteInline]
Expand All @@ -474,7 +523,6 @@ def votes_count(self, obj):
return obj.votes.count()

votes_count.short_description = _("Votes")
# votes_count.admin_order_field = "votes_count"

def supporters_count(self, obj):
if get_feature_flag(FLAG_CHOICES.global_support_round):
Expand All @@ -483,13 +531,11 @@ def supporters_count(self, obj):
return "N/A"

supporters_count.short_description = _("Supporters")
# supporters_count.admin_order_field = "supporters_count"

def confirmations_count(self, obj):
return obj.confirmations.count()

confirmations_count.short_description = _("Confirmations")
# confirmations_count.admin_order_field = "confirmations_count"

def has_add_permission(self, request, obj=None):
return False
Expand All @@ -502,14 +548,6 @@ def has_change_permission(self, request, obj=None):
def has_delete_permission(self, request, obj=None):
return False

def get_form(self, request, obj=None, **kwargs):
admin_user = request.user
if obj and admin_user.is_staff:
kwargs["fields"] = Candidate.file_fields()
return super().get_form(request, obj, **kwargs)

return super().get_form(request, obj, **kwargs)


@admin.register(Domain)
class DomainAdmin(ImportExportModelAdmin, BasePermissionsAdmin):
Expand Down
4 changes: 2 additions & 2 deletions backend/hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ class Candidate(StatusModel, TimeStampedModel, BaseCompleteModel):
help_text=_("The domain in which the candidate is running."),
)

is_proposed = models.BooleanField(_("Is proposed?"), default=False)

name = models.CharField(
_("Representative name"),
max_length=254,
Expand Down Expand Up @@ -808,8 +810,6 @@ class Candidate(StatusModel, TimeStampedModel, BaseCompleteModel):
validators=[file_validator],
)

is_proposed = models.BooleanField(_("Is proposed?"), default=False)

objects = models.Manager()
objects_with_org = CandidatesWithOrgManager()

Expand Down
Loading

0 comments on commit 3f9b2b3

Please sign in to comment.