Skip to content

Commit

Permalink
Bugfix: sponsorship package-only benefits disappearing (#1737)
Browse files Browse the repository at this point in the history
* Add level name to list display

* Do not disable input if benefit was selected

* Allow to filter sponsorship applications by the level name

* capture all active listings, not just ones with _only_ active

= was missing active + package_only labels

Co-authored-by: Ernest W. Durbin III <ewdurbin@gmail.com>
  • Loading branch information
berinhard and ewdurbin committed Feb 26, 2021
1 parent 6df19e3 commit 4188497
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion sponsors/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ def has_delete_permission(self, request, obj=None):
return obj.open_for_editing


class LevelNameFilter(admin.SimpleListFilter):
title = "level name"
parameter_name = "level"

def lookups(self, request, model_admin):
qs = SponsorshipPackage.objects.all()
return list(set([(program.name, program.name) for program in qs]))

def queryset(self, request, queryset):
if self.value() == "all":
return queryset
if self.value():
return queryset.filter(level_name=self.value())


@admin.register(Sponsorship)
class SponsorshipAdmin(admin.ModelAdmin):
change_form_template = "sponsors/admin/sponsorship_change_form.html"
Expand All @@ -127,13 +142,14 @@ class SponsorshipAdmin(admin.ModelAdmin):
list_display = [
"sponsor",
"status",
"level_name",
"applied_on",
"approved_on",
"start_date",
"end_date",
"display_sponsorship_link",
]
list_filter = ["status"]
list_filter = ["status", LevelNameFilter]
readonly_fields = [
"for_modified_package",
"sponsor",
Expand Down
2 changes: 1 addition & 1 deletion static/js/sponsors/applicationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $(document).ready(function(){

SELECTORS.clearFormBtn().click(function(){
SELECTORS.applicationForm().trigger("reset");
SELECTORS.applicationForm().find("[class=active]").removeClass("active");
SELECTORS.applicationForm().find(".active").removeClass("active");
SELECTORS.packageInput().prop("checked", false);
SELECTORS.checkboxesContainer().find(':checkbox').each(function(){
$(this).prop('checked', false);
Expand Down
2 changes: 1 addition & 1 deletion templates/sponsors/sponsorship_benefits_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h3 class="title">{{ field.label }}</h3>
{% for benefit in field.field.queryset %}
<li class="{% cycle '' 'highlight' %}">
<label for="id_{{field.name}}_{{ forloop.counter0 }}" {% if benefit.package_only %} class='package_only'{% endif %} benefit_id="{{ benefit.id }}">
<input id="id_{{field.name}}_{{ forloop.counter0 }}" name="{{ field.name }}" type="checkbox" value="{{ benefit.id }}" {% if benefit.unavailability_message %}disabled{% endif %} {% if benefit.id in field.initial %}checked{% endif %} {% if benefit.package_only %}package_only='true'{% endif %}>
<input id="id_{{field.name}}_{{ forloop.counter0 }}" name="{{ field.name }}" type="checkbox" value="{{ benefit.id }}" {% if benefit.unavailability_message and benefit.id not in field.initial %}disabled{% endif %} {% if benefit.id in field.initial %}checked{% endif %} {% if benefit.package_only %}package_only='true'{% endif %}>
<span>{{ benefit.name }}</span>
{% if benefit.description %}<i class="fa fa-info" title="{{ benefit.description }}"></i>{% endif %}
{% if benefit.package_only %}<i class="fa fa-cubes" title="{{ benefit_model.PACKAGE_ONLY_MESSAGE }}"></i>{% endif %}
Expand Down

0 comments on commit 4188497

Please sign in to comment.