Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10533 -- Worked around an apparent limitation of xgettext.

Looks like we have to use the same format specifiers in both singular and
plural forms of a message or the PO file cannot be compiled to MO format. This
commit changes one place in admin that was using different specifiers.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10081 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4a67fee785d4d71203031fc46c0aafa15c1437a1 1 parent 4a88785
Malcolm Tredinnick authored March 18, 2009

Showing 1 changed file with 117 additions and 114 deletions. Show diff stats Hide diff stats

  1. 231  django/contrib/admin/options.py
231  django/contrib/admin/options.py
@@ -32,11 +32,11 @@ class IncorrectLookupParameters(Exception):
32 32
 
33 33
 # Defaults for formfield_overrides. ModelAdmin subclasses can change this
34 34
 # by adding to ModelAdmin.formfield_overrides.
35  
-    
  35
+
36 36
 FORMFIELD_FOR_DBFIELD_DEFAULTS = {
37  
-    models.DateTimeField: { 
  37
+    models.DateTimeField: {
38 38
         'form_class': forms.SplitDateTimeField,
39  
-        'widget': widgets.AdminSplitDateTime 
  39
+        'widget': widgets.AdminSplitDateTime
40 40
     },
41 41
     models.DateField:    {'widget': widgets.AdminDateWidget},
42 42
     models.TimeField:    {'widget': widgets.AdminTimeWidget},
@@ -51,7 +51,7 @@ class IncorrectLookupParameters(Exception):
51 51
 
52 52
 class BaseModelAdmin(object):
53 53
     """Functionality common to both ModelAdmin and InlineAdmin."""
54  
-    
  54
+
55 55
     raw_id_fields = ()
56 56
     fields = None
57 57
     exclude = None
@@ -62,57 +62,57 @@ class BaseModelAdmin(object):
62 62
     radio_fields = {}
63 63
     prepopulated_fields = {}
64 64
     formfield_overrides = {}
65  
-    
  65
+
66 66
     def __init__(self):
67 67
         self.formfield_overrides = dict(FORMFIELD_FOR_DBFIELD_DEFAULTS, **self.formfield_overrides)
68  
-    
  68
+
69 69
     def formfield_for_dbfield(self, db_field, **kwargs):
70 70
         """
71 71
         Hook for specifying the form Field instance for a given database Field
72 72
         instance.
73  
-        
  73
+
74 74
         If kwargs are given, they're passed to the form Field's constructor.
75 75
         """
76 76
         request = kwargs.pop("request", None)
77  
-        
  77
+
78 78
         # If the field specifies choices, we don't need to look for special
79 79
         # admin widgets - we just need to use a select widget of some kind.
80 80
         if db_field.choices:
81 81
             return self.formfield_for_choice_field(db_field, request, **kwargs)
82  
-        
  82
+
83 83
         # ForeignKey or ManyToManyFields
84 84
         if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
85 85
             # Combine the field kwargs with any options for formfield_overrides.
86  
-            # Make sure the passed in **kwargs override anything in 
  86
+            # Make sure the passed in **kwargs override anything in
87 87
             # formfield_overrides because **kwargs is more specific, and should
88 88
             # always win.
89 89
             if db_field.__class__ in self.formfield_overrides:
90 90
                 kwargs = dict(self.formfield_overrides[db_field.__class__], **kwargs)
91  
-            
  91
+
92 92
             # Get the correct formfield.
93 93
             if isinstance(db_field, models.ForeignKey):
94 94
                 formfield = self.formfield_for_foreignkey(db_field, request, **kwargs)
95 95
             elif isinstance(db_field, models.ManyToManyField):
96 96
                 formfield = self.formfield_for_manytomany(db_field, request, **kwargs)
97  
-            
  97
+
98 98
             # For non-raw_id fields, wrap the widget with a wrapper that adds
99 99
             # extra HTML -- the "add other" interface -- to the end of the
100  
-            # rendered output. formfield can be None if it came from a 
  100
+            # rendered output. formfield can be None if it came from a
101 101
             # OneToOneField with parent_link=True or a M2M intermediary.
102 102
             if formfield and db_field.name not in self.raw_id_fields:
103 103
                 formfield.widget = widgets.RelatedFieldWidgetWrapper(formfield.widget, db_field.rel, self.admin_site)
104 104
 
105 105
             return formfield
106  
-                    
  106
+
107 107
         # If we've got overrides for the formfield defined, use 'em. **kwargs
108 108
         # passed to formfield_for_dbfield override the defaults.
109 109
         if db_field.__class__ in self.formfield_overrides:
110 110
             kwargs = dict(self.formfield_overrides[db_field.__class__], **kwargs)
111 111
             return db_field.formfield(**kwargs)
112  
-            
  112
+
113 113
         # For any other type of field, just call its formfield() method.
114 114
         return db_field.formfield(**kwargs)
115  
-        
  115
+
116 116
     def formfield_for_choice_field(self, db_field, request=None, **kwargs):
117 117
         """
118 118
         Get a form Field for a database Field that has declared choices.
@@ -130,7 +130,7 @@ def formfield_for_choice_field(self, db_field, request=None, **kwargs):
130 130
                     blank_choice=[('', _('None'))]
131 131
                 )
132 132
         return db_field.formfield(**kwargs)
133  
-    
  133
+
134 134
     def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
135 135
         """
136 136
         Get a form Field for a ForeignKey.
@@ -142,7 +142,7 @@ def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
142 142
                 'class': get_ul_class(self.radio_fields[db_field.name]),
143 143
             })
