Ticket #4846: main.py.diff
File main.py.diff, 11.6 KB (added by , 17 years ago) |
---|
-
main.py
261 261 new_object = manipulator.save(new_data) 262 262 pk_value = new_object._get_pk_val() 263 263 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), ADDITION) 264 msg = _( 'The %(name)s "%(obj)s" was added successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': new_object}264 msg = _(u'The %(name)s "%(obj)s" was added successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(new_object)} 265 265 # Here, we distinguish between different save types by checking for 266 266 # the presence of keys in request.POST. 267 267 if "_continue" in request.POST: 268 request.user.message_set.create(message=msg + ' ' + _( "You may edit it again below."))268 request.user.message_set.create(message=msg + ' ' + _(u"You may edit it again below.")) 269 269 if "_popup" in request.POST: 270 270 post_url_continue += "?_popup=1" 271 271 return HttpResponseRedirect(post_url_continue % pk_value) 272 272 if "_popup" in request.POST: 273 273 if type(pk_value) is str: # Quote if string, so JavaScript doesn't think it's a variable. 274 pk_value = '"%s"' % pk_value.replace('"', '\\"')275 return HttpResponse( '<script type="text/javascript">opener.dismissAddAnotherPopup(window, %s, "%s");</script>' % \274 pk_value = u'"%s"' % pk_value.replace('"', '\\"') 275 return HttpResponse(u'<script type="text/javascript">opener.dismissAddAnotherPopup(window, %s, "%s");</script>' % \ 276 276 (pk_value, force_unicode(new_object).replace('"', '\\"'))) 277 277 elif "_addanother" in request.POST: 278 request.user.message_set.create(message=msg + ' ' + (_( "You may add another %s below.") % force_unicode(opts.verbose_name)))278 request.user.message_set.create(message=msg + ' ' + (_(u"You may add another %s below.") % force_unicode(opts.verbose_name))) 279 279 return HttpResponseRedirect(request.path) 280 280 else: 281 281 request.user.message_set.create(message=msg) … … 293 293 form = oldforms.FormWrapper(manipulator, new_data, errors) 294 294 295 295 c = template.RequestContext(request, { 296 'title': _( 'Add %s') % force_unicode(opts.verbose_name),296 'title': _(u'Add %s') % force_unicode(opts.verbose_name), 297 297 'form': form, 298 298 'is_popup': '_popup' in request.REQUEST, 299 299 'show_delete': show_delete, … … 309 309 model = models.get_model(app_label, model_name) 310 310 object_id = unquote(object_id) 311 311 if model is None: 312 raise Http404( "App %r, model %r, not found" % (app_label, model_name))312 raise Http404(u"App %r, model %r, not found" % (app_label, model_name)) 313 313 opts = model._meta 314 314 315 315 if not request.user.has_perm(app_label + '.' + opts.get_change_permission()): … … 321 321 try: 322 322 manipulator = model.ChangeManipulator(object_id) 323 323 except model.DoesNotExist: 324 raise Http404( '%s object with primary key %r does not exist' % (model_name, escape(object_id)))324 raise Http404(u'%s object with primary key %r does not exist' % (model_name, escape(object_id))) 325 325 326 326 if request.POST: 327 327 new_data = request.POST.copy() … … 339 339 # Construct the change message. 340 340 change_message = [] 341 341 if manipulator.fields_added: 342 change_message.append(_( 'Added %s.') % get_text_list(manipulator.fields_added, _('and')))342 change_message.append(_(u'Added %s.') % get_text_list(manipulator.fields_added, _('and'))) 343 343 if manipulator.fields_changed: 344 change_message.append(_( 'Changed %s.') % get_text_list(manipulator.fields_changed, _('and')))344 change_message.append(_(u'Changed %s.') % get_text_list(manipulator.fields_changed, _('and'))) 345 345 if manipulator.fields_deleted: 346 change_message.append(_( 'Deleted %s.') % get_text_list(manipulator.fields_deleted, _('and')))346 change_message.append(_(u'Deleted %s.') % get_text_list(manipulator.fields_deleted, _('and'))) 347 347 change_message = ' '.join(change_message) 348 348 if not change_message: 349 change_message = _( 'No fields changed.')349 change_message = _(u'No fields changed.') 350 350 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), CHANGE, change_message) 351 351 352 msg = _( 'The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': new_object}352 msg = _(u'The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(new_object)} 353 353 if "_continue" in request.POST: 354 request.user.message_set.create(message=msg + ' ' + _( "You may edit it again below."))354 request.user.message_set.create(message=msg + ' ' + _(u"You may edit it again below.")) 355 355 if '_popup' in request.REQUEST: 356 356 return HttpResponseRedirect(request.path + "?_popup=1") 357 357 else: 358 358 return HttpResponseRedirect(request.path) 359 359 elif "_saveasnew" in request.POST: 360 request.user.message_set.create(message=_( 'The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': new_object})361 return HttpResponseRedirect( "../%s/" % pk_value)360 request.user.message_set.create(message=_(u'The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(new_object)}) 361 return HttpResponseRedirect(u"../%s/" % pk_value) 362 362 elif "_addanother" in request.POST: 363 request.user.message_set.create(message=msg + ' ' + (_( "You may add another %s below.") % force_unicode(opts.verbose_name)))363 request.user.message_set.create(message=msg + ' ' + (_(u"You may add another %s below.") % force_unicode(opts.verbose_name))) 364 364 return HttpResponseRedirect("../add/") 365 365 else: 366 366 request.user.message_set.create(message=msg) … … 389 389 for related in opts.get_followed_related_objects(): 390 390 wrt = related.opts.order_with_respect_to 391 391 if wrt and wrt.rel and wrt.rel.to == opts: 392 func = getattr(manipulator.original_object, 'get_%s_list' %392 func = getattr(manipulator.original_object, u'get_%s_list' % 393 393 related.get_accessor_name()) 394 394 orig_list = func() 395 395 form.order_objects.extend(orig_list) 396 396 397 397 c = template.RequestContext(request, { 398 'title': _( 'Change %s') % force_unicode(opts.verbose_name),398 'title': _(u'Change %s') % force_unicode(opts.verbose_name), 399 399 'form': form, 400 400 'object_id': object_id, 401 401 'original': manipulator.original_object, … … 428 428 pass 429 429 else: 430 430 if related.opts.admin: 431 p = '%s.%s' % (related.opts.app_label, related.opts.get_delete_permission())431 p = u'%s.%s' % (related.opts.app_label, related.opts.get_delete_permission()) 432 432 if not user.has_perm(p): 433 433 perms_needed.add(related.opts.verbose_name) 434 434 # We don't care about populating deleted_objects now. … … 459 459 # If there were related objects, and the user doesn't have 460 460 # permission to delete them, add the missing perm to perms_needed. 461 461 if related.opts.admin and has_related_objs: 462 p = '%s.%s' % (related.opts.app_label, related.opts.get_delete_permission())462 p = u'%s.%s' % (related.opts.app_label, related.opts.get_delete_permission()) 463 463 if not user.has_perm(p): 464 464 perms_needed.add(related.opts.verbose_name) 465 465 for related in opts.get_all_related_many_to_many_objects(): … … 480 480 if related.field.rel.edit_inline or not related.opts.admin: 481 481 # Don't display link to edit, because it either has no 482 482 # admin or is edited inline. 483 nh(deleted_objects, current_depth, [_( 'One or more %(fieldname)s in %(name)s: %(obj)s') % \483 nh(deleted_objects, current_depth, [_(u'One or more %(fieldname)s in %(name)s: %(obj)s') % \ 484 484 {'fieldname': force_unicode(related.field.verbose_name), 'name': force_unicode(related.opts.verbose_name), 'obj': escape(sub_obj)}, []]) 485 485 else: 486 486 # Display a link to the admin page. 487 487 nh(deleted_objects, current_depth, [ 488 (_( 'One or more %(fieldname)s in %(name)s:') % {'fieldname': force_unicode(related.field.verbose_name), 'name': force_unicode(related.opts.verbose_name)}) + \488 (_(u'One or more %(fieldname)s in %(name)s:') % {'fieldname': force_unicode(related.field.verbose_name), 'name': force_unicode(related.opts.verbose_name)}) + \ 489 489 (u' <a href="../../../../%s/%s/%s/">%s</a>' % \ 490 490 (related.opts.app_label, related.opts.module_name, sub_obj._get_pk_val(), escape(sub_obj))), []]) 491 491 # If there were related objects, and the user doesn't have … … 499 499 model = models.get_model(app_label, model_name) 500 500 object_id = unquote(object_id) 501 501 if model is None: 502 raise Http404( "App %r, model %r, not found" % (app_label, model_name))502 raise Http404(u"App %r, model %r, not found" % (app_label, model_name)) 503 503 opts = model._meta 504 504 if not request.user.has_perm(app_label + '.' + opts.get_delete_permission()): 505 505 raise PermissionDenied … … 517 517 obj_display = force_unicode(obj) 518 518 obj.delete() 519 519 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, object_id, obj_display, DELETION) 520 request.user.message_set.create(message=_( 'The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': obj_display})520 request.user.message_set.create(message=_(u'The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)}) 521 521 return HttpResponseRedirect("../../") 522 522 extra_context = { 523 523 "title": _("Are you sure?"), … … 536 536 model = models.get_model(app_label, model_name) 537 537 object_id = unquote(object_id) 538 538 if model is None: 539 raise Http404( "App %r, model %r, not found" % (app_label, model_name))539 raise Http404(u"App %r, model %r, not found" % (app_label, model_name)) 540 540 action_list = LogEntry.objects.filter(object_id=object_id, 541 541 content_type__id__exact=ContentType.objects.get_for_model(model).id).select_related().order_by('action_time') 542 542 # If no history was found, see whether this object even exists. 543 543 obj = get_object_or_404(model, pk=object_id) 544 544 extra_context = { 545 'title': _( 'Change history: %s') % obj,545 'title': _(u'Change history: %s') % obj, 546 546 'action_list': action_list, 547 547 'module_name': force_unicode(capfirst(model._meta.verbose_name_plural)), 548 548 'object': obj,