Skip to content

Commit

Permalink
add API view for admin to see all ownershiprequests older than a week
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeweng committed Oct 15, 2024
1 parent 42e953b commit 9439212
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
23 changes: 23 additions & 0 deletions backend/clubs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
MembershipRequest,
Note,
NoteTag,
OwnershipRequest,
Profile,
QuestionAnswer,
RecurringEvent,
Expand Down Expand Up @@ -281,6 +282,27 @@ def is_member(self, obj):
is_member.boolean = True


class OwnershipRequestAdmin(admin.ModelAdmin):
search_fields = (
"person__username",
"person__email",
"club__name",
"club__pk",
"created_at",
)
list_display = ("person", "club", "email", "withdrew", "created_at")
list_filter = ("withdrew",)

def person(self, obj):
return obj.person.username

def club(self, obj):
return obj.club.name

def email(self, obj):
return obj.person.email


class MembershipAdmin(admin.ModelAdmin):
search_fields = (
"person__username",
Expand Down Expand Up @@ -438,6 +460,7 @@ class ApplicationSubmissionAdmin(admin.ModelAdmin):
admin.site.register(Major, MajorAdmin)
admin.site.register(Membership, MembershipAdmin)
admin.site.register(MembershipInvite, MembershipInviteAdmin)
admin.site.register(OwnershipRequest, OwnershipRequestAdmin)
admin.site.register(Profile, ProfileAdmin)
admin.site.register(QuestionAnswer, QuestionAnswerAdmin)
admin.site.register(RecurringEvent)
Expand Down
6 changes: 6 additions & 0 deletions backend/clubs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
NoteViewSet,
OptionListView,
OwnershipRequestOwnerViewSet,
OwnershipRequestSuperuserAPIView,
OwnershipRequestViewSet,
QuestionAnswerViewSet,
ReportViewSet,
Expand Down Expand Up @@ -173,6 +174,11 @@
path(r"emailpreview/", email_preview, name="email-preview"),
path(r"scripts/", ScriptExecutionView.as_view(), name="scripts"),
path(r"options/", OptionListView.as_view(), name="options"),
path(
r"ownershiprequestsadmin/",
OwnershipRequestSuperuserAPIView.as_view(),
name="ownershiprequestsadmin",
),
path(r"social/", include("social_django.urls", namespace="social")),
path(
r"webhook/meeting/",
Expand Down
18 changes: 16 additions & 2 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3854,10 +3854,10 @@ def get_queryset(self):
class OwnershipRequestOwnerViewSet(XLSXFormatterMixin, viewsets.ModelViewSet):
"""
list:
Return a list of users who have sent membership request to the club.
Return a list of users who have sent ownership request to the club.
destroy:
Delete a membership request for a specific user.
Delete a ownership request for a specific user.
"""

serializer_class = OwnershipRequestSerializer
Expand Down Expand Up @@ -3904,6 +3904,20 @@ def accept(self, request, *ages, **kwargs):
return Response({"success": True})


class OwnershipRequestSuperuserAPIView(generics.ListAPIView):
"""
Return a list of ownership requests older than a week.
"""

serializer_class = OwnershipRequestSerializer
permission_classes = [IsSuperuser]

def get_queryset(self):
return OwnershipRequest.objects.filter(
withdrew=False, created_at__lte=timezone.now() - datetime.timedelta(days=7)
)


class MemberViewSet(XLSXFormatterMixin, viewsets.ModelViewSet):
"""
list:
Expand Down

0 comments on commit 9439212

Please sign in to comment.