diff --git a/djrill/__init__.py b/djrill/__init__.py index e69de29..fa6d9a2 100644 --- a/djrill/__init__.py +++ b/djrill/__init__.py @@ -0,0 +1,45 @@ +from django.contrib.admin.sites import AdminSite +from django.utils.text import capfirst + +VERSION = (0, 1, 0) +__version__ = '.'.join([str(x) for x in VERSION]) + + +class DjrillAdminSite(AdminSite): + index_template = "djrill/index.html" + custom_views = [] + + def register_view(self, path, view, name=None): + """Add a custom admin view. + + * `path` is the path in the admin where the view will live, e.g. + http://example.com/admin/somepath + * `view` is any view function you can imagine. + * `name` is an optional pretty name for the list of custom views. If + empty, we'll guess based on view.__name__. + """ + self.custom_views.append((path, view, name)) + + def get_urls(self): + """Add our custom views to the admin urlconf.""" + urls = super(DjrillAdminSite, self).get_urls() + from django.conf.urls.defaults import patterns, url + for path, view, name in self.custom_views: + urls += patterns('', + url(r'^%s$' % path, self.admin_view(view)), + ) + return urls + + def index(self, request, extra_context=None): + """Make sure our list of custom views is on the index page.""" + if not extra_context: + extra_context = {} + custom_list = [(path, name if name else + capfirst(view.__name__)) for path, view, name in + self.custom_views] + # Sort views alphabetically. + custom_list.sort(key=lambda x: x[1]) + extra_context.update({ + 'custom_list': custom_list + }) + return super(DjrillAdminSite, self).index(request, extra_context) diff --git a/djrill/admin.py b/djrill/admin.py index e69de29..481da59 100644 --- a/djrill/admin.py +++ b/djrill/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +from djrill.views import AdminListView + + +admin.site.register_view("djrill", AdminListView.as_view(), "Djrill") diff --git a/djrill/templates/djrill/base.html b/djrill/templates/djrill/base.html new file mode 100644 index 0000000..a9bc658 --- /dev/null +++ b/djrill/templates/djrill/base.html @@ -0,0 +1,7 @@ +{% extends "admin/base_site.html" %} + +{% block breadcrumbs %} +
+{% endblock %} diff --git a/djrill/templates/djrill/index.html b/djrill/templates/djrill/index.html new file mode 100644 index 0000000..6502f0b --- /dev/null +++ b/djrill/templates/djrill/index.html @@ -0,0 +1,18 @@ +{% extends "admin/index.html" %} + +{% block sidebar %} + {{ block.super }} + + {% if custom_list %} +| {{ name }} |