diff --git a/docs/changelog.rst b/docs/changelog.rst index e23442ecf..5758617ec 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,8 @@ Changelog * 0.0.4 * Added automated tagging basted on keyword matching + * Cleaned up the document listing page + * Removed ``User`` and ``Group`` from the admin * 0.0.3 diff --git a/src/documents/admin.py b/src/documents/admin.py index 613e7b292..2ac8f2f3f 100644 --- a/src/documents/admin.py +++ b/src/documents/admin.py @@ -1,15 +1,42 @@ from django.contrib import admin +from django.contrib.auth.models import User, Group from django.core.urlresolvers import reverse from django.templatetags.static import static from .models import Sender, Tag, Document +class MonthListFilter(admin.SimpleListFilter): + + title = "Month" + + # Parameter for the filter that will be used in the URL query. + parameter_name = "month" + + def lookups(self, request, model_admin): + r = [] + for document in Document.objects.all(): + r.append(( + document.created.strftime("%Y-%m"), + document.created.strftime("%B %Y") + )) + return sorted(set(r), key=lambda x: x[0], reverse=True) + + def queryset(self, request, queryset): + + if not self.value(): + return None + + year, month = self.value().split("-") + return queryset.filter(created__year=year, created__month=month) + + class DocumentAdmin(admin.ModelAdmin): search_fields = ("sender__name", "title", "content",) list_display = ("edit", "created", "sender", "title", "tags_", "pdf") - list_filter = ("created", "tags", "sender") + list_filter = (MonthListFilter, "tags", "sender") + list_editable = ("sender", "title",) list_per_page = 25 def edit(self, obj): @@ -39,3 +66,7 @@ class DocumentAdmin(admin.ModelAdmin): admin.site.register(Sender) admin.site.register(Tag) admin.site.register(Document, DocumentAdmin) + +# Unless we implement multi-user, these default registrations don't make sense. +admin.site.unregister(Group) +admin.site.unregister(User)