Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Patch by Justin R. Donnelly for helpers.py #533

Closed
wants to merge 1 commit into from

2 participants

@edwtjo

Integrated read only test for his use case

[ticket: 17911]

@edwtjo edwtjo Patch by Justin R. Donnelly for helpers.py
Integrated read only test for his use case

[ticket: 17911]
5581655
@jphalip
Collaborator

Merged in 29d59a8. Thanks!

@jphalip jphalip closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 18, 2012
  1. @edwtjo

    Patch by Justin R. Donnelly for helpers.py

    edwtjo authored
    Integrated read only test for his use case
    
    [ticket: 17911]
This page is out of date. Refresh to see the latest.
View
4 django/contrib/admin/helpers.py
@@ -186,9 +186,7 @@ def contents(self):
if getattr(attr, "allow_tags", False):
result_repr = mark_safe(result_repr)
else:
- if value is None:
- result_repr = EMPTY_CHANGELIST_VALUE
- elif isinstance(f.rel, ManyToManyRel):
+ if isinstance(f.rel, ManyToManyRel) and value is not None:
result_repr = ", ".join(map(six.text_type, value.all()))
else:
result_repr = display_for_field(value, f)
View
9 tests/regressiontests/admin_views/admin.py
@@ -27,7 +27,7 @@
Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug,
AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod,
AdminOrderedCallable, Report, Color2, UnorderedObject, MainPrepopulated,
- RelatedPrepopulated, UndeletableObject, Simple)
+ RelatedPrepopulated, UndeletableObject, Simple, Choice)
def callable_year(dt_value):
@@ -661,6 +661,13 @@ class AttributeErrorRaisingAdmin(admin.ModelAdmin):
site.register(Color2, CustomTemplateFilterColorAdmin)
site.register(Simple, AttributeErrorRaisingAdmin)
+# Render readonly None fields, via choice, in admin
+class ChoiceList(admin.ModelAdmin):
+ list_display = ['choice']
+ readonly_fields = ['choice']
+ fields = ['choice']
+site.register(Choice, ChoiceList)
+
# Register core models we need in our tests
from django.contrib.auth.models import User, Group
from django.contrib.auth.admin import UserAdmin, GroupAdmin
View
9 tests/regressiontests/admin_views/fixtures/readonly-render-none-fields.json
@@ -0,0 +1,9 @@
+[
+{
+ "pk": 1,
+ "model": "admin_views.choice",
+ "fields": {
+ "choice": null
+ }
+}
+]
View
10 tests/regressiontests/admin_views/models.py
@@ -652,6 +652,16 @@ class UndeletableObject(models.Model):
name = models.CharField(max_length=255)
+class Choice(models.Model):
+ choice = models.CharField(max_length=1,
+ blank=True,
+ null=True,
+ choices=(
+ ('y','Yes'),
+ ('n','No'),
+ (None, 'No opinion')
+ ))
+
class Simple(models.Model):
"""
Simple model with nothing on it for use in testing
View
11 tests/regressiontests/admin_views/tests.py
@@ -46,7 +46,7 @@
OtherStory, ComplexSortedPerson, Parent, Child, AdminOrderedField,
AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject,
- Simple, UndeletableObject)
+ Simple, UndeletableObject, Choice)
ERROR_MESSAGE = "Please enter the correct username and password \
@@ -3003,7 +3003,7 @@ def test_prepopulated_maxlength_localized(self):
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class SeleniumPrePopulatedFirefoxTests(AdminSeleniumWebDriverTestCase):
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
- urls = "regressiontests.admin_views.urls"
+ urls = 'regressiontests.admin_views.urls'
fixtures = ['admin-views-users.xml']
def test_basic(self):
@@ -3128,7 +3128,7 @@ class SeleniumPrePopulatedIETests(SeleniumPrePopulatedFirefoxTests):
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class ReadonlyTest(TestCase):
urls = "regressiontests.admin_views.urls"
- fixtures = ['admin-views-users.xml']
+ fixtures = ['admin-views-users.xml','readonly-render-none-fields.json']
def setUp(self):
self.client.login(username='super', password='secret')
@@ -3198,6 +3198,11 @@ def test_user_password_change_limited_queryset(self):
response = self.client.get('/test_admin/admin2/auth/user/%s/password/' % su.pk)
self.assertEqual(response.status_code, 404)
+ def test_change_form_renders_correct_null_choice_value(self):
+ response = self.client.get('/test_admin/admin/admin_views/choice/1/')
+ self.assertContains(response, '<p>No opinion</p>', html=True)
+ self.assertNotContains(response, '<p>(None)</p>')
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class RawIdFieldsTest(TestCase):
Something went wrong with that request. Please try again.