144 144
             kwargs['empty_label'] = db_field.blank and _('None') or None
145  
-        
  145
+
146 146
         return db_field.formfield(**kwargs)
147 147
 
148 148
     def formfield_for_manytomany(self, db_field, request=None, **kwargs):
@@ -152,15 +152,15 @@ def formfield_for_manytomany(self, db_field, request=None, **kwargs):
152 152
         # If it uses an intermediary model, don't show field in admin.
153 153
         if db_field.rel.through is not None:
154 154
             return None
155  
-        
  155
+
156 156
         if db_field.name in self.raw_id_fields:
157 157
             kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.rel)
158 158
             kwargs['help_text'] = ''
159 159
         elif db_field.name in (list(self.filter_vertical) + list(self.filter_horizontal)):
160 160
             kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name, (db_field.name in self.filter_vertical))
161  
-        
  161
+
162 162
         return db_field.formfield(**kwargs)
163  
-    
  163
+
164 164
     def _declared_fieldsets(self):
165 165
         if self.fieldsets:
166 166
             return self.fieldsets
@@ -172,7 +172,7 @@ def _declared_fieldsets(self):
172 172
 class ModelAdmin(BaseModelAdmin):
173 173
     "Encapsulates all admin options and functionality for a given model."
174 174
     __metaclass__ = forms.MediaDefiningClass
175  
-    
  175
+
176 176
     list_display = ('__str__',)
177 177
     list_display_links = ()
178 178
     list_filter = ()
@@ -185,13 +185,13 @@ class ModelAdmin(BaseModelAdmin):
185 185
     save_on_top = False
186 186
     ordering = None
187 187
     inlines = []
188  
-    
  188
+
189 189
     # Custom templates (designed to be over-ridden in subclasses)
190 190
     change_form_template = None
191 191
     change_list_template = None
192 192
     delete_confirmation_template = None
193 193
     object_history_template = None
194  
-    
  194
+
195 195
     def __init__(self, model, admin_site):
196 196
         self.model = model
197 197
         self.opts = model._meta
@@ -201,17 +201,17 @@ def __init__(self, model, admin_site):
201 201
             inline_instance = inline_class(self.model, self.admin_site)
202 202
             self.inline_instances.append(inline_instance)
203 203
         super(ModelAdmin, self).__init__()
204  
-        
  204
+
205 205
     def get_urls(self):
206 206
         from django.conf.urls.defaults import patterns, url
207  
-        
  207
+
208 208
         def wrap(view):
209 209
             def wrapper(*args, **kwargs):
210 210
                 return self.admin_site.admin_view(view)(*args, **kwargs)
