mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-25 18:40:25 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
ff54b31abf
11 changed files with 128 additions and 21 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
@ -78,6 +88,7 @@ class Admin2(object):
|
|||
def get_index_kwargs(self):
|
||||
return {
|
||||
'registry': self.registry,
|
||||
'apps': self.apps,
|
||||
}
|
||||
|
||||
def get_urls(self):
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
class NoAdminSpecified(Exception):
|
||||
pass
|
||||
15
djadmin2/static/themes/bootstrap/css/bootstrap-custom.css
vendored
Normal file
15
djadmin2/static/themes/bootstrap/css/bootstrap-custom.css
vendored
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<!-- Bootstrap -->
|
||||
<link href="{{ STATIC_URL }}themes/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||
<link href="{{ STATIC_URL }}themes/bootstrap/css/bootstrap-custom.css" rel="stylesheet" media="screen">
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-inverse navbar-static-top">
|
||||
|
|
|
|||
|
|
@ -1,10 +1,61 @@
|
|||
{% extends "admin2/bootstrap/base.html" %}
|
||||
{% load admin2_urls %}
|
||||
|
||||
{% 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 %}
|
||||
</table>
|
||||
<h3>Site administration</h3>
|
||||
|
||||
<div class="row">
|
||||
<div class="span7">
|
||||
{% for app, registry in apps.items %}
|
||||
<table class="table table-bordered table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3">
|
||||
<a href="TODO {{ app.get_index_url }}">{{ app|title }}</a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for model_class, model_admin in registry.items %}
|
||||
<tr>
|
||||
<td width="40%">
|
||||
<a href="{{ model_admin.get_index_url }}">
|
||||
{{ model_admin.verbose_name_plural|title }}
|
||||
</a>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<<<<<<< HEAD
|
||||
{# if has_add_permission #}
|
||||
<a href="TODO">
|
||||
=======
|
||||
<a href="{% url model_admin|admin2_urlname:'create' %}">
|
||||
>>>>>>> fix-admin-index-links
|
||||
<i class="icon-plus"></i>
|
||||
|
||||
Add
|
||||
</a>
|
||||
{# endif #}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<<<<<<< HEAD
|
||||
<a href="{{ model_admin.get_index_url }}">
|
||||
=======
|
||||
<a href="{# FIXME: edit kind of doesn't make sense for the whole ModelAdmin #}">
|
||||
>>>>>>> fix-admin-index-links
|
||||
<i class="icon-pencil"></i>
|
||||
Change
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="span5">
|
||||
<h4>Recent Actions</h4>
|
||||
<h5>My Actions</h5>
|
||||
TODO
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
@ -173,7 +173,7 @@ First we pull the code into a local branch::
|
|||
|
||||
Then we run the tests::
|
||||
|
||||
python manage.py test
|
||||
./runtests.py
|
||||
|
||||
We finish with a non-fastforward merge (to preserve the branch history) and push to GitHub::
|
||||
|
||||
|
|
|
|||
|
|
@ -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
6
requirements.txt
Normal 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
|
||||
Loading…
Reference in a new issue