Ticket #9071: add-r9017-tests.diff

File add-r9017-tests.diff, 2.0 KB (added by Ivan Giuliani, 12 years ago)
  • tests/regressiontests/admin_widgets/models.py

     
    3939>>> from django.contrib.admin.widgets import FilteredSelectMultiple, AdminSplitDateTime
    4040>>> from django.contrib.admin.widgets import AdminFileWidget, ForeignKeyRawIdWidget, ManyToManyRawIdWidget
    4141>>> from django.contrib.admin.widgets import RelatedFieldWidgetWrapper
     42>>> from django.contrib.admin import site
     43>>> from django.forms.widgets import Select as SelectWidget
    4244
    4345Calling conditional_escape on the output of widget.render will simulate what
    4446happens in the template. This is easier than setting up a template and context
     
    101103>>> w = ForeignKeyRawIdWidget(rel)
    102104>>> print w.render('test', core.parent_id, attrs={})
    103105<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Apple</strong>
     106
     107
     108# Check that RelatedFieldWidgetWrapper doesn'tshow the add image when explicitely
     109# requested
     110>>> site.register(Band)
     111>>> rel = Album._meta.get_field('band').rel
     112>>> w = RelatedFieldWidgetWrapper(SelectWidget(), rel, site, True)
     113>>> print w.render('test', 'test')
     114<select name="test">
     115</select><a href="../../../admin_widgets/band/add/" class="add-another" id="add_id_test" onclick="return showAddAnotherPopup(this);"> <img src="/media/img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>
     116
     117>>> w = RelatedFieldWidgetWrapper(SelectWidget(), rel, site, False)
     118>>> print w.render('test', 'test')
     119<select name="test">
     120</select>
     121
    104122""" % {
    105123    'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
    106124    'STORAGE_URL': default_storage.url(''),
    107125}}
     126
Back to Top