Skip to content

Sponsorship admin helpers #1973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions sponsors/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,22 @@ class SponsorContactInline(admin.TabularInline):
extra = 0


class SponsorshipsInline(admin.TabularInline):
model = Sponsorship
fields = ["link", "status", "applied_on", "start_date", "end_date"]
readonly_fields = ["link", "status", "applied_on", "start_date", "end_date"]
can_delete = False
extra = 0

def link(self, obj):
url = reverse("admin:sponsors_sponsorship_change", args=[obj.id])
return mark_safe(f"<a href={url}>{obj.id}</a>")
link.short_description = "ID"


@admin.register(Sponsor)
class SponsorAdmin(ContentManageableModelAdmin):
inlines = [SponsorContactInline, AssetsInline]
inlines = [SponsorContactInline, SponsorshipsInline, AssetsInline]
search_fields = ["name"]


Expand Down Expand Up @@ -268,7 +281,7 @@ class SponsorshipAdmin(admin.ModelAdmin):
{
"fields": (
"for_modified_package",
"sponsor",
"sponsor_link",
"status",
"package",
"sponsorship_fee",
Expand Down Expand Up @@ -340,7 +353,7 @@ def send_notifications(self, request, queryset):
def get_readonly_fields(self, request, obj):
readonly_fields = [
"for_modified_package",
"sponsor",
"sponsor_link",
"status",
"applied_on",
"rejected_on",
Expand Down Expand Up @@ -368,6 +381,11 @@ def get_readonly_fields(self, request, obj):

return readonly_fields

def sponsor_link(self, obj):
url = reverse("admin:sponsors_sponsor_change", args=[obj.sponsor.id])
return mark_safe(f"<a href={url}>{obj.sponsor.name}</a>")
sponsor_link.short_description = "Sponsor"

def get_estimated_cost(self, obj):
cost = None
html = "This sponsorship has not customizations so there's no estimated cost"
Expand Down
4 changes: 4 additions & 0 deletions templates/sponsors/admin/sponsorship_change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
{% block object-tools-items %}
{% with original as sp %}

<li>
<a href="{% url 'users:sponsorship_application_detail' sp.pk %}" style="background: #70bf2b">View Dashboard</a>
</li>

{% if sp.APPROVED in sp.next_status %}
<li>
<a href="{% url 'admin:sponsors_sponsorship_approve' sp.pk %}" style="background: #70bf2b">Generate Contract for Signing</a>
Expand Down
8 changes: 8 additions & 0 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ class SponsorshipDetailView(DetailView):
template_name = 'users/sponsorship_detail.html'

def get_queryset(self):
if self.request.user.is_superuser:
return Sponsorship.objects.select_related("sponsor").all()
return self.request.user.sponsorships.select_related("sponsor")

def get_context_data(self, *args, **kwargs):
Expand Down Expand Up @@ -266,6 +268,8 @@ class UpdateSponsorInfoView(UpdateView):
form_class = SponsorUpdateForm

def get_queryset(self):
if self.request.user.is_superuser:
return Sponsor.objects.all()
sponsor_ids = self.request.user.sponsorships.values_list("sponsor_id", flat=True)
return Sponsor.objects.filter(id__in=Subquery(sponsor_ids))

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

def get_queryset(self):
if self.request.user.is_superuser:
return Sponsorship.objects.select_related("sponsor").all()
return self.request.user.sponsorships.select_related("sponsor")

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

def get_queryset(self):
if self.request.user.is_superuser:
return Sponsorship.objects.select_related("sponsor").all()
return self.request.user.sponsorships.select_related("sponsor")

def get_context_data(self, **kwargs):
Expand Down