211 211
             return update_wrapper(wrapper, view)
212  
-        
  212
+
213 213
         info = self.admin_site.name, self.model._meta.app_label, self.model._meta.module_name
214  
-        
  214
+
215 215
         urlpatterns = patterns('',
216 216
             url(r'^$',
217 217
                 wrap(self.changelist_view),
@@ -230,50 +230,50 @@ def wrapper(*args, **kwargs):
230 230
                 name='%sadmin_%s_%s_change' % info),
231 231
         )
232 232
         return urlpatterns
233  
-    
  233
+
234 234
     def urls(self):
235 235
         return self.get_urls()
236 236
     urls = property(urls)
237  
-    
  237
+
238 238
     def _media(self):
239 239
         from django.conf import settings
240  
-        
  240
+
241 241
         js = ['js/core.js', 'js/admin/RelatedObjectLookups.js']
242 242
         if self.prepopulated_fields:
243 243
             js.append('js/urlify.js')
244 244
         if self.opts.get_ordered_objects():
245 245
             js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js'])
246  
-        
  246
+
247 247
         return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
248 248
     media = property(_media)
249  
-    
  249
+
250 250
     def has_add_permission(self, request):
251 251
         "Returns True if the given request has permission to add an object."
252 252
         opts = self.opts
253 253
         return request.user.has_perm(opts.app_label + '.' + opts.get_add_permission())
254  
-    
  254
+
255 255
     def has_change_permission(self, request, obj=None):
256 256
         """
257 257
         Returns True if the given request has permission to change the given
258 258
         Django model instance.
259  
-        
  259
+
260 260
         If `obj` is None, this should return True if the given request has
261 261
         permission to change *any* object of the given type.
262 262
         """
263 263
         opts = self.opts
264 264
         return request.user.has_perm(opts.app_label + '.' + opts.get_change_permission())
265  
-    
  265
+
266 266
     def has_delete_permission(self, request, obj=None):
267 267
         """
268 268
         Returns True if the given request has permission to change the given
269 269
         Django model instance.
270  
-        
  270
+
271 271
         If `obj` is None, this should return True if the given request has
272 272
         permission to delete *any* object of the given type.
273 273
         """
274 274
         opts = self.opts
275 275
         return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission())
276  
-    
  276
+
277 277
     def queryset(self, request):
278 278
         """
279 279
         Returns a QuerySet of all model instances that can be edited by the
@@ -285,14 +285,14 @@ def queryset(self, request):
285 285
         if ordering:
286 286
             qs = qs.order_by(*ordering)
287 287
         return qs
288  
-    
  288
+
289 289
     def get_fieldsets(self, request, obj=None):
290 290
         "Hook for specifying fieldsets for the add form."
291 291
         if self.declared_fieldsets:
292 292
             return self.declared_fieldsets
293 293
         form = self.get_form(request, obj)
294 294
         return [(None, {'fields': form.base_fields.keys()})]
295  
-    
  295
+
296 296
     def get_form(self, request, obj=None, **kwargs):
297 297
         """
298 298
         Returns a Form class for use in the admin add view. This is used by
@@ -314,7 +314,7 @@ def get_form(self, request, obj=None, **kwargs):
314 314
         }
315 315
         defaults.update(kwargs)
316 316
         return modelform_factory(self.model, **defaults)
317  
-    
  317
+
318 318
     def get_changelist_form(self, request, **kwargs):
319 319
         """
320 320
         Returns a Form class for use in the Formset on the changelist page.
@@ -324,28 +324,28 @@ def get_changelist_form(self, request, **kwargs):
324 324
         }
325 325
         defaults.update(kwargs)
326 326
         return modelform_factory(self.model, **defaults)
327  
-    
  327
+
328 328
     def get_changelist_formset(self, request, **kwargs):
329 329
         """
330  
-        Returns a FormSet class for use on the changelist page if list_editable 
  330
+        Returns a FormSet class for use on the changelist page if list_editable
331 331
         is used.
