Commits

Federico Maggi committed 77673c0 Draft

Filters

Comments (0)

Files changed (1)

academic/people/admin.py

 from django import forms
 from django.db import models
 from django.conf import settings
+from django.http import HttpResponseRedirect
+from django.core.urlresolvers import reverse
 
 from academic.people.models import *
 
+class DefaultFilterMixIn(admin.ModelAdmin):
+    def changelist_view(self, request, *args, **kwargs):
+        from django.http import HttpResponseRedirect
+        if self.default_filters:
+            try:
+                if request.META['QUERY_STRING'] == '':
+                    url = reverse('admin:%s_%s_changelist' % \
+                                      (self.opts.app_label,
+                                       self.opts.module_name))
+                    filters = []
+
+                    for filter in self.default_filters:
+                        key = filter.split('=')[0]
+                        if not request.GET.has_key(key):
+                            filters.append(filter)
+                    if filters:
+                        return HttpResponseRedirect(
+                            "%s?%s" % (url, "&".join(filters)))
+            except:
+                pass
+        return super(DefaultFilterMixIn, self).\
+            changelist_view(request, *args, **kwargs)
+    
+
 class PersonAdmin(admin.ModelAdmin):
     filter_horizontal = [
         'affiliation',]
+    default_filters = (
+        'public__exact=1',
+        'current__exact=1')
     list_display_links = (
         'photo',
         'first_name',
         'visitor',
         'e_mail',)
     list_filter = (
-        'internal',
         'public',
         'current',
         'visitor',
         'first_name',
         'last_name',
         'e_mail',)
+
+    
 admin.site.register(Person, PersonAdmin)
 
 class PersonInlineForm(forms.ModelForm):