@@ -110,6 +110,7 @@ class ProvidedFileAssetConfigurationInline(StackedPolymorphicInline.Child):
110
110
ProvidedFileAssetConfigurationInline ,
111
111
]
112
112
113
+
113
114
@admin .register (SponsorshipBenefit )
114
115
class SponsorshipBenefitAdmin (PolymorphicInlineSupportMixin , OrderedModelAdmin ):
115
116
change_form_template = "sponsors/admin/sponsorshipbenefit_change_form.html"
@@ -179,12 +180,12 @@ def update_related_sponsorships(self, *args, **kwargs):
179
180
@admin .register (SponsorshipPackage )
180
181
class SponsorshipPackageAdmin (OrderedModelAdmin ):
181
182
ordering = ("-year" , "order" ,)
182
- list_display = ["name" , "year" , "advertise" , "allow_a_la_carte" , "move_up_down_links" ]
183
+ list_display = ["name" , "year" , "advertise" , "allow_a_la_carte" , "get_benefit_split" , " move_up_down_links" ]
183
184
list_filter = ["advertise" , "year" , "allow_a_la_carte" ]
184
185
search_fields = ["name" ]
185
186
186
187
def get_readonly_fields (self , request , obj = None ):
187
- readonly = []
188
+ readonly = ["get_benefit_split" ]
188
189
if obj :
189
190
readonly .append ("slug" )
190
191
if not request .user .is_superuser :
@@ -196,6 +197,30 @@ def get_prepopulated_fields(self, request, obj=None):
196
197
return {'slug' : ['name' ]}
197
198
return {}
198
199
200
+ def get_benefit_split (self , obj : SponsorshipPackage ) -> str :
201
+ colors = [
202
+ "#ffde57" , # Python Gold
203
+ "#4584b6" , # Python Blue
204
+ "#646464" , # Python Grey
205
+ ]
206
+ split = obj .get_default_revenue_split ()
207
+ # rotate colors through our available palette
208
+ if len (split ) > len (colors ):
209
+ colors = colors * (1 + (len (split ) // len (colors )))
210
+ # build some span elements to show the percentages and have the program name in the title (to show on hover)
211
+ widths , spans = [], []
212
+ for i , (name , pct ) in enumerate (split ):
213
+ pct_str = f"{ pct :.0f} %"
214
+ widths .append (pct_str )
215
+ spans .append (f"<span title='{ name } ' style='background-color:var(--{ colors [i ]} )'>{ pct_str } </span>" )
216
+ # define a style that will show our span elements like a single horizontal stacked bar chart
217
+ style = f'color:#fff;text-align:center;cursor:pointer;display:grid;grid-template-columns:{ " " .join (widths )} '
218
+ # wrap it all up and put a bow on it
219
+ html = f"<div style='{ style } '>{ '' .join (spans )} </div>"
220
+ return mark_safe (html )
221
+
222
+ get_benefit_split .short_description = "Revenue split"
223
+
199
224
200
225
class SponsorContactInline (admin .TabularInline ):
201
226
model = SponsorContact
0 commit comments