-
Notifications
You must be signed in to change notification settings - Fork 2
Django admin #46
Django admin #46
Changes from all commits
f642d84
887fa01
5bfd43e
3a1bb85
b011d8b
32c1670
f6f75f2
f593541
707114c
e7dcfee
a6979c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from django.contrib import admin | ||
| from polymorphic_tree.admin import ( | ||
| PolymorphicMPTTChildModelAdmin, | ||
| PolymorphicMPTTParentModelAdmin, | ||
| ) | ||
|
|
||
| from .models import Route | ||
|
|
||
|
|
||
| class BaseRouteChildAdmin(PolymorphicMPTTChildModelAdmin): | ||
| """Common base of all Route subclass admin classes.""" | ||
| GENERAL_FIELDSET = (None, { | ||
| 'fields': ('slug', 'parent'), | ||
| }) | ||
|
|
||
| base_model = Route | ||
| base_fieldsets = (GENERAL_FIELDSET,) | ||
|
|
||
|
|
||
| class RouteParentAdmin(PolymorphicMPTTParentModelAdmin): | ||
| """The master admin class for Route.""" | ||
| base_model = Route | ||
| list_display = ('__str__', 'actions_column') | ||
| polymorphic_list = True | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test content of list for this. |
||
|
|
||
| class Media: | ||
| css = { | ||
| 'all': ('admin/treenode/admin.css',) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs check to ensure that
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this css do anyway?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| def get_child_models(self): | ||
| """Collect the admin classes of all subclasses of Route.""" | ||
| subclasses = self.base_model.__subclasses__() | ||
|
|
||
| child_models = [] | ||
| for subclass in subclasses: | ||
| admin_class = subclass.get_admin_class() | ||
| if admin_class is not None: | ||
| child_models.append((subclass, admin_class)) | ||
| return child_models | ||
|
|
||
| admin.site.register(Route, RouteParentAdmin) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ class Route(PolymorphicMPTTModel): | |
| slug = models.SlugField( | ||
| max_length=255, | ||
| default='', | ||
| blank=True, | ||
| help_text=_('The url fragment at this point in the Route hierarchy.'), | ||
| ) | ||
| # Cached location in tree. Reflects parent and slug on self and ancestors. | ||
|
|
@@ -76,6 +77,17 @@ def __str__(self): | |
| """Display a Route's class and url.""" | ||
| return '{} @ {}'.format(self.__class__.__name__, self.url) | ||
|
|
||
| @classmethod | ||
| def get_admin_class(cls): | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| """ | ||
| Return the class to use in the admin. | ||
|
|
||
| This is only used for subclasses of Route. To disable the | ||
| subclass in the admin, make this method return None. | ||
| """ | ||
| from .admin import BaseRouteChildAdmin | ||
| return BaseRouteChildAdmin | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There;s probably a nicer way to get this done. Possibly using |
||
|
|
||
| def get_handler_class(self): | ||
| """Import a class from the python path string in `self.handler`.""" | ||
| return import_from_dotted_path(self.handler) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from incuna_test_utils.testcases.integration import BaseAdminIntegrationTestCase | ||
|
|
||
| from conman.tests.factories import AdminFactory | ||
| from .factories import RootRouteFactory | ||
| from ..models import Route | ||
|
|
||
|
|
||
| class TestRouteAdmin(BaseAdminIntegrationTestCase): | ||
| """Test the functionality of the Route admin.""" | ||
| user_factory = AdminFactory | ||
| model = Route | ||
|
|
||
| def test_add_page(self): | ||
| """Ensure the add page is accessible.""" | ||
| response = self.get_admin_add_page() | ||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| def test_changelist_page(self): | ||
| """Ensure the list page is accessible.""" | ||
| response = self.get_admin_changelist_page() | ||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| def test_change_page(self): | ||
| """Ensure the update page is accessible.""" | ||
| route = RootRouteFactory.create() | ||
| response = self.get_admin_change_page(route) | ||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| def test_delete_page(self): | ||
| """Ensure the delete page is accessible.""" | ||
| route = RootRouteFactory.create() | ||
| response = self.get_admin_delete_page(route) | ||
| self.assertEqual(response.status_code, 200) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| from django.conf.urls import include, url | ||
| from django.contrib import admin | ||
|
|
||
|
|
||
| urlpatterns = [ | ||
| url(r'^admin/', include(admin.site.urls)), | ||
| url(r'', include('conman.routes.urls')), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| from django.conf.urls import include, url | ||
| from django.contrib import admin | ||
|
|
||
|
|
||
| urlpatterns = [ | ||
| url(r'^admin/', include(admin.site.urls)), | ||
| url(r'^sirtrevor/', include('sirtrevor.urls')), | ||
| url(r'', include('conman.routes.urls')), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,5 +25,6 @@ | |
| 'django-mptt>=0.7.4,<=0.8', | ||
| 'django-polymorphic-tree>=1.1,<2', | ||
| 'django-sirtrevor>=0.2.4,<0.3', | ||
| 'pillow>=2.9.0,<3', | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was required by |
||
| ], | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make FKs
raw_idfield.