332 332
         """
333 333
         defaults = {
334 334
             "formfield_callback": curry(self.formfield_for_dbfield, request=request),
335 335
         }
336 336
         defaults.update(kwargs)
337  
-        return modelformset_factory(self.model, 
338  
-            self.get_changelist_form(request), extra=0, 
  337
+        return modelformset_factory(self.model,
  338
+            self.get_changelist_form(request), extra=0,
339 339
             fields=self.list_editable, **defaults)
340  
-    
  340
+
341 341
     def get_formsets(self, request, obj=None):
342 342
         for inline in self.inline_instances:
343 343
             yield inline.get_formset(request, obj)
344  
-    
  344
+
345 345
     def log_addition(self, request, object):
346 346
         """
347 347
         Log that an object has been successfully added.
348  
-        
  348
+
349 349
         The default implementation creates an admin LogEntry object.
350 350
         """
351 351
         from django.contrib.admin.models import LogEntry, ADDITION
@@ -356,11 +356,11 @@ def log_addition(self, request, object):
356 356
             object_repr     = force_unicode(object),
357 357
             action_flag     = ADDITION
358 358
         )
359  
-    
  359
+
360 360
     def log_change(self, request, object, message):
361 361
         """
362 362
         Log that an object has been successfully changed.
363  
-        
  363
+
364 364
         The default implementation creates an admin LogEntry object.
365 365
         """
366 366
         from django.contrib.admin.models import LogEntry, CHANGE
@@ -372,13 +372,13 @@ def log_change(self, request, object, message):
372 372
             action_flag     = CHANGE,
373 373
             change_message  = message
374 374
         )
375  
-    
  375
+
376 376
     def log_deletion(self, request, object, object_repr):
377 377
         """
378 378
         Log that an object has been successfully deleted. Note that since the
379 379
         object is deleted, it might no longer be safe to call *any* methods
380 380
         on the object, hence this method getting object_repr.
381  
-        
  381
+
382 382
         The default implementation creates an admin LogEntry object.
383 383
         """
384 384
         from django.contrib.admin.models import LogEntry, DELETION
@@ -389,8 +389,8 @@ def log_deletion(self, request, object, object_repr):
389 389
             object_repr     = object_repr,
390 390
             action_flag     = DELETION
391 391
         )
392  
-    
393  
-    
  392
+
  393
+
394 394
     def construct_change_message(self, request, form, formsets):
395 395
         """
396 396
         Construct a change message from a changed object.
@@ -398,7 +398,7 @@ def construct_change_message(self, request, form, formsets):
398 398
         change_message = []
399 399
         if form.changed_data:
400 400
             change_message.append(_('Changed %s.') % get_text_list(form.changed_data, _('and')))
401  
-        
  401
+
402 402
         if formsets:
403 403
             for formset in formsets:
404 404
                 for added_object in formset.new_objects:
@@ -416,33 +416,33 @@ def construct_change_message(self, request, form, formsets):
416 416
                                              'object': force_unicode(deleted_object)})
417 417
         change_message = ' '.join(change_message)
418 418
         return change_message or _('No fields changed.')
419  
-    
  419
+
420 420
     def message_user(self, request, message):
421 421
         """
422 422
         Send a message to the user. The default implementation
423 423
         posts a message using the auth Message object.
424 424
         """
425 425
         request.user.message_set.create(message=message)
426  
-    
  426
+
427 427
     def save_form(self, request, form, change):
428 428
         """
429 429
         Given a ModelForm return an unsaved instance. ``change`` is True if
430 430
         the object is being changed, and False if it's being added.
431 431
         """
432 432
         return form.save(commit=False)
433  
-    
  433
+
434 434
     def save_model(self, request, obj, form, change):
435 435
         """
436 436
         Given a model instance save it to the database.
437 437
         """
438 438
         obj.save()
439  
-    
  439
+
440 440
     def save_formset(self, request, form, formset, change):
441 441
         """
442 442
         Given an inline formset save it to the database.
443 443
         """
444 444
         formset.save()
445  
-    
  445
+
446 446
     def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
447 447
         opts = self.model._meta
448 448
         app_label = opts.app_label
