Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Patch for Ticket #13629 #158

Closed
wants to merge 2 commits into from

3 participants

Phillip Chin Julien Phalip Florian Apolloner
Phillip Chin

This is a patch and unit test for Ticket #13629 - Admin Changelist: add app-model_name class to

tag.
https://code.djangoproject.com/ticket/13629#comment:10
Julien Phalip jphalip commented on the diff June 16, 2012
django/contrib/admin/templates/admin/index.html
@@ -5,7 +5,7 @@
5 5
 
6 6
 {% block coltype %}colMS{% endblock %}
7 7
 
8  
-{% block bodyclass %}dashboard{% endblock %}
  8
+{% block bodyclass %}dashboard {{ app_label|default:"home" }}{% endblock %}
9 9
 
1
Julien Phalip Owner
jphalip added a note June 16, 2012

There's no need to add a class here, as there already is 'dashboard'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Julien Phalip jphalip commented on the diff June 16, 2012
tests/mkd_run_admin_test.ksh
((2 lines not shown))
  2
+
  3
+export DJANGO_LIVE_TEST_SERVER_ADDRESS=localhost:5150
  4
+
  5
+python runtests.py --settings=test_sqlite admin_changelist
  6
+python runtests.py --settings=test_sqlite admin_custom_urls
  7
+python runtests.py --settings=test_sqlite admin_filters
  8
+python runtests.py --settings=test_sqlite admin_inlines
  9
+python runtests.py --settings=test_sqlite admin_ordering
  10
+python runtests.py --settings=test_sqlite admin_registration
  11
+python runtests.py --settings=test_sqlite admin_scripts
  12
+python runtests.py --settings=test_sqlite admin_util
  13
+python runtests.py --settings=test_sqlite admin_validation
  14
+python runtests.py --settings=test_sqlite admin_views
  15
+python runtests.py --settings=test_sqlite admin_widgets
  16
+
  17
+
1
Julien Phalip Owner
jphalip added a note June 16, 2012

Looks like you forgot to remove this file :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Julien Phalip jphalip commented on the diff June 16, 2012
tests/regressiontests/admin_views/tests.py
@@ -90,6 +90,16 @@ def testBasicAddGet(self):
90 90
         self.assertIsInstance(response, TemplateResponse)
91 91
         self.assertEqual(response.status_code, 200)
92 92
 
  93
+    def testAppModelNameInClassForBodyTag(self):
  94
+        """
  95
+        Ticket #13629 - Admin Changelist: add app-model_name class to <body> tag
  96
+        """
  97
+        response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit)
  98
+        self.assertEqual(response.status_code, 200)   
  99
+        self.assertContains(response, '<body class="admin_views-section change-form">',
  100
+            msg_prefix="Couldn't find app model name in class for the body tag"
  101
+        )     
  102
+
1
Julien Phalip Owner
jphalip added a note June 16, 2012

Could you add tests for all the other views?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Julien Phalip
Owner

This generally looks good, thank you. Now that I've thought about it some more, I think the classes should in fact be app- and model-. This would allow to dissociate the app from the model, and have for example app-wide styles.

Some templates are also missing: app_index.html and object_history.html

Thanks!

Phillip Chin

Julien, I'm in the process of making those changes but you can you clarify what you mean by "the classes should in fact be app- and model-."? Right now, an admin link such as '/test_admin/%s/admin_views/section/add/' will have '

' for the body tag. I think what you're suggesting is to also have a class for the body tag for non-admin (regular) pages. If this is true, could you give me an example of what the class for the non-admin body tag should be called?
Julien Phalip
Owner

Hi Phil. Sorry for the late reply. What I mean is that, if we have an app called 'blog' and a model called 'Entry', then we should have two classes: app-blog and model-entry. Both classes would be used on the add/change/history/delete views, and only the app-blog class would be used on the app index view. Does it make sense?

Florian Apolloner
Owner

Closing here since #575 seems to have way more tests and is cleaned up a bit.

Florian Apolloner apollo13 closed this December 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  django/contrib/admin/options.py
@@ -1237,6 +1237,7 @@ def changelist_view(self, request, extra_context=None):
1237 1237
             'cl': cl,
1238 1238
             'media': media,
