sponsorship benefit relation administration
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
parent
91ae3de6df
commit
8bc696a2dc
2 changed files with 82 additions and 7 deletions
|
@ -1,7 +1,8 @@
|
|||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from symposion.sponsorship.models import SponsorLevel, Sponsor, Benefit, BenefitLevel, \
|
||||
SponsorBenefit
|
||||
from symposion.sponsorship.models import SponsorLevel, Sponsor, Benefit, \
|
||||
BenefitLevel, SponsorBenefit, BENEFITS
|
||||
|
||||
|
||||
class BenefitLevelInline(admin.TabularInline):
|
||||
|
@ -44,29 +45,66 @@ class SponsorAdmin(admin.ModelAdmin):
|
|||
]
|
||||
inlines = [SponsorBenefitInline]
|
||||
list_display = ["name", "external_url", "level", "active"]
|
||||
list_filter = ["level", "active"]
|
||||
|
||||
def get_form(self, *args, **kwargs):
|
||||
# @@@ kinda ugly but using choices= on NullBooleanField is broken
|
||||
form = super(SponsorAdmin, self).get_form(*args, **kwargs)
|
||||
form.base_fields["active"].widget.choices = [
|
||||
(u"1", "unreviewed"),
|
||||
(u"2", "approved"),
|
||||
(u"3", "rejected")
|
||||
(u"1", _("unreviewed")),
|
||||
(u"2", _("approved")),
|
||||
(u"3", _("rejected"))
|
||||
]
|
||||
return form
|
||||
|
||||
# Define accessor functions for our benefit fields and add them to
|
||||
# list_display, so we can sort on them and give them sensible names.
|
||||
# Add the fields to list_filters while we're at it.
|
||||
for benefit in BENEFITS:
|
||||
benefit_name = benefit['name']
|
||||
field_name = benefit['field_name']
|
||||
|
||||
def func_generator(ben):
|
||||
def column_func(obj):
|
||||
return getattr(obj, ben['field_name'])
|
||||
column_func.short_description = ben['column_title']
|
||||
column_func.boolean = True
|
||||
column_func.admin_order_field = ben['field_name']
|
||||
return column_func
|
||||
list_display.append(func_generator(benefit))
|
||||
list_filter.append(field_name)
|
||||
|
||||
def save_related(self, request, form, formsets, change):
|
||||
super(SponsorAdmin, self).save_related(request, form, formsets, change)
|
||||
obj = form.instance
|
||||
obj.save()
|
||||
|
||||
|
||||
class BenefitAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ["name", "type", "description"]
|
||||
list_display = ["name", "type", "description", "levels"]
|
||||
inlines = [BenefitLevelInline]
|
||||
|
||||
def levels(self, benefit):
|
||||
return u", ".join(l.level.name for l in benefit.benefit_levels.all())
|
||||
|
||||
|
||||
class SponsorLevelAdmin(admin.ModelAdmin):
|
||||
|
||||
inlines = [BenefitLevelInline]
|
||||
|
||||
|
||||
class SponsorBenefitAdmin(admin.ModelAdmin):
|
||||
list_display = ('benefit', 'sponsor', 'active', '_is_complete', 'show_text')
|
||||
|
||||
def show_text(self, sponsor_benefit):
|
||||
if sponsor_benefit.text:
|
||||
return sponsor_benefit.text[:100]
|
||||
else:
|
||||
return _("None")
|
||||
|
||||
|
||||
admin.site.register(SponsorLevel, SponsorLevelAdmin)
|
||||
admin.site.register(Sponsor, SponsorAdmin)
|
||||
admin.site.register(Benefit, BenefitAdmin)
|
||||
admin.site.register(SponsorBenefit, SponsorBenefitAdmin)
|
||||
|
|
|
@ -13,6 +13,35 @@ from symposion.conference.models import Conference
|
|||
from symposion.sponsorship.managers import SponsorManager
|
||||
|
||||
|
||||
# The benefits we track as individual fields on sponsors
|
||||
# Names are the names in the database as defined by organizers.
|
||||
# Field names are the benefit names, lowercased, with
|
||||
# spaces changed to _, and with "_benefit" appended.
|
||||
# Column titles are arbitrary.
|
||||
|
||||
# "really just care about the ones we have today: print logo, web logo, print description, web description and the ad."
|
||||
|
||||
BENEFITS = [
|
||||
{
|
||||
'name': 'Web logo',
|
||||
'field_name': 'web_logo_benefit',
|
||||
'column_title': _(u"Web Logo"),
|
||||
}, {
|
||||
'name': 'Print logo',
|
||||
'field_name': 'print_logo_benefit',
|
||||
'column_title': _(u"Print Logo"),
|
||||
}, {
|
||||
'name': 'Company Description',
|
||||
'field_name': 'company_description_benefit',
|
||||
'column_title': _(u"Web Desc"),
|
||||
}, {
|
||||
'name': 'Print Description',
|
||||
'field_name': 'print_description_benefit',
|
||||
'column_title': _(u"Print Desc"),
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
class SponsorLevel(models.Model):
|
||||
|
||||
conference = models.ForeignKey(Conference, verbose_name=_("conference"))
|
||||
|
@ -27,7 +56,7 @@ class SponsorLevel(models.Model):
|
|||
verbose_name_plural = _("sponsor levels")
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
return u"%s %s" % (self.conference, self.name)
|
||||
|
||||
def sponsors(self):
|
||||
return self.sponsor_set.filter(active=True).order_by("added")
|
||||
|
@ -51,6 +80,13 @@ class Sponsor(models.Model):
|
|||
sponsor_logo = models.ForeignKey("SponsorBenefit", related_name="+", null=True, blank=True,
|
||||
editable=False)
|
||||
|
||||
# Whether things are complete
|
||||
# True = complete, False = incomplate, Null = n/a for this sponsor level
|
||||
web_logo_benefit = models.NullBooleanField(_("Web logo benefit"), help_text=_(u"Web logo benefit is complete"))
|
||||
print_logo_benefit = models.NullBooleanField(_("Print logo benefit"), help_text=_(u"Print logo benefit is complete"))
|
||||
print_description_benefit = models.NullBooleanField(_("Print description benefit"), help_text=_(u"Print description benefit is complete"))
|
||||
company_description_benefit = models.NullBooleanField(_("Company description benefit"), help_text=_(u"Company description benefit is complete"))
|
||||
|
||||
objects = SponsorManager()
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -59,6 +95,7 @@ class Sponsor(models.Model):
|
|||
class Meta:
|
||||
verbose_name = _("sponsor")
|
||||
verbose_name_plural = _("sponsors")
|
||||
ordering = ['name']
|
||||
|
||||
def get_absolute_url(self):
|
||||
if self.active:
|
||||
|
|
Loading…
Reference in a new issue