From b71fd7382da4d33ed89f12806157f2e308a3a3a4 Mon Sep 17 00:00:00 2001 From: Ludvig Wadenstein Date: Sun, 19 May 2013 11:34:20 +0200 Subject: [PATCH 01/10] 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 f411b63fd4192a69434dce2d272dd952c58a76b5 Mon Sep 17 00:00:00 2001 From: Ludvig Wadenstein Date: Sun, 19 May 2013 12:08:17 +0200 Subject: [PATCH 02/10] 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 03/10] 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 04/10] 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 05/10] 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 From 547fb77c2440c2000194d8ca660e0338ae080190 Mon Sep 17 00:00:00 2001 From: Audrey Roy Date: Sun, 19 May 2013 13:29:28 +0200 Subject: [PATCH 06/10] Stub out more UI parts for #81 --- .../themes/bootstrap/css/bootstrap-custom.css | 15 +++++ djadmin2/templates/admin2/bootstrap/base.html | 1 + .../templates/admin2/bootstrap/index.html | 63 ++++++++++++------- 3 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 djadmin2/static/themes/bootstrap/css/bootstrap-custom.css diff --git a/djadmin2/static/themes/bootstrap/css/bootstrap-custom.css b/djadmin2/static/themes/bootstrap/css/bootstrap-custom.css new file mode 100644 index 0000000..6a29526 --- /dev/null +++ b/djadmin2/static/themes/bootstrap/css/bootstrap-custom.css @@ -0,0 +1,15 @@ +/* Fixes a Bootstrap 2.3 bug. This can be removed when upgrading to Bootstrap v3. */ +.text-right +{ + text-align: right !important; +} + +.text-center +{ + text-align: center !important; +} + +.text-left +{ + text-align: left !important; +} \ No newline at end of file diff --git a/djadmin2/templates/admin2/bootstrap/base.html b/djadmin2/templates/admin2/bootstrap/base.html index 231b9a8..546f26f 100644 --- a/djadmin2/templates/admin2/bootstrap/base.html +++ b/djadmin2/templates/admin2/bootstrap/base.html @@ -7,6 +7,7 @@ + +
+

Recent Actions

+
My Actions
+ TODO +
+ {% endblock content %} From 56135460ea6b050827701536173dc6c1e803f173 Mon Sep 17 00:00:00 2001 From: Raphael Kimmig Date: Sun, 19 May 2013 13:47:51 +0200 Subject: [PATCH 07/10] fix add links on index page --- djadmin2/templates/admin2/bootstrap/index.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/djadmin2/templates/admin2/bootstrap/index.html b/djadmin2/templates/admin2/bootstrap/index.html index 06e1ac8..080c2a6 100644 --- a/djadmin2/templates/admin2/bootstrap/index.html +++ b/djadmin2/templates/admin2/bootstrap/index.html @@ -1,4 +1,5 @@ {% extends "admin2/bootstrap/base.html" %} +{% load admin2_urls %} {% block content %}

Site administration

@@ -23,13 +24,14 @@ - + + Add - + Edit From e50f26947b0d01198a48a8e207a6454cf4a3e1e8 Mon Sep 17 00:00:00 2001 From: Audrey Roy Date: Sun, 19 May 2013 14:06:27 +0200 Subject: [PATCH 08/10] Change model from index. Stub for Add. Close #81. --- djadmin2/templates/admin2/bootstrap/index.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/djadmin2/templates/admin2/bootstrap/index.html b/djadmin2/templates/admin2/bootstrap/index.html index 06e1ac8..f49e79a 100644 --- a/djadmin2/templates/admin2/bootstrap/index.html +++ b/djadmin2/templates/admin2/bootstrap/index.html @@ -23,15 +23,17 @@ - + {# if has_add_permission #} + Add + {# endif #} - + - Edit + Change From 539dac99575c679893de3f06aef2f0ab4e77e4b2 Mon Sep 17 00:00:00 2001 From: Daniel Greenfeld Date: Sun, 19 May 2013 14:26:03 +0200 Subject: [PATCH 09/10] remove unnecessary exceptions file --- djadmin2/exceptions.py | 2 -- djadmin2/templatetags/admin2_urls.py | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) delete mode 100644 djadmin2/exceptions.py diff --git a/djadmin2/exceptions.py b/djadmin2/exceptions.py deleted file mode 100644 index 31a12c8..0000000 --- a/djadmin2/exceptions.py +++ /dev/null @@ -1,2 +0,0 @@ -class NoAdminSpecified(Exception): - pass diff --git a/djadmin2/templatetags/admin2_urls.py b/djadmin2/templatetags/admin2_urls.py index e5e5395..27d815a 100644 --- a/djadmin2/templatetags/admin2_urls.py +++ b/djadmin2/templatetags/admin2_urls.py @@ -4,5 +4,9 @@ register = template.Library() @register.filter -def admin2_urlname(value, arg): - return 'admin2:%s_%s_%s' % (value.app_label, value.model_name, arg) +def admin2_urlname(view, action): + """ + Converts the view and the specified action into a valid namespaced URLConf name. + """ + return 'admin2:%s_%s_%s' % (view.app_label, view.model_name, action) + From 594d6f9b27760a18dc562bcee87087cf2f32b9bc Mon Sep 17 00:00:00 2001 From: Daniel Greenfeld Date: Sun, 19 May 2013 14:38:27 +0200 Subject: [PATCH 10/10] Documentation and cleanup of core --- djadmin2/core.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/djadmin2/core.py b/djadmin2/core.py index 8e2138c..3109ce5 100644 --- a/djadmin2/core.py +++ b/djadmin2/core.py @@ -25,7 +25,9 @@ class Admin2(object): def register(self, model, modeladmin=None, **kwargs): """ - Registers the given model with the given admin class. + Registers the given model with the given admin class. Once a model is + registered in self.registry, we also add it to app registries in + self.apps. If no modeladmin is passed, it will use ModelAdmin2. If keyword arguments are given they will be passed to the admin class on @@ -33,8 +35,7 @@ class Admin2(object): 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('%s is already registered in django-admin2' % model) @@ -51,16 +52,25 @@ class Admin2(object): def deregister(self, model): """ - Deregisters the given model. + Deregisters the given model. Remove the model from the self.app as well 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] except KeyError: - raise ImproperlyConfigured + raise ImproperlyConfigured('%s was never registered in django-admin2' % model) + + # Remove the model from the apps registry + # Get the app label + app_label = model._meta.app_label + # Delete the model from it's app registry + del self.apps[app_label][model] + + # if no more models in an app's registry + # then delete the app from the apps. + if self.apps[app_label] is {}: + del self.apps[app_label] # no def autodiscover(self): """