@@ -468,14 +468,14 @@ def render_change_form(self, request, context, add=False, change=False, form_url
468 468
             "admin/%s/change_form.html" % app_label,
469 469
             "admin/change_form.html"
470 470
         ], context, context_instance=template.RequestContext(request))
471  
-    
  471
+
472 472
     def response_add(self, request, obj, post_url_continue='../%s/'):
473 473
         """
474 474
         Determines the HttpResponse for the add_view stage.
475 475
         """
476 476
         opts = obj._meta
477 477
         pk_value = obj._get_pk_val()
478  
-        
  478
+
479 479
         msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj)}
480 480
         # Here, we distinguish between different save types by checking for
481 481
         # the presence of keys in request.POST.
@@ -484,7 +484,7 @@ def response_add(self, request, obj, post_url_continue='../%s/'):
484 484
             if request.POST.has_key("_popup"):
485 485
                 post_url_continue += "?_popup=1"
486 486
             return HttpResponseRedirect(post_url_continue % pk_value)
487  
-        
  487
+
488 488
         if request.POST.has_key("_popup"):
489 489
             return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' % \
490 490
                 # escape() calls force_unicode.
@@ -494,7 +494,7 @@ def response_add(self, request, obj, post_url_continue='../%s/'):
494 494
             return HttpResponseRedirect(request.path)
495 495
         else:
496 496
             self.message_user(request, msg)
497  
-            
  497
+
498 498
             # Figure out where to redirect. If the user has change permission,
499 499
             # redirect to the change-list page for this object. Otherwise,
500 500
             # redirect to the admin index.
@@ -503,14 +503,14 @@ def response_add(self, request, obj, post_url_continue='../%s/'):
503 503
             else:
504 504
                 post_url = '../../../'
505 505
             return HttpResponseRedirect(post_url)
506  
-    
  506
+
507 507
     def response_change(self, request, obj):
508 508
         """
509 509
         Determines the HttpResponse for the change_view stage.
510 510
         """
511 511
         opts = obj._meta
512 512
         pk_value = obj._get_pk_val()
513  
-        
  513
+
514 514
         msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj)}
515 515
         if request.POST.has_key("_continue"):
516 516
             self.message_user(request, msg + ' ' + _("You may edit it again below."))
@@ -528,15 +528,15 @@ def response_change(self, request, obj):
528 528
         else:
529 529
             self.message_user(request, msg)
530 530
             return HttpResponseRedirect("../")
531  
-    
  531
+
532 532
     def add_view(self, request, form_url='', extra_context=None):
533 533
         "The 'add' admin view for this model."
534 534
         model = self.model
535 535
         opts = model._meta
536  
-        
  536
+
537 537
         if not self.has_add_permission(request):
538 538
             raise PermissionDenied
539  
-        
  539
+
540 540
         ModelForm = self.get_form(request)
541 541
         formsets = []
542 542
         if request.method == 'POST':
@@ -563,7 +563,7 @@ def add_view(self, request, form_url='', extra_context=None):
563 563
                 form.save_m2m()
564 564
                 for formset in formsets:
565 565
                     self.save_formset(request, form, formset, change=False)
566  
-                
  566
+
567 567
                 self.log_addition(request, new_object)
568 568
                 return self.response_add(request, new_object)
569 569
         else:
@@ -586,17 +586,17 @@ def add_view(self, request, form_url='', extra_context=None):
586 586
                     prefix = "%s-%s" % (prefix, prefixes[prefix])
587 587
                 formset = FormSet(instance=self.model(), prefix=prefix)
588 588
                 formsets.append(formset)
589  
-        
  589
+
590 590
         adminForm = helpers.AdminForm(form, list(self.get_fieldsets(request)), self.prepopulated_fields)
591 591
         media = self.media + adminForm.media
592  
-        
  592
+
593 593
         inline_admin_formsets = []
594 594
         for inline, formset in zip(self.inline_instances, formsets):
595 595
             fieldsets = list(inline.get_fieldsets(request))
596 596
             inline_admin_formset = helpers.InlineAdminFormSet(inline, formset, fieldsets)
597 597
             inline_admin_formsets.append(inline_admin_formset)
