Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sponsorship renewal review (#2345)
Browse files Browse the repository at this point in the history
* add rewnewal to the admin view for sponsorship

* use the sponsorship form directly rather than editing template

* include previous effective date in context/review form for renewals

* update to real renewal contract

* missing migration
ewdurbin authored Dec 19, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c652a9f commit f6fbceb
Showing 9 changed files with 64 additions and 7 deletions.
1 change: 1 addition & 0 deletions sponsors/admin.py
Original file line number Diff line number Diff line change
@@ -402,6 +402,7 @@ class SponsorshipAdmin(ImportExportActionModelAdmin, admin.ModelAdmin):
"end_date",
"get_contract",
"level_name",
"renewal",
"overlapped_by",
),
},
8 changes: 6 additions & 2 deletions sponsors/forms.py
Original file line number Diff line number Diff line change
@@ -392,7 +392,10 @@ class SponsorshipReviewAdminForm(forms.ModelForm):
start_date = forms.DateField(widget=AdminDateWidget(), required=False)
end_date = forms.DateField(widget=AdminDateWidget(), required=False)
overlapped_by = forms.ModelChoiceField(queryset=Sponsorship.objects.select_related("sponsor", "package"), required=False)
renewal = forms.CheckboxInput()
renewal = forms.BooleanField(
help_text="If true, it means the sponsorship is a renewal of a previous sponsorship and will use the renewal template for contracting.",
required=False,
)

def __init__(self, *args, **kwargs):
force_required = kwargs.pop("force_required", False)
@@ -404,11 +407,12 @@ def __init__(self, *args, **kwargs):
self.fields.pop("overlapped_by") # overlapped should never be displayed on approval
for field_name in self.fields:
self.fields[field_name].required = True
self.fields["renewal"].required = False


class Meta:
model = Sponsorship
fields = ["start_date", "end_date", "package", "sponsorship_fee"]
fields = ["start_date", "end_date", "package", "sponsorship_fee", "renewal"]
widgets = {
'year': SPONSORSHIP_YEAR_SELECT,
}
18 changes: 18 additions & 0 deletions sponsors/migrations/0098_auto_20231219_1910.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.24 on 2023-12-19 19:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('sponsors', '0097_sponsorship_renewal'),
]

operations = [
migrations.AlterField(
model_name='sponsorship',
name='renewal',
field=models.BooleanField(blank=True, help_text='If true, it means the sponsorship is a renewal of a previous sponsorship and will use the renewal template for contracting.', null=True),
),
]
12 changes: 11 additions & 1 deletion sponsors/models/sponsorship.py
Original file line number Diff line number Diff line change
@@ -182,7 +182,11 @@ class Sponsorship(models.Model):
package = models.ForeignKey(SponsorshipPackage, null=True, on_delete=models.SET_NULL)
sponsorship_fee = models.PositiveIntegerField(null=True, blank=True)
overlapped_by = models.ForeignKey("self", null=True, on_delete=models.SET_NULL)
renewal = models.BooleanField(null=True, blank=True)
renewal = models.BooleanField(
null=True,
blank=True,
help_text="If true, it means the sponsorship is a renewal of a previous sponsorship and will use the renewal template for contracting."
)

assets = GenericRelation(GenericAsset)

@@ -379,6 +383,12 @@ def next_status(self):
}
return states_map[self.status]

@property
def previous_effective_date(self):
if len(self.sponsor.sponsorship_set.all().order_by('-year')) > 1:
return self.sponsor.sponsorship_set.all().order_by('-year')[1].start_date
return None


class SponsorshipBenefit(OrderedModel):
"""
1 change: 1 addition & 0 deletions sponsors/pdf.py
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ def _contract_context(contract, **context):
"legal_clauses": _clean_split(contract.legal_clauses.raw),
"renewal": contract.sponsorship.renewal,
})
context["previous_effective"] = contract.sponsorship.previous_effective_date if contract.sponsorship.previous_effective_date else "UNKNOWN"
return context


2 changes: 2 additions & 0 deletions sponsors/tests/test_pdf.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ def setUp(self):
"benefits": [],
"legal_clauses": [],
"renewal": None,
"previous_effective": "UNKNOWN",
}
self.template = "sponsors/admin/preview-contract.html"

@@ -88,6 +89,7 @@ def test_render_response_with_docx_attachment__renewal(self, MockDocxTemplate):
"benefits": [],
"legal_clauses": [],
"renewal": True,
"previous_effective": "UNKNOWN",
}
renewal_template = "sponsors/admin/preview-contract.html"

6 changes: 5 additions & 1 deletion sponsors/views_admin.py
Original file line number Diff line number Diff line change
@@ -85,7 +85,11 @@ def approve_sponsorship_view(ModelAdmin, request, pk):
)
return redirect(redirect_url)

context = {"sponsorship": sponsorship, "form": form}
context = {
"sponsorship": sponsorship,
"form": form,
"previous_effective": sponsorship.previous_effective_date if sponsorship.previous_effective_date else "UNKNOWN",
}
return render(request, "sponsors/admin/approve_application.html", context=context)


23 changes: 20 additions & 3 deletions templates/sponsors/admin/approve_application.html
Original file line number Diff line number Diff line change
@@ -2,7 +2,18 @@
{% extends 'admin/change_form.html' %}
{% load i18n static sponsors %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">{% endblock %}
{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">
<style>
.helptext {
font-size: smaller;
display: block;
padding-top: .5em;
color: #999;
}
</style>
{% endblock %}

{% block title %}Accept {{ sponsorship }} | python.org{% endblock %}

@@ -33,9 +44,15 @@ <h1>Generate Contract for Signing</h1>
{{ form.media }}
{{ form.as_p }}

<p>
<label for="id_renewal_previous_effective_date">
Previous Effective Contract:
</label>
<span><b>{{ previous_effective }}</b></span>
<span class="helptext">The last known contract effective date for this sponsor. This will <i>only</i> impact renewals. If UNKNOWN, you <strong>MUST</strong> update the resulting docx with the correct effective date.</span>
</p>

<input name="confirm" value="yes" style="display:none">
<input type="checkbox" id="renewal" name="renewal" value="renewal">
<label for="renewal">Renewal of a previous sponsorship</label><br>
<div class="submit-row">
<input type="submit" value="Approve" class="default">
</div>
Binary file modified templates/sponsors/admin/renewal-contract-template.docx
Binary file not shown.

0 comments on commit f6fbceb

Please sign in to comment.