symposion_app/symposion/sponsorship/admin.py
Hiroshi Miura a95825ede8 python3 compatibility
- Things are suggested in python3 porting guide.
https://docs.djangoproject.com/en/1.8/topics/python3/

     1. adding ```from django.utils.encoding import
     python_2_unicode_compatible```

     2. ``` __str__``` instead of ```__unicode__```
     https://docs.djangoproject.com/en/1.8/topics/python3/#str-and-unicode-methods

     3. Adding ```from __future__ import unicode_literals``` at the top
     of your Python modules
     https://docs.djangoproject.com/en/1.8/topics/python3/#unicode-literals

     4. Removing the `u` prefix before unicode strings;
     https://docs.djangoproject.com/en/1.8/topics/python3/#unicode-literals

- also closed #66

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
2015-08-03 23:32:25 +09:00

85 lines
2.4 KiB
Python

from __future__ import unicode_literals
from django.contrib import admin
from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from symposion.sponsorship.models import SponsorLevel, Sponsor, Benefit, BenefitLevel, \
SponsorBenefit
class BenefitLevelInline(admin.TabularInline):
model = BenefitLevel
extra = 0
class SponsorBenefitInline(admin.StackedInline):
model = SponsorBenefit
extra = 0
fieldsets = [
(None, {
"fields": [
("benefit", "active"),
("max_words", "other_limits"),
"text",
"upload",
]
})
]
class SponsorAdmin(admin.ModelAdmin):
save_on_top = True
fieldsets = [
(None, {
"fields": [
("name", "applicant"),
("level", "active"),
"external_url",
"annotation",
("contact_name", "contact_email")
]
}),
("Metadata", {
"fields": ["added"],
"classes": ["collapse"]
})
]
inlines = [SponsorBenefitInline]
list_display = ["name", "external_url", "level", "active", "contact", "applicant_field"]
def contact(self, sponsor):
return mark_safe('<a href="mailto:%s">%s</a>' % (escape(sponsor.contact_email), escape(sponsor.contact_name)))
def applicant_field(self, sponsor):
name = sponsor.applicant.get_full_name()
email = sponsor.applicant.email
return mark_safe('<a href="mailto:%s">%s</a>' % (escape(email), escape(name)))
applicant_field.short_description = _(u"Applicant")
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")
]
return form
class BenefitAdmin(admin.ModelAdmin):
list_display = ["name", "type", "description"]
inlines = [BenefitLevelInline]
class SponsorLevelAdmin(admin.ModelAdmin):
inlines = [BenefitLevelInline]
admin.site.register(SponsorLevel, SponsorLevelAdmin)
admin.site.register(Sponsor, SponsorAdmin)
admin.site.register(Benefit, BenefitAdmin)