598 598
             media = media + inline_admin_formset.media
599  
-        
  599
+
600 600
         context = {
601 601
             'title': _('Add %s') % force_unicode(opts.verbose_name),
602 602
             'adminform': adminForm,
@@ -611,12 +611,12 @@ def add_view(self, request, form_url='', extra_context=None):
611 611
         context.update(extra_context or {})
612 612
         return self.render_change_form(request, context, add=True)
613 613
     add_view = transaction.commit_on_success(add_view)
614  
-    
  614
+
615 615
     def change_view(self, request, object_id, extra_context=None):
616 616
         "The 'change' admin view for this model."
617 617
         model = self.model
618 618
         opts = model._meta
619  
-        
  619
+
620 620
         try:
621 621
             obj = model._default_manager.get(pk=unquote(object_id))
622 622
         except model.DoesNotExist:
@@ -624,16 +624,16 @@ def change_view(self, request, object_id, extra_context=None):
624 624
             # permissions yet. We don't want an unauthenticated user to be able
625 625
             # to determine whether a given object exists.
626 626
             obj = None
627  
-        
  627
+
628 628
         if not self.has_change_permission(request, obj):
629 629
             raise PermissionDenied
630  
-        
  630
+
631 631
         if obj is None:
632 632
             raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)})
633  
-        
  633
+
634 634
         if request.method == 'POST' and request.POST.has_key("_saveasnew"):
635 635
             return self.add_view(request, form_url='../../add/')
636  
-        
  636
+
637 637
         ModelForm = self.get_form(request, obj)
638 638
         formsets = []
639 639
         if request.method == 'POST':
@@ -653,17 +653,17 @@ def change_view(self, request, object_id, extra_context=None):
653 653
                 formset = FormSet(request.POST, request.FILES,
654 654
                                   instance=new_object, prefix=prefix)
655 655
                 formsets.append(formset)
656  
-            
  656
+
657 657
             if all_valid(formsets) and form_validated:
658 658
                 self.save_model(request, new_object, form, change=True)
659 659
                 form.save_m2m()
660 660
                 for formset in formsets:
661 661
                     self.save_formset(request, form, formset, change=True)
662  
-                
  662
+
663 663
                 change_message = self.construct_change_message(request, form, formsets)
664 664
                 self.log_change(request, new_object, change_message)
665 665
                 return self.response_change(request, new_object)
666  
-        
  666
+
667 667
         else:
668 668
             form = ModelForm(instance=obj)
669 669
             prefixes = {}
@@ -674,17 +674,17 @@ def change_view(self, request, object_id, extra_context=None):
674 674
                     prefix = "%s-%s" % (prefix, prefixes[prefix])
675 675
                 formset = FormSet(instance=obj, prefix=prefix)
676 676
                 formsets.append(formset)
677  
-        
  677
+
678 678
         adminForm = helpers.AdminForm(form, self.get_fieldsets(request, obj), self.prepopulated_fields)
679 679
         media = self.media + adminForm.media
680  
-        
  680
+
681 681
         inline_admin_formsets = []
682 682
         for inline, formset in zip(self.inline_instances, formsets):
683 683
             fieldsets = list(inline.get_fieldsets(request, obj))
684 684
             inline_admin_formset = helpers.InlineAdminFormSet(inline, formset, fieldsets)
685 685
             inline_admin_formsets.append(inline_admin_formset)
686 686
             media = media + inline_admin_formset.media
687  
-        
  687
