From 36b502f7c79368fdd9dd0009ebb74e4ac1d189ec Mon Sep 17 00:00:00 2001 From: Peter Inglesby Date: Sun, 19 May 2013 10:39:32 +0200 Subject: [PATCH 1/7] Remove spurious print statement --- djadmin2/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/djadmin2/views.py b/djadmin2/views.py index 6d95db6..35575d7 100644 --- a/djadmin2/views.py +++ b/djadmin2/views.py @@ -39,7 +39,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. From b71fd7382da4d33ed89f12806157f2e308a3a3a4 Mon Sep 17 00:00:00 2001 From: Ludvig Wadenstein Date: Sun, 19 May 2013 11:34:20 +0200 Subject: [PATCH 2/7] Added requirements file --- docs/contributing.rst | 2 +- requirements.txt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 requirements.txt 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/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0d5933b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +django>=1.5.0 +django-braces==1.0.0 +djangorestframework==2.3.3 +django-debug-toolbar==0.9.4 +coverage==3.6 From 25f3e598f3dc246ae5053a285b15e59b0da70fd3 Mon Sep 17 00:00:00 2001 From: Daniel Greenfeld Date: Sun, 19 May 2013 12:09:12 +0200 Subject: [PATCH 3/7] Added self.apps in the registration method of core.Admin2 #81 --- djadmin2/core.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/djadmin2/core.py b/djadmin2/core.py index e9a7e49..a289a7a 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] From f411b63fd4192a69434dce2d272dd952c58a76b5 Mon Sep 17 00:00:00 2001 From: Ludvig Wadenstein Date: Sun, 19 May 2013 12:08:17 +0200 Subject: [PATCH 4/7] Added django-coverage as test runner --- example/example/settings.py | 3 +++ requirements.txt | 1 + 2 files changed, 4 insertions(+) diff --git a/example/example/settings.py b/example/example/settings.py index 6cf54ad..2b7e450 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', ) diff --git a/requirements.txt b/requirements.txt index 0d5933b..d51dbe7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ django-braces==1.0.0 djangorestframework==2.3.3 django-debug-toolbar==0.9.4 coverage==3.6 +django-coverage==1.2.2 From 53e359f5bdd5dbc7fc793b24418703340bd9f047 Mon Sep 17 00:00:00 2001 From: Ludvig Wadenstein Date: Sun, 19 May 2013 12:40:26 +0200 Subject: [PATCH 5/7] Changed how travis install requirements --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 123104828173bc5db301b2d97ab7902092b3639e Mon Sep 17 00:00:00 2001 From: Audrey Roy Date: Sun, 19 May 2013 13:03:25 +0200 Subject: [PATCH 6/7] Better index view. First part of #81 --- djadmin2/core.py | 1 + .../templates/admin2/bootstrap/index.html | 28 +++++++++++++++---- djadmin2/views.py | 4 ++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/djadmin2/core.py b/djadmin2/core.py index a289a7a..8e2138c 100644 --- a/djadmin2/core.py +++ b/djadmin2/core.py @@ -78,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 35575d7..5afce4c 100644 --- a/djadmin2/views.py +++ b/djadmin2/views.py @@ -75,11 +75,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 From 69bf7b497eed6b0f2903ef416d0c5fd646729dfd Mon Sep 17 00:00:00 2001 From: Daniel Greenfeld Date: Sun, 19 May 2013 13:10:02 +0200 Subject: [PATCH 7/7] Get djang-debug-toolbar into the demo --- example/example/settings.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/example/example/settings.py b/example/example/settings.py index 2b7e450..6de83ad 100644 --- a/example/example/settings.py +++ b/example/example/settings.py @@ -156,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