@@ -110,6 +110,7 @@ class ProvidedFileAssetConfigurationInline(StackedPolymorphicInline.Child):
110110 ProvidedFileAssetConfigurationInline ,
111111 ]
112112
113+
113114@admin .register (SponsorshipBenefit )
114115class SponsorshipBenefitAdmin (PolymorphicInlineSupportMixin , OrderedModelAdmin ):
115116 change_form_template = "sponsors/admin/sponsorshipbenefit_change_form.html"
@@ -179,12 +180,12 @@ def update_related_sponsorships(self, *args, **kwargs):
179180@admin .register (SponsorshipPackage )
180181class SponsorshipPackageAdmin (OrderedModelAdmin ):
181182 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" ]
183184 list_filter = ["advertise" , "year" , "allow_a_la_carte" ]
184185 search_fields = ["name" ]
185186
186187 def get_readonly_fields (self , request , obj = None ):
187- readonly = []
188+ readonly = ["get_benefit_split" ]
188189 if obj :
189190 readonly .append ("slug" )
190191 if not request .user .is_superuser :
@@ -196,6 +197,30 @@ def get_prepopulated_fields(self, request, obj=None):
196197 return {'slug' : ['name' ]}
197198 return {}
198199
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+
199224
200225class SponsorContactInline (admin .TabularInline ):
201226 model = SponsorContact
0 commit comments