+
688 688
         context = {
689 689
             'title': _('Change %s') % force_unicode(opts.verbose_name),
690 690
             'adminform': adminForm,
@@ -700,7 +700,7 @@ def change_view(self, request, object_id, extra_context=None):
700 700
         context.update(extra_context or {})
701 701
         return self.render_change_form(request, context, change=True, obj=obj)
702 702
     change_view = transaction.commit_on_success(change_view)
703  
-    
  703
+
704 704
     def changelist_view(self, request, extra_context=None):
705 705
         "The 'change list' admin view for this model."
706 706
         from django.contrib.admin.views.main import ChangeList, ERROR_FLAG
@@ -720,12 +720,12 @@ def changelist_view(self, request, extra_context=None):
720 720
             if ERROR_FLAG in request.GET.keys():
721 721
                 return render_to_response('admin/invalid_setup.html', {'title': _('Database error')})
722 722
             return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1')
723  
-        
  723
+
724 724
         # If we're allowing changelist editing, we need to construct a formset
725 725
         # for the changelist given all the fields to be edited. Then we'll
726 726
         # use the formset to validate/process POSTed data.
727 727
         formset = cl.formset = None
728  
-        
  728
+
729 729
         # Handle POSTed bulk-edit data.
730 730
         if request.method == "POST" and self.list_editable:
731 731
             FormSet = self.get_changelist_formset(request)
@@ -740,23 +740,26 @@ def changelist_view(self, request, extra_context=None):
740 740
                         change_msg = self.construct_change_message(request, form, None)
741 741
                         self.log_change(request, obj, change_msg)
742 742
                         changecount += 1
743  
-                
  743
+
744 744
                 if changecount:
745  
-                    msg = ngettext("%(count)s %(singular)s was changed successfully.", 
746  
-                                   "%(count)s %(plural)s were changed successfully.", 
  745
+                    if changecount == 1:
  746
+                        name = force_unicode(opts.verbose_name)
  747
+                    else:
  748
+                        name = force_unicode(opts.verbose_name_plural)
  749
+                    msg = ngettext("%(count)s %(name)s was changed successfully.",
  750
+                                   "%(count)s %(name)s were changed successfully.",
747 751
                                    changecount) % {'count': changecount,
748  
-                                                   'singular': force_unicode(opts.verbose_name), 
749  
-                                                   'plural': force_unicode(opts.verbose_name_plural),
  752
+                                                   'name': name,
750 753
                                                    'obj': force_unicode(obj)}
751 754
                     self.message_user(request, msg)
752  
-            
  755
+
753 756
                 return HttpResponseRedirect(request.get_full_path())
754  
-        
  757
+
755 758
         # Handle GET -- construct a formset for display.
756 759
         elif self.list_editable:
757 760
             FormSet = self.get_changelist_formset(request)
758 761
             formset = cl.formset = FormSet(queryset=cl.result_list)
759  
-        
  762
+
760 763
         # Build the list of media to be used by the formset.
761 764
         if formset:
762 765
             media = self.media + formset.media
@@ -778,12 +781,12 @@ def changelist_view(self, request, extra_context=None):
778 781
             'admin/%s/change_list.html' % app_label,
779 782
             'admin/change_list.html'
780 783
         ], context, context_instance=template.RequestContext(request))
781  
-    
  784
+
782 785
     def delete_view(self, request, object_id, extra_context=None):
783 786
         "The 'delete' admin view for this model."
784 787
         opts = self.model._meta
785 788
         app_label = opts.app_label
786  
-        
  789
+
787 790
         try:
788 791
             obj = self.model._default_manager.get(pk=unquote(object_id))
789 792
         except self.model.DoesNotExist:
@@ -791,32 +794,32 @@ def delete_view(self, request, object_id, extra_context=None):
791 794
             # permissions yet. We don't want an unauthenticated user to be able
792 795
             # to determine whether a given object exists.
793 796
             obj = None
794  
-        
  797
+
795 798
         if not self.has_delete_permission(request, obj):
796 799
             raise PermissionDenied
797  
-        
  800
+
798 801
         if obj is None:
799 802
             raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)})
800  
-        
  803
+
801 804
         # Populate deleted_objects, a data structure of all related objects that
802 805
         # will also be deleted.
803 806
         deleted_objects = [mark_safe(u'%s: <a href="../../%s/">%s</a>' % (escape(force_unicode(capfirst(opts.verbose_name))), object_id, escape(obj))), []]
804 807
         perms_needed = set()
805 808
         get_deleted_objects(deleted_objects, perms_needed, request.user, obj, opts, 1, self.admin_site)
806  
-        
  809
+
807 810
         if request.POST: # The user has already confirmed the deletion.