1239 1239
             'has_add_permission': self.has_add_permission(request),
  1240
+            'opts': opts,
1240 1241
             'app_label': app_label,
1241 1242
             'action_form': action_form,
1242 1243
             'actions_on_top': self.actions_on_top,
1  django/contrib/admin/sites.py
@@ -431,6 +431,7 @@ def app_index(self, request, app_label, extra_context=None):
431 431
         context = {
432 432
             'title': _('%s administration') % capfirst(app_label),
433 433
             'app_list': [app_dict],
  434
+            'app_label': app_label,
434 435
         }
435 436
         context.update(extra_context or {})
436 437
 
2  django/contrib/admin/templates/admin/change_list.html
@@ -34,7 +34,7 @@
34 34
 {% endif %}{% endif %}
35 35
 {% endblock %}
36 36
 
37  
-{% block bodyclass %}change-list{% endblock %}
  37
+{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-list{% endblock %}
38 38
 
39 39
 {% if not is_popup %}
40 40
 {% block breadcrumbs %}
2  django/contrib/admin/templates/admin/delete_confirmation.html
@@ -2,6 +2,8 @@
2 2
 {% load i18n %}
3 3
 {% load admin_urls %}
4 4
 
  5
+{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} delete-confirmation{% endblock %}
  6
+
5 7
 {% block breadcrumbs %}
6 8
 <div class="breadcrumbs">
7 9
 <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
2  django/contrib/admin/templates/admin/delete_selected_confirmation.html
@@ -2,6 +2,8 @@
2 2
 {% load i18n l10n %}
3 3
 {% load admin_urls %}
4 4
 
  5
+{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} delete-confirmation delete-selected-confirmation{% endblock %}
  6
+
5 7
 {% block breadcrumbs %}
6 8
 <div class="breadcrumbs">
7 9
 <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
2  django/contrib/admin/templates/admin/index.html
@@ -5,7 +5,7 @@
5 5
 
6 6
 {% block coltype %}colMS{% endblock %}
7 7
 
8  
-{% block bodyclass %}dashboard{% endblock %}
  8
+{% block bodyclass %}dashboard {{ app_label|default:"home" }}{% endblock %}
9 9
 
10 10
 {% block breadcrumbs %}{% endblock %}
11 11
 
17  tests/mkd_run_admin_test.ksh
... ...
@@ -0,0 +1,17 @@
  1
+#!/bin/ksh
  2
+
  3
+export DJANGO_LIVE_TEST_SERVER_ADDRESS=localhost:5150
  4
+
  5
+python runtests.py --settings=test_sqlite admin_changelist
  6
+python runtests.py --settings=test_sqlite admin_custom_urls
  7
+python runtests.py --settings=test_sqlite admin_filters
  8
+python runtests.py --settings=test_sqlite admin_inlines
  9
+python runtests.py --settings=test_sqlite admin_ordering
  10
+python runtests.py --settings=test_sqlite admin_registration
  11
+python runtests.py --settings=test_sqlite admin_scripts
  12
+python runtests.py --settings=test_sqlite admin_util
  13
+python runtests.py --settings=test_sqlite admin_validation
  14
+python runtests.py --settings=test_sqlite admin_views
  15
+python runtests.py --settings=test_sqlite admin_widgets
  16
+
  17
+
10  tests/regressiontests/admin_views/tests.py
@@ -90,6 +90,16 @@ def testBasicAddGet(self):
90 90
         self.assertIsInstance(response, TemplateResponse)
91 91
         self.assertEqual(response.status_code, 200)
92 92
 
  93
+    def testAppModelNameInClassForBodyTag(self):
  94
+        """
  95
+        Ticket #13629 - Admin Changelist: add app-model_name class to <body> tag
  96
+        """
  97
+        response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit)
  98
+        self.assertEqual(response.status_code, 200)   
  99
+        self.assertContains(response, '<body class="admin_views-section change-form">',
  100
+            msg_prefix="Couldn't find app model name in class for the body tag"
  101
+        )     
  102
+
93 103
     def testAddWithGETArgs(self):
94 104
         response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit, {'name': 'My Section'})
95 105
         self.assertEqual(response.status_code, 200)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.