39674ea672486242b5a0592e9f83d3aa78d60605
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / sitotheque / admin.py
1 # -*- encoding: utf-8 -*-
2 from django.contrib import admin
3 from django.core.urlresolvers import reverse as url
4 from django.http import HttpResponseRedirect
5 from models import Site, SiteVoir
6
7 class SiteAdmin(admin.ModelAdmin):
8 list_display = ['titre', 'recherche_google']
9 list_editable = ['recherche_google']
10 actions = ('assigner_regions', 'assigner_disciplines')
11 list_filter = ('discipline', 'regions')
12
13 def queryset(self, request):
14 return Site.all_objects.all()
15
16 def assigner_regions(self, request, queryset):
17 selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
18 return HttpResponseRedirect(url('assigner_regions', kwargs=dict(app_name='sitotheque', model_name='site')) + '?ids=' + ','.join(selected))
19 assigner_regions.short_description = u'Assigner des régions'
20
21 def assigner_disciplines(self, request, queryset):
22 selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
23 return HttpResponseRedirect(url('assigner_disciplines', kwargs=dict(app_name='sitotheque', model_name='site')) + '?ids=' + ','.join(selected))
24 assigner_disciplines.short_description = u'Assigner des disciplines'
25
26 admin.site.register(Site, SiteAdmin)
27
28 class SiteVoirAdmin(SiteAdmin):
29
30 actions = None
31 list_editable = []
32
33 def __init__(self, model, admin_site):
34 super(SiteAdmin, self).__init__(model, admin_site)
35
36 self.readonly_fields = self.fields
37
38
39 admin.site.register(SiteVoir, SiteVoirAdmin)