Skip to content

Commit f25f223

Browse files
authored
Sponsorship admin helpers (#1973)
* render sponsor/sponsorships as links to one another * allow superusers to view and interact with sponsor dashboards
1 parent e650ab5 commit f25f223

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

sponsors/admin.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,22 @@ class SponsorContactInline(admin.TabularInline):
185185
extra = 0
186186

187187

188+
class SponsorshipsInline(admin.TabularInline):
189+
model = Sponsorship
190+
fields = ["link", "status", "applied_on", "start_date", "end_date"]
191+
readonly_fields = ["link", "status", "applied_on", "start_date", "end_date"]
192+
can_delete = False
193+
extra = 0
194+
195+
def link(self, obj):
196+
url = reverse("admin:sponsors_sponsorship_change", args=[obj.id])
197+
return mark_safe(f"<a href={url}>{obj.id}</a>")
198+
link.short_description = "ID"
199+
200+
188201
@admin.register(Sponsor)
189202
class SponsorAdmin(ContentManageableModelAdmin):
190-
inlines = [SponsorContactInline, AssetsInline]
203+
inlines = [SponsorContactInline, SponsorshipsInline, AssetsInline]
191204
search_fields = ["name"]
192205

193206

@@ -268,7 +281,7 @@ class SponsorshipAdmin(admin.ModelAdmin):
268281
{
269282
"fields": (
270283
"for_modified_package",
271-
"sponsor",
284+
"sponsor_link",
272285
"status",
273286
"package",
274287
"sponsorship_fee",
@@ -340,7 +353,7 @@ def send_notifications(self, request, queryset):
340353
def get_readonly_fields(self, request, obj):
341354
readonly_fields = [
342355
"for_modified_package",
343-
"sponsor",
356+
"sponsor_link",
344357
"status",
345358
"applied_on",
346359
"rejected_on",
@@ -368,6 +381,11 @@ def get_readonly_fields(self, request, obj):
368381

369382
return readonly_fields
370383

384+
def sponsor_link(self, obj):
385+
url = reverse("admin:sponsors_sponsor_change", args=[obj.sponsor.id])
386+
return mark_safe(f"<a href={url}>{obj.sponsor.name}</a>")
387+
sponsor_link.short_description = "Sponsor"
388+
371389
def get_estimated_cost(self, obj):
372390
cost = None
373391
html = "This sponsorship has not customizations so there's no estimated cost"

templates/sponsors/admin/sponsorship_change_form.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
{% block object-tools-items %}
55
{% with original as sp %}
66

7+
<li>
8+
<a href="{% url 'users:sponsorship_application_detail' sp.pk %}" style="background: #70bf2b">View Dashboard</a>
9+
</li>
10+
711
{% if sp.APPROVED in sp.next_status %}
812
<li>
913
<a href="{% url 'admin:sponsors_sponsorship_approve' sp.pk %}" style="background: #70bf2b">Generate Contract for Signing</a>

users/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ class SponsorshipDetailView(DetailView):
232232
template_name = 'users/sponsorship_detail.html'
233233

234234
def get_queryset(self):
235+
if self.request.user.is_superuser:
236+
return Sponsorship.objects.select_related("sponsor").all()
235237
return self.request.user.sponsorships.select_related("sponsor")
236238

237239
def get_context_data(self, *args, **kwargs):
@@ -266,6 +268,8 @@ class UpdateSponsorInfoView(UpdateView):
266268
form_class = SponsorUpdateForm
267269

268270
def get_queryset(self):
271+
if self.request.user.is_superuser:
272+
return Sponsor.objects.all()
269273
sponsor_ids = self.request.user.sponsorships.values_list("sponsor_id", flat=True)
270274
return Sponsor.objects.filter(id__in=Subquery(sponsor_ids))
271275

@@ -281,6 +285,8 @@ class UpdateSponsorshipAssetsView(UpdateView):
281285
form_class = SponsorRequiredAssetsForm
282286

283287
def get_queryset(self):
288+
if self.request.user.is_superuser:
289+
return Sponsorship.objects.select_related("sponsor").all()
284290
return self.request.user.sponsorships.select_related("sponsor")
285291

286292
def get_form_kwargs(self):
@@ -310,6 +316,8 @@ class ProvidedSponsorshipAssetsView(DetailView):
310316
template_name = 'users/sponsorship_assets_view.html'
311317

312318
def get_queryset(self):
319+
if self.request.user.is_superuser:
320+
return Sponsorship.objects.select_related("sponsor").all()
313321
return self.request.user.sponsorships.select_related("sponsor")
314322

315323
def get_context_data(self, **kwargs):

0 commit comments

Comments
 (0)