Ticket #14402: 14402.diff

File 14402.diff, 7.5 KB (added by Ramiro Morales, 14 years ago)

Patch, includes tests

  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    a b  
    172172
    173173        if db_field.name in self.raw_id_fields:
    174174            kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.rel, using=db)
    175             kwargs['help_text'] = ''
    176175        elif db_field.name in (list(self.filter_vertical) + list(self.filter_horizontal)):
    177176            kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name, (db_field.name in self.filter_vertical))
    178177
  • django/contrib/admin/templates/admin/includes/fieldset.html

    diff --git a/django/contrib/admin/templates/admin/includes/fieldset.html b/django/contrib/admin/templates/admin/includes/fieldset.html
    a b  
    1818                            {{ field.field }}
    1919                        {% endif %}
    2020                    {% endif %}
    21                     {% if field.field.field.help_text %}
    22                         <p class="help">{{ field.field.field.help_text|safe }}</p>
     21                    {% if field.field.help_text %}
     22                        <p class="help">{{ field.field.help_text|safe }}</p>
    2323                    {% endif %}
    2424                </div>
    2525            {% endfor %}
  • django/db/models/fields/related.py

    diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
    a b  
    88from django.db.models.query import QuerySet
    99from django.db.models.query_utils import QueryWrapper
    1010from django.utils.encoding import smart_unicode
    11 from django.utils.translation import ugettext_lazy as _, string_concat, ungettext, ugettext
     11from django.utils.translation import ugettext_lazy as _, ungettext, ugettext
    1212from django.utils.functional import curry
    1313from django.core import exceptions
    1414from django import forms
     
    10001000
    10011001        Field.__init__(self, **kwargs)
    10021002
    1003         msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.')
    1004         self.help_text = string_concat(self.help_text, ' ', msg)
    1005 
    10061003    def get_choices_default(self):
    10071004        return Field.get_choices(self, include_blank=False)
    10081005
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    a b  
    77from django.utils.encoding import smart_unicode, force_unicode
    88from django.utils.datastructures import SortedDict
    99from django.utils.text import get_text_list, capfirst
    10 from django.utils.translation import ugettext_lazy as _, ugettext
     10from django.utils.translation import ugettext_lazy as _, ugettext, string_concat
    1111
    1212from django.core.exceptions import ValidationError, NON_FIELD_ERRORS, \
    1313                                   FieldError
     
    10271027    def __init__(self, queryset, cache_choices=False, required=True,
    10281028                 widget=None, label=None, initial=None,
    10291029                 help_text=None, *args, **kwargs):
     1030        msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.')
     1031        if help_text is None:
     1032            help_text = msg
     1033        else:
     1034            help_text = string_concat(help_text, ' ', msg)
    10301035        super(ModelMultipleChoiceField, self).__init__(queryset, None,
    10311036            cache_choices, required, widget, label, initial, help_text,
    10321037            *args, **kwargs)
  • tests/regressiontests/admin_widgets/models.py

    diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py
    a b  
    44from django.core.files.storage import default_storage
    55from django.contrib.auth.models import User
    66
    7 class MyFileField(models.FileField): 
    8     pass 
     7class MyFileField(models.FileField):
     8    pass
    99
    1010class Member(models.Model):
    1111    name = models.CharField(max_length=100)
     
    3131    def __unicode__(self):
    3232        return self.name
    3333
     34class Director(models.Model):
     35    name = models.CharField(max_length=40)
     36
     37    def __unicode__(self):
     38        return self.name
     39
     40class Genre(models.Model):
     41    name = models.CharField(max_length=40)
     42
     43    def __unicode__(self):
     44        return self.name
     45
     46class Orchestra(models.Model):
     47    name = models.CharField(max_length=100)
     48    members = models.ManyToManyField(Member, help_text='This is the orchestra members help_text.')
     49    director = models.ForeignKey(Director)
     50    genres = models.ManyToManyField(Genre, help_text='This is the orchestra genres help_text.')
     51
     52    def __unicode__(self):
     53        return self.name
     54
    3455class HiddenInventoryManager(models.Manager):
    3556    def get_query_set(self):
    3657        return super(HiddenInventoryManager, self).get_query_set().filter(hidden=False)
  • tests/regressiontests/admin_widgets/tests.py

    diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py
    a b  
    163163
    164164            self.assertContains(response,
    165165                'Select a valid choice. That choice is not one of the available choices.')
     166
     167class Ticket14402(DjangoTestCase):
     168    fixtures = ["admin-widgets-users.xml"]
     169    admin_root = '/widget_admin'
     170
     171    def setUp(self):
     172        self.client.login(username="super", password="secret")
     173
     174    def tearDown(self):
     175        self.client.logout()
     176
     177    def test_m2m_has_helptext(self):
     178        """Non raw_id m2m model field help_text shouldn't be affected by the fix for this ticket."""
     179        response = self.client.get('%s/admin_widgets/orchestra/add/' % self.admin_root)
     180        self.assert_("This is the orchestra genres help_text." in response.content)
     181
     182    def test_inline_m2m_has_helptext(self):
     183        """Non raw_id m2m model field help_text shouldn't be affected by the fix for this ticket (inline case)."""
     184        response = self.client.get('%s/admin_widgets/director/add/' % self.admin_root)
     185        self.assert_("This is the orchestra genres help_text." in response.content)
     186
     187    def test_raw_id_m2m_has_helptext(self):
     188        """raw_id m2m model field help_text shouldn't be ignored when displaying its admin widget."""
     189        response = self.client.get('%s/admin_widgets/orchestra/add/' % self.admin_root)
     190        self.assert_("This is the orchestra members help_text." in response.content)
     191
     192    def test_raw_id_inline_m2m_has_helptext(self):
     193        """raw_id m2m model field help_text shouldn't be ignored when displaying the admin widget (inline case)."""
     194        response = self.client.get('%s/admin_widgets/director/add/' % self.admin_root)
     195        self.assert_("This is the orchestra members help_text." in response.content)
  • tests/regressiontests/admin_widgets/widgetadmin.py

    diff --git a/tests/regressiontests/admin_widgets/widgetadmin.py b/tests/regressiontests/admin_widgets/widgetadmin.py
    a b  
    2222class EventAdmin(admin.ModelAdmin):
    2323    raw_id_fields = ['band']
    2424
     25class OrchestraAdmin(admin.ModelAdmin):
     26    raw_id_fields = ['members']
     27
     28class OrchestraInline(admin.StackedInline):
     29    model = models.Orchestra
     30    raw_id_fields = ['members']
     31
     32class DirectorAdmin(admin.ModelAdmin):
     33    inlines = [OrchestraInline]
     34
    2535site = WidgetAdmin(name='widget-admin')
    2636
    2737site.register(models.User)
    2838site.register(models.Car, CarAdmin)
    2939site.register(models.CarTire, CarTireAdmin)
    3040site.register(models.Event, EventAdmin)
     41site.register(models.Orchestra, OrchestraAdmin)
     42site.register(models.Director, DirectorAdmin)
Back to Top