Ticket #13165: patch_13165_20110923.diff
File patch_13165_20110923.diff, 28.0 KB (added by , 13 years ago) |
---|
-
AUTHORS
diff --git a/AUTHORS b/AUTHORS index 6faa171..48433b6 100644
a b answer newbie questions, and generally made Django that much better: 357 357 michael.mcewan@gmail.com 358 358 Paul McLanahan <paul@mclanahan.net> 359 359 Tobias McNulty <http://www.caktusgroup.com/blog> 360 Simon Meers <http://simonmeers.com/> 360 361 Zain Memon 361 362 Christian Metts 362 363 michal@plovarna.cz -
django/contrib/admin/helpers.py
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index 04a3492..0af2375 100644
a b 1 1 from django import forms 2 2 from django.contrib.admin.util import (flatten_fieldsets, lookup_field, 3 display_for_field, label_for_field, help_text_for_field) 3 display_for_field, label_for_field, help_text_for_field, 4 get_related_object, get_changelink_url) 4 5 from django.contrib.admin.templatetags.admin_static import static 5 6 from django.contrib.contenttypes.models import ContentType 6 7 from django.core.exceptions import ObjectDoesNotExist … … class AdminReadonlyField(object): 189 190 result_repr = display_for_field(value, f) 190 191 return conditional_escape(result_repr) 191 192 193 def change_url(self): 194 """ Return admin change URL for field if applicable. """ 195 field, original, model_admin = \ 196 self.field['field'], self.form.instance, self.model_admin 197 try: 198 f, attr, value = lookup_field(field, original, model_admin) 199 except (AttributeError, ValueError, ObjectDoesNotExist): 200 return None 201 return get_changelink_url(value, self.model_admin.admin_site) 202 203 192 204 class InlineAdminFormSet(object): 193 205 """ 194 206 A wrapper around an inline formset for use in the admin system. … … class InlineAdminForm(AdminForm): 254 266 if original is not None: 255 267 self.original_content_type_id = ContentType.objects.get_for_model(original).pk 256 268 self.show_url = original and hasattr(original, 'get_absolute_url') 269 if original is not None and model_admin is not None: 270 self.admin_url = get_changelink_url(original, model_admin.admin_site) 271 else: 272 self.admin_url = None 257 273 super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields, 258 274 readonly_fields, model_admin) 259 275 -
django/contrib/admin/templates/admin/edit_inline/stacked.html
diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html index 476e261..cf6723b 100644
a b 6 6 7 7 {% for inline_admin_form in inline_admin_formset %}<div class="inline-related{% if forloop.last %} empty-form last-related{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}"> 8 8 <h3><b>{{ inline_admin_formset.opts.verbose_name|title }}:</b> <span class="inline_label">{% if inline_admin_form.original %}{{ inline_admin_form.original }}{% else %}#{{ forloop.counter }}{% endif %}</span> 9 {% if inline_admin_form.admin_url %}<a href="{{ inline_admin_form.admin_url }}" class="inline-changelink changelink">{% trans "edit separately" %}</a> {% endif %} 9 10 {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %} 10 11 {% if inline_admin_formset.formset.can_delete and inline_admin_form.original %}<span class="delete">{{ inline_admin_form.deletion_field.field }} {{ inline_admin_form.deletion_field.label_tag }}</span>{% endif %} 11 12 </h3> -
django/contrib/admin/templates/admin/edit_inline/tabular.html
diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html index 71b097e..6741749 100644
a b 27 27 <td class="original"> 28 28 {% if inline_admin_form.original or inline_admin_form.show_url %}<p> 29 29 {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %} 30 {% if inline_admin_form.admin_url %}<a href="{{ inline_admin_form.admin_url }}" class="inline-changelink changelink">{% trans "edit separately" %}</a> {% endif %} 31 30 32 {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %} 31 33 </p>{% endif %} 32 34 {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %} … … 46 48 {% for field in line %} 47 49 <td class="{{ field.field.name }}"> 48 50 {% if field.is_readonly %} 49 <p>{{ field.contents }}</p>51 <p>{{ field.contents }}{% if field.change_url %} <a href="{{ field.change_url }}" class="readonly-changelink changelink">{% trans "edit" %}</a>{% endif %}</p> 50 52 {% else %} 51 53 {{ field.field.errors.as_ul }} 52 54 {{ field.field }} -
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 index 6363aee..8720999 100644
a b 14 14 {% else %} 15 15 {{ field.label_tag }} 16 16 {% if field.is_readonly %} 17 <p>{{ field.contents }} </p>17 <p>{{ field.contents }}{% if field.change_url %} <a href="{{ field.change_url }}" class="readonly-changelink changelink">Edit</a>{% endif %}</p> 18 18 {% else %} 19 19 {{ field.field }} 20 20 {% endif %} -
django/contrib/admin/util.py
diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py index 7204a12..2434c4f 100644
a b from django.utils.html import escape 8 8 from django.utils.safestring import mark_safe 9 9 from django.utils.text import capfirst 10 10 from django.utils.encoding import force_unicode, smart_unicode, smart_str 11 from django.utils.translation import ungettext 12 from django.core.urlresolvers import reverse 11 from django.utils.translation import ungettext, ugettext 12 from django.core.urlresolvers import reverse, NoReverseMatch 13 13 14 14 15 15 def quote(s): … … def get_limit_choices_to_from_path(model, path): 393 393 return limit_choices_to # already a Q 394 394 else: 395 395 return models.Q(**limit_choices_to) # convert dict to Q 396 397 def get_related_object(rel, value): 398 try: 399 return rel.to.objects.get(pk=value) 400 except: 401 return None 402 403 def get_changelink_url(obj, admin_site): 404 """ If obj is registered in admin_site, return URL for change view. """ 405 if admin_site is None: 406 # probably a ManyToManyRawIdWidget 407 return None 408 if obj.__class__ in admin_site._registry: 409 try: 410 view_name = '%s:%s_%s_change' % ( 411 admin_site.name, 412 obj._meta.app_label, 413 obj._meta.object_name.lower()) 414 return reverse(view_name, None, (quote(obj._get_pk_val()),)) 415 except NoReverseMatch: 416 # should not happen, but fail silently just in case 417 pass 418 return None 419 420 def get_changelink_html(obj, admin_site, show_name=False): 421 """ Return HTML link to change view for obj if registered in admin_site. 422 423 Optionally includes representation of object (%s) in link. 424 """ 425 url = get_changelink_url(obj, admin_site) 426 if url is None: 427 return '' 428 if show_name: 429 text = ugettext(u'Edit %s') % force_unicode(obj) 430 else: 431 text = ugettext('Edit') 432 return (u' <a href="%(url)s" class="related-field-changelink changelink">' 433 '%(text)s</a>' % {'url': url, 'text': escape(text)}) -
django/contrib/admin/widgets.py
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 0d1f2a9..8415566 100644
a b Form Widget classes specific to the Django admin site. 4 4 5 5 import copy 6 6 from django import forms 7 from django.contrib.admin.util import get_related_object, get_changelink_html 7 8 from django.contrib.admin.templatetags.admin_static import static 8 9 from django.core.urlresolvers import reverse 9 10 from django.forms.widgets import RadioFieldRenderer … … class ForeignKeyRawIdWidget(forms.TextInput): 154 155 extra.append(u'<img src="%s" width="16" height="16" alt="%s" /></a>' 155 156 % (static('admin/img/selector-search.gif'), _('Lookup'))) 156 157 output = [super(ForeignKeyRawIdWidget, self).render(name, value, attrs)] + extra 158 159 output.append(get_changelink_html( 160 get_related_object(self.rel, value), 161 self.admin_site, show_name=False)) 157 162 if value: 158 163 output.append(self.label_for_value(value)) 159 164 return mark_safe(u''.join(output)) … … class RelatedFieldWidgetWrapper(forms.Widget): 259 264 % (related_url, name)) 260 265 output.append(u'<img src="%s" width="10" height="10" alt="%s"/></a>' 261 266 % (static('admin/img/icon_addlink.gif'), _('Add Another'))) 267 output.append(get_changelink_html( 268 get_related_object(self.rel, value), 269 self.admin_site, show_name=True)) 262 270 return mark_safe(u''.join(output)) 263 271 264 272 def build_attrs(self, extra_attrs=None, **kwargs): -
tests/regressiontests/admin_inlines/admin.py
diff --git a/tests/regressiontests/admin_inlines/admin.py b/tests/regressiontests/admin_inlines/admin.py index 4edd361..43d7232 100644
a b class SottoCapoInline(admin.TabularInline): 109 109 model = SottoCapo 110 110 111 111 112 class IndividualInline(admin.StackedInline): 113 model = Individual 114 extra = 1 115 116 117 class PhoneInline(admin.StackedInline): 118 model = Phone 119 extra = 1 120 121 122 class EmailInline(admin.TabularInline): 123 model = Email 124 extra = 1 125 126 112 127 site.register(TitleCollection, inlines=[TitleInline]) 113 128 # Test bug #12561 and #12778 114 129 # only ModelAdmin media … … site.register(Fashionista, inlines=[InlineWeakness]) 124 139 site.register(Holder4, Holder4Admin) 125 140 site.register(Author, AuthorAdmin) 126 141 site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline]) 142 143 site.register(Household, inlines=[IndividualInline, PhoneInline]) 144 site.register(Individual, inlines=[EmailInline]) 145 site.register(Email) 146 # (Phone not registered) -
tests/regressiontests/admin_inlines/models.py
diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py index 748280d..896b3d0 100644
a b class Consigliere(models.Model): 136 136 class SottoCapo(models.Model): 137 137 name = models.CharField(max_length=100) 138 138 capo_famiglia = models.ForeignKey(CapoFamiglia, related_name='+') 139 140 141 # Test InlineAdminForm.admin_url: 142 143 class Household(models.Model): 144 pass 145 146 147 class Individual(models.Model): 148 household = models.ForeignKey(Household) 149 150 151 class Phone(models.Model): 152 household = models.ForeignKey(Household) 153 number = models.CharField(max_length=64) 154 155 156 class Email(models.Model): 157 individual = models.ForeignKey(Individual) 158 email = models.EmailField() -
tests/regressiontests/admin_inlines/tests.py
diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py index 955d620..6cf077b 100644
a b 1 from django.core import urlresolvers 1 2 from django.contrib.admin.helpers import InlineAdminForm 2 3 from django.contrib.contenttypes.models import ContentType 3 4 from django.test import TestCase 4 5 5 6 # local test models 7 6 8 from models import (Holder, Inner, Holder2, Inner2, Holder3, 7 9 Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child, 8 CapoFamiglia, Consigliere, SottoCapo) 9 from admin import InnerInline 10 CapoFamiglia, Consigliere, SottoCapo, Household, Individual, Phone, Email) 11 12 from admin import site, InnerInline 10 13 11 14 12 15 class TestInline(TestCase): … … class TestInlineAdminForm(TestCase): 196 199 iaf = InlineAdminForm(None, None, {}, {}, joe) 197 200 parent_ct = ContentType.objects.get_for_model(Parent) 198 201 self.assertEqual(iaf.original.content_type, parent_ct) 202 203 204 class TestAdminURL(TestCase): 205 urls = "regressiontests.admin_inlines.urls" 206 fixtures = ['admin-views-users.xml'] 207 208 def get_admin_url(self, obj_or_class, add=False): 209 params = [site.name, obj_or_class._meta.app_label, 210 obj_or_class._meta.module_name] 211 if add: 212 params.append("add") 213 args = () 214 else: 215 params.append("change") 216 args = (obj_or_class.pk,) 217 return urlresolvers.reverse('%s:%s_%s_%s' % tuple(params), args=args) 218 219 def setUp(self): 220 self.household = Household.objects.create() 221 self.individual = Individual.objects.create(household=self.household) 222 self.phone = Phone.objects.create(household=self.household, 223 number='1234567890') 224 self.email = Email.objects.create(individual=self.individual, 225 email='me@example.com') 226 227 result = self.client.login(username='super', password='secret') 228 self.assertEqual(result, True) 229 230 def tearDown(self): 231 self.client.logout() 232 233 def test_admin_url(self): 234 """ 235 admin_url should be set for admin-registered inline models only. 236 237 Also check to ensure URLs look correct and only set on bound forms. 238 """ 239 240 response = self.client.get(self.get_admin_url(self.household)) 241 for inline_admin_fset in response.context[-1]['inline_admin_formsets']: 242 for inline_admin_form in inline_admin_fset: 243 if inline_admin_form.form._meta.model != Individual: 244 self.assertFalse( 245 getattr(inline_admin_form, 'admin_url', None), 246 'admin_url set with unregistered model') 247 elif not inline_admin_form.original: 248 self.assertFalse( 249 getattr(inline_admin_form, 'admin_url', None), 250 'admin_url set on unbound form!') 251 else: 252 self.assertTrue(inline_admin_form.admin_url, 253 'admin_url not set') 254 self.assertEqual( 255 inline_admin_form.original, self.individual, 256 'original is not expected object') 257 self.assertEqual( 258 inline_admin_form.admin_url, 259 self.get_admin_url(inline_admin_form.original), 260 'admin_url appears incorrect') 261 262 def test_link_rendering(self): 263 """ Confirm links are displayed where appropriate. """ 264 LINK_CSS_CLASS = 'inline-changelink' 265 LINK_TEXT = 'edit separately' 266 267 # test StackedInline rendering 268 269 response = self.client.get(self.get_admin_url(Household, 'add')) 270 self.assertNotContains(response, LINK_CSS_CLASS) 271 self.assertNotContains(response, LINK_TEXT) 272 273 response = self.client.get(self.get_admin_url(self.household)) 274 self.assertContains(response, LINK_CSS_CLASS) 275 self.assertContains(response, LINK_TEXT) 276 277 # test TabularInline rendering 278 279 response = self.client.get(self.get_admin_url(Individual, 'add')) 280 self.assertNotContains(response, LINK_CSS_CLASS) 281 self.assertNotContains(response, LINK_TEXT) 282 283 response = self.client.get(self.get_admin_url(self.individual)) 284 self.assertContains(response, LINK_CSS_CLASS) 285 self.assertContains(response, LINK_TEXT) -
tests/regressiontests/admin_views/admin.py
diff --git a/tests/regressiontests/admin_views/admin.py b/tests/regressiontests/admin_views/admin.py index e4aae4f..3d47ab6 100644
a b class PizzaAdmin(admin.ModelAdmin): 385 385 readonly_fields = ('toppings',) 386 386 387 387 388 class DonutOrderAdmin(admin.ModelAdmin): 389 raw_id_fields = ('donut',) 390 391 392 class PizzaOrderAdmin(admin.ModelAdmin): 393 readonly_fields = ('pizza',) 394 395 388 396 class WorkHourAdmin(admin.ModelAdmin): 389 397 list_display = ('datum', 'employee') 390 398 list_filter = ('employee',) … … site.register(Post, PostAdmin) 486 494 site.register(Gadget, GadgetAdmin) 487 495 site.register(Villain) 488 496 site.register(SuperVillain) 497 site.register(Ambush) 489 498 site.register(Plot) 490 499 site.register(PlotDetails) 491 500 site.register(CyclicOne) … … site.register(Book, inlines=[ChapterInline]) 512 521 site.register(Promo) 513 522 site.register(ChapterXtra1, ChapterXtra1Admin) 514 523 site.register(Pizza, PizzaAdmin) 524 site.register(PizzaOrder, PizzaOrderAdmin) 515 525 site.register(Topping) 526 site.register(Donut) 527 site.register(DonutOrder, DonutOrderAdmin) 516 528 site.register(Album, AlbumAdmin) 517 529 site.register(Question) 518 530 site.register(Answer) -
tests/regressiontests/admin_views/models.py
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index bb8d026..f04dfea 100644
a b class SuperSecretHideout(models.Model): 433 433 return self.location 434 434 435 435 436 class Ambush(models.Model): 437 hideout = models.ForeignKey(SecretHideout) 438 when = models.DateTimeField() 439 440 def __unicode__(self): 441 return u'Ambush %s at %s' % (self.hideout, self.when) 442 443 436 444 class CyclicOne(models.Model): 437 445 name = models.CharField(max_length=25) 438 446 two = models.ForeignKey('CyclicTwo') … … class Pizza(models.Model): 458 466 toppings = models.ManyToManyField('Topping') 459 467 460 468 469 class Donut(models.Model): 470 name = models.CharField(max_length=20) 471 toppings = models.ManyToManyField('Topping') 472 473 def __unicode__(self): 474 return self.name 475 476 477 class DonutOrder(models.Model): 478 donut = models.ForeignKey(Donut) 479 quantity = models.IntegerField() 480 481 def __unicode__(self): 482 return '%s x %d' % (self.donut, self.quantity) 483 484 485 class PizzaOrder(models.Model): 486 pizza = models.ForeignKey(Pizza) 487 quantity = models.IntegerField() 488 489 def __unicode__(self): 490 return '%s x %d' % (self.pizza, self.quantity) 491 492 461 493 class Album(models.Model): 462 494 owner = models.ForeignKey(User) 463 495 title = models.CharField(max_length=30) -
tests/regressiontests/admin_views/tests.py
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index b6e7b9e..2761610 100644
a b from django.utils.http import urlencode 31 31 from django.utils import unittest 32 32 33 33 # local test models 34 34 35 from models import (Article, BarAccount, CustomArticle, EmptyModel, 35 36 FooAccount, Gallery, ModelWithStringPrimaryKey, 36 37 Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, … … from models import (Article, BarAccount, CustomArticle, EmptyModel, 38 39 Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee, 39 40 Question, Answer, Inquisition, Actor, FoodDelivery, 40 41 RowLevelChangePermissionModel, Paper, CoverLetter, Story, OtherStory, 41 ComplexSortedPerson, Parent, Child) 42 ComplexSortedPerson, Parent, Child, PlotDetails, Villain, SecretHideout, 43 Ambush, Pizza, PizzaOrder, Topping, Donut, DonutOrder) 44 42 45 43 46 ERROR_MESSAGE = "Please enter the correct username and password \ 44 47 for a staff account. Note that both fields are case-sensitive." … … class AdminCustomSaveRelatedTests(TestCase): 3255 3258 3256 3259 self.assertEqual('Josh Stone', Parent.objects.latest('id').name) 3257 3260 self.assertEqual([u'Catherine Stone', u'Paul Stone'], children_names) 3261 3262 3263 class RelatedLinksTest(TestCase): 3264 urls = "regressiontests.admin_views.urls" 3265 fixtures = ['admin-views-users.xml'] 3266 3267 def setUp(self): 3268 self.client.login(username='super', password='secret') 3269 self.RELATED_LINK_CSS_CLASS = 'related-field-changelink' 3270 self.READONLY_LINK_CSS_CLASS = 'readonly-changelink' 3271 self.black_knight = Villain.objects.create(name='Black Knight') 3272 self.plot = Plot.objects.create(name='None shall <pass>', 3273 team_leader=self.black_knight, 3274 contact=self.black_knight) 3275 self.plot_details = PlotDetails.objects.create( 3276 plot=self.plot, details="I'll bite your legs off!") 3277 self.hideout = SecretHideout.objects.create(villain=self.black_knight, 3278 location='forest') 3279 self.ambush = Ambush.objects.create(hideout=self.hideout, 3280 when=datetime.datetime.now()) 3281 3282 self.pizza = Pizza.objects.create(name='Wafer-thin pizza') 3283 self.topping = Topping.objects.create(name='Mint') 3284 self.pizza.toppings.add(self.topping) 3285 self.donut = Donut.objects.create(name='Wafer-thin donut') 3286 self.donut.toppings.add(self.topping) 3287 self.donut_order = DonutOrder.objects.create(donut=self.donut, 3288 quantity=1000000) 3289 self.pizza_order = PizzaOrder.objects.create(pizza=self.pizza, 3290 quantity=50) 3291 3292 def tearDown(self): 3293 self.client.logout() 3294 3295 def test_foreignkey(self): 3296 """ Confirm changelink appears for populated ForeignKey fields """ 3297 response = self.client.get('/test_admin/admin/admin_views/plot/add/') 3298 self.assertNotContains(response, self.RELATED_LINK_CSS_CLASS) 3299 response = self.client.get('/test_admin/admin/admin_views/plot/%d/' % 3300 self.plot.pk) 3301 self.assertContains(response, self.RELATED_LINK_CSS_CLASS) 3302 self.assertContains(response, '>Edit %s</a>' % self.black_knight) 3303 3304 def test_onetoone(self): 3305 """ Confirm changelink appears for populated OneToOne fields """ 3306 response = self.client.get( 3307 '/test_admin/admin/admin_views/plotdetails/add/') 3308 self.assertNotContains(response, self.RELATED_LINK_CSS_CLASS) 3309 response = self.client.get( 3310 '/test_admin/admin/admin_views/plotdetails/%d/' % 3311 self.plot_details.pk) 3312 self.assertContains(response, self.RELATED_LINK_CSS_CLASS) 3313 self.assertContains(response, '>Edit %s</a>' % escape(self.plot)) 3314 3315 def test_unregistered(self): 3316 """ Confirm changelink does *not* appear for unregistered fields """ 3317 response = self.client.get( 3318 '/test_admin/admin/admin_views/ambush/add/') 3319 self.assertNotContains(response, self.RELATED_LINK_CSS_CLASS) 3320 response = self.client.get( 3321 '/test_admin/admin/admin_views/ambush/%d/' % 3322 self.ambush.pk) 3323 self.assertNotContains(response, self.RELATED_LINK_CSS_CLASS) 3324 3325 def test_readonly(self): 3326 """ Confirm changelink appears for populated readonly fields """ 3327 response = self.client.get( 3328 '/test_admin/admin/admin_views/pizzaorder/add/') 3329 self.assertNotContains(response, self.READONLY_LINK_CSS_CLASS) 3330 response = self.client.get( 3331 '/test_admin/admin/admin_views/pizzaorder/%d/' % 3332 self.pizza_order.pk) 3333 self.assertContains(response, self.READONLY_LINK_CSS_CLASS) 3334 self.assertContains(response, '>Edit</a>') 3335 3336 def test_manytomany(self): 3337 """ Confirm changelinks do *not* appear for ManyToMany fields """ 3338 MULTIPLE_SELECT_STRING = '<select multiple="multiple"' 3339 3340 response = self.client.get( 3341 '/test_admin/admin/admin_views/pizza/add/') 3342 self.assertNotContains(response, self.RELATED_LINK_CSS_CLASS) 3343 self.assertNotContains(response, MULTIPLE_SELECT_STRING) 3344 response = self.client.get( 3345 '/test_admin/admin/admin_views/pizza/%d/' % self.pizza.pk) 3346 self.assertNotContains(response, self.RELATED_LINK_CSS_CLASS) 3347 self.assertNotContains(response, MULTIPLE_SELECT_STRING) 3348 3349 # try non-readonly ManyToMany 3350 response = self.client.get( 3351 '/test_admin/admin/admin_views/donut/add/') 3352 self.assertContains(response, MULTIPLE_SELECT_STRING) 3353 self.assertNotContains(response, self.RELATED_LINK_CSS_CLASS) 3354 response = self.client.get( 3355 '/test_admin/admin/admin_views/donut/%d/' % self.donut.pk) 3356 self.assertNotContains(response, self.RELATED_LINK_CSS_CLASS) 3357 self.assertContains(response, MULTIPLE_SELECT_STRING) 3358 3359 def test_raw_id(self): 3360 """ Confirm links appears for populated raw_id_fields """ 3361 response = self.client.get( 3362 '/test_admin/admin/admin_views/donutorder/add/') 3363 self.assertNotContains(response, self.RELATED_LINK_CSS_CLASS) 3364 response = self.client.get( 3365 '/test_admin/admin/admin_views/donutorder/%d/' % 3366 self.donut_order.pk) 3367 self.assertContains(response, self.RELATED_LINK_CSS_CLASS) 3368 self.assertContains(response, '>Edit</a>') -
tests/regressiontests/admin_widgets/tests.py
diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py index a7bfe55..7d6702d 100644
a b class ForeignKeyRawIdWidgetTest(DjangoTestCase): 255 255 w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site) 256 256 self.assertEqual( 257 257 conditional_escape(w.render('test', band.pk, attrs={})), 258 '<input type="text" name="test" value="%(bandpk)s" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong>Linkin Park</strong>' % dict(admin_media_prefix(), bandpk=band.pk)258 '<input type="text" name="test" value="%(bandpk)s" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <a href="/widget_admin/admin_widgets/band/%(bandpk)s/" class="related-field-changelink changelink">Edit</a> <strong>Linkin Park</strong>' % dict(admin_media_prefix(), bandpk=band.pk) 259 259 ) 260 260 261 261 def test_relations_to_non_primary_key(self): … … class ManyToManyRawIdWidgetTest(DjangoTestCase): 333 333 334 334 self.assertEqual( 335 335 conditional_escape(w.render('test', [m1.pk])), 336 '<input type="text" name="test" value="%(m1pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a> ' % dict(admin_media_prefix(), m1pk=m1.pk)336 '<input type="text" name="test" value="%(m1pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <a href="/widget_admin/admin_widgets/member/%(m1pk)s/" class="related-field-changelink changelink">Edit</a>' % dict(admin_media_prefix(), m1pk=m1.pk) 337 337 ) 338 338 339 339 self.assertEqual(w._has_changed(None, None), False)