Merge remote-tracking branch 'origin/master' into inline-formsets

This commit is contained in:
Andrew Ingram 2013-05-19 13:11:01 +02:00
commit 0ebedc8dfd
7 changed files with 68 additions and 10 deletions

View file

@ -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

View file

@ -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):

View file

@ -1,10 +1,28 @@
{% extends "admin2/bootstrap/base.html" %}
{% block content %}
<h1>Index</h1>
<table>
{% for modeladmin in registry.values %}
<tr><td><a href="{{ modeladmin.get_index_url }}">{{ modeladmin.verbose_name_plural }}</a></td></tr>
{% endfor %}
<h3>Site administration</h3>
{% for app, registry in apps.items %}
<table class="table">
<thead>
<tr>
<th>
<a href="TODO {{ app.get_index_url }}">{{ app|title }}</a>
</th>
</tr>
</thead>
<tbody>
{% for model_class, model_admin in registry.items %}
<tr>
<td>
<a href="{{ model_admin.get_index_url }}">
{{ model_admin.verbose_name_plural|title }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endfor %}
{% endblock content %}

View file

@ -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

View file

@ -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!

View file

@ -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

6
requirements.txt Normal file
View file

@ -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