Source

cciw-website / cciw / cciwmain / admin.py

Luke Plant 3585aa1 
Luke Plant b514c47 

Luke Plant 6c00a46 


























Luke Plant b514c47 



Luke Plant b2a4b69 
Luke Plant b514c47 




Luke Plant ac89f68 
Luke Plant b7f653d 
Luke Plant ac89f68 

Luke Plant b514c47 
Luke Plant 161784c 



Luke Plant ac89f68 




Luke Plant b514c47 
Luke Plant ef264bd 


Luke Plant d2f1749 



Luke Plant ef264bd 
Luke Plant d2f1749 
Luke Plant b7f653d 
Luke Plant b514c47 
Luke Plant e498736 
Luke Plant b514c47 
Luke Plant 81e9e16 


Luke Plant b514c47 

from cciw.cciwmain.models import Site, Person, Camp
from django.contrib import admin


from functools import wraps
def rename_app_list(func):
    m = {'Cciwmain': 'Camp info',
         'Sitecontent': 'Site content',
         'Sites': 'Web sites'
         }
    @wraps(func)
    def _wrapper(*args, **kwargs):
        response = func(*args, **kwargs)
        app_list = response.context_data.get('app_list')
        if app_list is not None:
            for a in app_list:
                name = a['name']
                a['name'] = m.get(name, name)
        title = response.context_data.get('title')
        if title is not None:
            app_label = title.split(' ')[0]
            if app_label in m:
                response.context_data['title'] = "%s administration" % m[app_label]
        return response
    return _wrapper

admin.site.index = rename_app_list(admin.site.index)
admin.site.app_index = rename_app_list(admin.site.app_index)


class SiteAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {'fields': ('short_name', 'long_name', 'info')}),
    )

class PersonAdmin(admin.ModelAdmin):
    filter_horizontal = ('users',)

class CampAdmin(admin.ModelAdmin):
    fieldsets = (
        ('Public info',
         {'fields': ('year', 'number', 'minimum_age', 'maximum_age', 'start_date', 'end_date',
                     'chaplain', 'leaders', 'site', 'previous_camp')
          }
        ),
        ('Booking constraints',
         {'fields': ('max_campers', 'max_male_campers', 'max_female_campers')
          }
         ),
        ('Applications and references',
         {'fields': ('online_applications', 'admins'),
          'description': '<div>Options for managing applications. Officer lists are managed <a href="/officers/leaders/">elsewhere</a>, not here.</div>',
          }
         ),
    )
    ordering = ('-year','number')
    def leaders(camp):
        return camp.leaders_formatted
    def chaplain(camp):
        return camp.chaplain
    chaplain.admin_order_field = 'chaplain__name'
    list_display = ('year', 'number', leaders, chaplain, 'age', 'site', 'start_date')
    list_display_links = ('number', leaders)
    del leaders, chaplain
    list_filter = ('site',)
    filter_horizontal = ('leaders', 'admins')
    date_hierarchy = 'start_date'

    def queryset(self, request):
        return super(CampAdmin, self).queryset(request).select_related('site', 'chaplain')

admin.site.register(Site, SiteAdmin)
admin.site.register(Person, PersonAdmin)
admin.site.register(Camp, CampAdmin)