mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-04-25 00:54:49 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
7704c11cdc
8 changed files with 44 additions and 38 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from django.conf.urls import patterns, include, url
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
|
||||
|
|
@ -16,12 +17,17 @@ class Admin2(object):
|
|||
self.app_name = app_name
|
||||
|
||||
def register(self, model, modeladmin=None, **kwargs):
|
||||
if model in self.registry:
|
||||
raise ImproperlyConfigured
|
||||
if not modeladmin:
|
||||
modeladmin = models.ModelAdmin2
|
||||
self.registry[model] = modeladmin(model, **kwargs)
|
||||
|
||||
def deregister(self, model):
|
||||
del self.registry[model]
|
||||
try:
|
||||
del self.registry[model]
|
||||
except KeyError:
|
||||
raise ImproperlyConfigured
|
||||
|
||||
def autodiscover(self):
|
||||
apps = []
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ class ModelAdmin2(BaseAdmin2):
|
|||
name='index'
|
||||
),
|
||||
url(
|
||||
regex=r'^create/$',
|
||||
regex=r'^create/$',
|
||||
view=self.create_view.as_view(**self.get_create_kwargs()),
|
||||
name='create'
|
||||
),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<h1>Index</h1>
|
||||
<table>
|
||||
{% for modeladmin in registry.values %}
|
||||
<tr><td>{{ modeladmin.verbose_name_plural }}</td></tr>
|
||||
<tr><td><a href="">{{ modeladmin.verbose_name_plural }}</a></td></tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endblock content %}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% endblock content %}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
{% extends "admin2/monkey/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% for app in object_list %}
|
||||
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan=3>{{ app.app_name.title }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for model in app.obj.models %}
|
||||
<tr>
|
||||
<td>{{ model.name }}</td>
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endfor %}
|
||||
|
||||
{% endblock content %}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
from test_models import *
|
||||
from test_utils import *
|
||||
from test_views import *
|
||||
from test_core import *
|
||||
|
|
|
|||
34
djadmin2/tests/test_core.py
Normal file
34
djadmin2/tests/test_core.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import unittest
|
||||
|
||||
from django.db import models
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from ..models import ModelAdmin2
|
||||
from ..core import Admin2
|
||||
|
||||
class Thing(models.Model):
|
||||
pass
|
||||
|
||||
class Admin2Test(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.admin2 = Admin2()
|
||||
|
||||
def test_register(self):
|
||||
self.admin2.register(Thing)
|
||||
self.assertTrue(isinstance(self.admin2.registry[Thing], ModelAdmin2))
|
||||
|
||||
def test_register_error(self):
|
||||
self.admin2.register(Thing)
|
||||
self.assertRaises(ImproperlyConfigured, self.admin2.register, Thing)
|
||||
|
||||
def test_deregister(self):
|
||||
self.admin2.register(Thing)
|
||||
self.admin2.deregister(Thing)
|
||||
self.assertTrue(Thing not in self.admin2.registry)
|
||||
|
||||
def test_deregister_error(self):
|
||||
self.assertRaises(ImproperlyConfigured, self.admin2.deregister, Thing)
|
||||
|
||||
def test_get_urls(self):
|
||||
self.admin2.register(Thing)
|
||||
self.assertEquals(2, len(self.admin2.get_urls()))
|
||||
Loading…
Reference in a new issue