Ticket #4846: main.py.2.diff

File main.py.2.diff, 12.0 KB (added by daybreaker12@…, 17 years ago)

patch revision

  • main.py

     
    261261            new_object = manipulator.save(new_data)
    262262            pk_value = new_object._get_pk_val()
    263263            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)}
    265265            # Here, we distinguish between different save types by checking for
    266266            # the presence of keys in request.POST.
    267267            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."))
    269269                if "_popup" in request.POST:
    270270                    post_url_continue += "?_popup=1"
    271271                return HttpResponseRedirect(post_url_continue % pk_value)
    272272            if "_popup" in request.POST:
    273273                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>' % \
    276276                    (pk_value, force_unicode(new_object).replace('"', '\\"')))
    277277            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)))
    279279                return HttpResponseRedirect(request.path)
    280280            else:
    281281                request.user.message_set.create(message=msg)
     
    293293    form = oldforms.FormWrapper(manipulator, new_data, errors)
    294294
    295295    c = template.RequestContext(request, {
    296         'title': _('Add %s') % force_unicode(opts.verbose_name),
     296        'title': _(u'Add %s') % force_unicode(opts.verbose_name),
    297297        'form': form,
    298298        'is_popup': '_popup' in request.REQUEST,
    299299        'show_delete': show_delete,
     
    309309    model = models.get_model(app_label, model_name)
    310310    object_id = unquote(object_id)
    311311    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))
    313313    opts = model._meta
    314314
    315315    if not request.user.has_perm(app_label + '.' + opts.get_change_permission()):
     
    321321    try:
    322322        manipulator = model.ChangeManipulator(object_id)
    323323    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)))
    325325
    326326    if request.POST:
    327327        new_data = request.POST.copy()
     
    339339            # Construct the change message.
    340340            change_message = []
    341341            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')))
    343343            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')))
    345345            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')))
    347347            change_message = ' '.join(change_message)
    348348            if not change_message:
    349                 change_message = _('No fields changed.')
     349                change_message = _(u'No fields changed.')
    350350            LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), CHANGE, change_message)
    351351
    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)}
    353353            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."))
    355355                if '_popup' in request.REQUEST:
    356356                    return HttpResponseRedirect(request.path + "?_popup=1")
    357357                else:
    358358                    return HttpResponseRedirect(request.path)
    359359            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)
    362362            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)))
    364364                return HttpResponseRedirect("../add/")
    365365            else:
    366366                request.user.message_set.create(message=msg)
     
    389389    for related in opts.get_followed_related_objects():
    390390        wrt = related.opts.order_with_respect_to
    391391        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' %
    393393                    related.get_accessor_name())
    394394            orig_list = func()
    395395            form.order_objects.extend(orig_list)
    396396
    397397    c = template.RequestContext(request, {
    398         'title': _('Change %s') % force_unicode(opts.verbose_name),
     398        'title': _(u'Change %s') % force_unicode(opts.verbose_name),
    399399        'form': form,
    400400        'object_id': object_id,
    401401        'original': manipulator.original_object,
     
    428428                pass
    429429            else:
    430430                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())
    432432                    if not user.has_perm(p):
    433433                        perms_needed.add(related.opts.verbose_name)
    434434                        # We don't care about populating deleted_objects now.
     
    459459            # If there were related objects, and the user doesn't have
    460460            # permission to delete them, add the missing perm to perms_needed.
    461461            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())
    463463                if not user.has_perm(p):
    464464                    perms_needed.add(related.opts.verbose_name)
    465465    for related in opts.get_all_related_many_to_many_objects():
     
    480480                if related.field.rel.edit_inline or not related.opts.admin:
    481481                    # Don't display link to edit, because it either has no
    482482                    # admin or is edited inline.
    483                     nh(deleted_objects, current_depth, [_('One or more %(fieldname)s in %(name)s: %(obj)s') % \
    484                         {'fieldname': force_unicode(related.field.verbose_name), 'name': force_unicode(related.opts.verbose_name), 'obj': escape(sub_obj)}, []])
     483                    nh(deleted_objects, current_depth, [_(u'One or more %(fieldname)s in %(name)s: %(obj)s') % \
     484                        {'fieldname': force_unicode(related.field.verbose_name), 'name': force_unicode(related.opts.verbose_name), 'obj': force_unicode(escape(sub_obj))}, []])
    485485                else:
    486486                    # Display a link to the admin page.
    487487                    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)}) + \
    489489                        (u' <a href="../../../../%s/%s/%s/">%s</a>' % \
    490                             (related.opts.app_label, related.opts.module_name, sub_obj._get_pk_val(), escape(sub_obj))), []])
     490                            (related.opts.app_label, related.opts.module_name, sub_obj._get_pk_val(), force_unicode(escape(sub_obj)))), []])
    491491        # If there were related objects, and the user doesn't have
    492492        # permission to change them, add the missing perm to perms_needed.
    493493        if related.opts.admin and has_related_objs:
     
    499499    model = models.get_model(app_label, model_name)
    500500    object_id = unquote(object_id)
    501501    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))
    503503    opts = model._meta
    504504    if not request.user.has_perm(app_label + '.' + opts.get_delete_permission()):
    505505        raise PermissionDenied
     
    517517        obj_display = force_unicode(obj)
    518518        obj.delete()
    519519        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': obj_display})
    521521        return HttpResponseRedirect("../../")
    522522    extra_context = {
    523523        "title": _("Are you sure?"),
     
    536536    model = models.get_model(app_label, model_name)
    537537    object_id = unquote(object_id)
    538538    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))
    540540    action_list = LogEntry.objects.filter(object_id=object_id,
    541541        content_type__id__exact=ContentType.objects.get_for_model(model).id).select_related().order_by('action_time')
    542542    # If no history was found, see whether this object even exists.
    543543    obj = get_object_or_404(model, pk=object_id)
    544544    extra_context = {
    545         'title': _('Change history: %s') % obj,
     545        'title': _(u'Change history: %s') % obj,
    546546        'action_list': action_list,
    547547        'module_name': force_unicode(capfirst(model._meta.verbose_name_plural)),
    548548        'object': obj,
Back to Top