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