808 811
             if perms_needed:
809 812
                 raise PermissionDenied
810 813
             obj_display = force_unicode(obj)
811 814
             obj.delete()
812  
-            
  815
+
813 816
             self.log_deletion(request, obj, obj_display)
814 817
             self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)})
815  
-            
  818
+
816 819
             if not self.has_change_permission(request, None):
817 820
                 return HttpResponseRedirect("../../../../")
818 821
             return HttpResponseRedirect("../../")
819  
-        
  822
+
820 823
         context = {
821 824
             "title": _("Are you sure?"),
822 825
             "object_name": force_unicode(opts.verbose_name),
@@ -833,7 +836,7 @@ def delete_view(self, request, object_id, extra_context=None):
833 836
             "admin/%s/delete_confirmation.html" % app_label,
834 837
             "admin/delete_confirmation.html"
835 838
         ], context, context_instance=template.RequestContext(request))
836  
-    
  839
+
837 840
     def history_view(self, request, object_id, extra_context=None):
838 841
         "The 'history' admin view for this model."
839 842
         from django.contrib.admin.models import LogEntry
@@ -869,11 +872,11 @@ def __call__(self, request, url):
869 872
         DEPRECATED: this is the old way of URL resolution, replaced by
870 873
         ``get_urls()``. This only called by AdminSite.root(), which is also
871 874
         deprecated.
872  
-        
  875
+
873 876
         Again, remember that the following code only exists for
874 877
         backwards-compatibility. Any new URLs, changes to existing URLs, or
875 878
         whatever need to be done up in get_urls(), above!
876  
-        
  879
+
877 880
         This function still exists for backwards-compatibility; it will be
878 881
         removed in Django 1.3.
879 882
         """
@@ -892,7 +895,7 @@ def __call__(self, request, url):
892 895
 class InlineModelAdmin(BaseModelAdmin):
893 896
     """
894 897
     Options for inline editing of ``model`` instances.
895  
-    
  898
+
896 899
     Provide ``name`` to specify the attribute name of the ``ForeignKey`` from
897 900
     ``model`` to its parent. This is required if ``model`` has more than one
898 901
     ``ForeignKey`` to its parent.
@@ -905,7 +908,7 @@ class InlineModelAdmin(BaseModelAdmin):
905 908
     template = None
906 909
     verbose_name = None
907 910
     verbose_name_plural = None
908  
-    
  911
+
909 912
     def __init__(self, parent_model, admin_site):
910 913
         self.admin_site = admin_site
911 914
         self.parent_model = parent_model
@@ -915,7 +918,7 @@ def __init__(self, parent_model, admin_site):
915 918
             self.verbose_name = self.model._meta.verbose_name
916 919
         if self.verbose_name_plural is None:
917 920
             self.verbose_name_plural = self.model._meta.verbose_name_plural
918  
-    
  921
+
919 922
     def _media(self):
920 923
         from django.conf import settings
921 924
         js = []
@@ -925,7 +928,7 @@ def _media(self):
925 928
             js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
926 929
         return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
927 930
     media = property(_media)
928  
-    
  931
+
929 932
     def get_formset(self, request, obj=None, **kwargs):
930 933
         """Returns a BaseInlineFormSet class for use in admin add/change views."""
931 934
         if self.declared_fieldsets:
@@ -948,13 +951,13 @@ def get_formset(self, request, obj=None, **kwargs):
948 951
         }
949 952
         defaults.update(kwargs)
950 953
         return inlineformset_factory(self.parent_model, self.model, **defaults)
951  
-    
  954
+
952 955
     def get_fieldsets(self, request, obj=None):
953 956
         if self.declared_fieldsets:
954 957
             return self.declared_fieldsets
955 958
         form = self.get_formset(request).form
956 959
         return [(None, {'fields': form.base_fields.keys()})]
957  
-    
  960
+
958 961
 class StackedInline(InlineModelAdmin):
959 962
     template = 'admin/edit_inline/stacked.html'
960 963
 

0 notes on commit 4a67fee

Please sign in to comment.
Something went wrong with that request. Please try again.