diff --git a/.travis.yml b/.travis.yml index de5b777..f7a3685 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,6 @@ before_install: - export PIP_USE_MIRRORS=true - export PIP_INDEX_URL=https://simple.crate.io/ install: - - python setup.py develop + - pip install -r requirements.txt script: - python runtests.py diff --git a/djadmin2/core.py b/djadmin2/core.py index e9a7e49..8e2138c 100644 --- a/djadmin2/core.py +++ b/djadmin2/core.py @@ -20,6 +20,7 @@ class Admin2(object): def __init__(self, name='admin2'): self.registry = {} + self.apps = {} self.name = name def register(self, model, modeladmin=None, **kwargs): @@ -31,18 +32,30 @@ class Admin2(object): instantiation. If a model is already registered, this will raise ImproperlyConfigured. + + Once a model is registered in self.registry, we also add it to app registries + in self.apps. """ if model in self.registry: - raise ImproperlyConfigured + raise ImproperlyConfigured('%s is already registered in django-admin2' % model) if not modeladmin: modeladmin = models.ModelAdmin2 self.registry[model] = modeladmin(model, **kwargs) + # Add the model to the apps registry + app_label = model._meta.app_label + if app_label in self.apps.keys(): + self.apps[app_label][model] = self.registry[model] + else: + self.apps[app_label] = {model: self.registry[model]} + def deregister(self, model): """ Deregisters the given model. If the model is not already registered, this will raise ImproperlyConfigured. + + TODO: Remove the model from the self.app as well """ try: del self.registry[model] @@ -65,6 +78,7 @@ class Admin2(object): def get_index_kwargs(self): return { 'registry': self.registry, + 'apps': self.apps, } def get_urls(self): diff --git a/djadmin2/templates/admin2/bootstrap/index.html b/djadmin2/templates/admin2/bootstrap/index.html index ac8d0e8..c14b8cd 100644 --- a/djadmin2/templates/admin2/bootstrap/index.html +++ b/djadmin2/templates/admin2/bootstrap/index.html @@ -1,10 +1,28 @@ {% extends "admin2/bootstrap/base.html" %} {% block content %} -

Index

- -{% for modeladmin in registry.values %} - -{% endfor %} +

Site administration

+ +{% for app, registry in apps.items %} +
{{ modeladmin.verbose_name_plural }}
+ + + + + + + {% for model_class, model_admin in registry.items %} + + + + {% endfor %} +
+ {{ app|title }} +
+ + {{ model_admin.verbose_name_plural|title }} + +
+{% endfor %} {% endblock content %} diff --git a/djadmin2/views.py b/djadmin2/views.py index 30f2728..8c088e7 100644 --- a/djadmin2/views.py +++ b/djadmin2/views.py @@ -42,7 +42,6 @@ class AdminModel2Mixin(Admin2Mixin, AccessMixin): def dispatch(self, request, *args, **kwargs): # Check if user has necessary permissions. If the permission_type isn't specified then check for staff status. - print "distpatch perm check:", self.permission_type has_permission = self.modeladmin.has_permission(request, self.permission_type) \ if self.permission_type else request.user.is_staff # Raise exception or redirect to login if user doesn't have permissions. @@ -79,11 +78,13 @@ class AdminModel2Mixin(Admin2Mixin, AccessMixin): class IndexView(Admin2Mixin, generic.TemplateView): default_template_name = "index.html" registry = None + apps = None def get_context_data(self, **kwargs): data = super(IndexView, self).get_context_data(**kwargs) data.update({ - 'registry': self.registry + 'apps': self.apps, + 'registry': self.registry, }) return data diff --git a/docs/contributing.rst b/docs/contributing.rst index 40f5261..535a344 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -22,7 +22,7 @@ Local Installation 1. Create a **virtualenv**. Activate it. 2. cd into django-admin2 -3. type ``$ python setup.py develop`` +3. type ``$ pip install -r requirements.txt`` Issues! diff --git a/example/example/settings.py b/example/example/settings.py index 6cf54ad..6de83ad 100644 --- a/example/example/settings.py +++ b/example/example/settings.py @@ -108,6 +108,8 @@ TEMPLATE_DIRS = ( # Don't forget to use absolute paths, not relative paths. ) +TEST_RUNNER = 'django_coverage.coverage_runner.CoverageRunner' + INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', @@ -118,6 +120,7 @@ INSTALLED_APPS = ( 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', + 'django_coverage', 'djadmin2', 'blog', ) @@ -153,3 +156,19 @@ LOGGING = { ADMIN2_THEME_DIRECTORY = "admin2/bootstrap/" + + +########## TOOLBAR CONFIGURATION +# See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation +INSTALLED_APPS += ( + 'debug_toolbar', +) + +# See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation +INTERNAL_IPS = ('127.0.0.1',) + +# See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation +MIDDLEWARE_CLASSES += ( + 'debug_toolbar.middleware.DebugToolbarMiddleware', +) +########## END TOOLBAR CONFIGURATION diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d51dbe7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +django>=1.5.0 +django-braces==1.0.0 +djangorestframework==2.3.3 +django-debug-toolbar==0.9.4 +coverage==3.6 +django-coverage==1.2.2