Ticket #17458: 17458-1.diff

File 17458-1.diff, 6.1 KB (added by Claude Paroz, 13 years ago)

Set Http404 strings as translatable

  • django/contrib/contenttypes/views.py

    diff --git a/django/contrib/contenttypes/views.py b/django/contrib/contenttypes/views.py
    index ac0feff..c9bafd8 100644
    a b from django import http  
    22from django.contrib.contenttypes.models import ContentType
    33from django.contrib.sites.models import Site, get_current_site
    44from django.core.exceptions import ObjectDoesNotExist
     5from django.utils.translation import ugettext as _
    56
    67def shortcut(request, content_type_id, object_id):
    78    "Redirect to an object's page based on a content-type ID and an object ID."
    def shortcut(request, content_type_id, object_id):  
    910    try:
    1011        content_type = ContentType.objects.get(pk=content_type_id)
    1112        if not content_type.model_class():
    12             raise http.Http404("Content type %s object has no associated model" % content_type_id)
     13            raise http.Http404(_(u"Content type %s object has no associated model") % content_type_id)
    1314        obj = content_type.get_object_for_this_type(pk=object_id)
    1415    except (ObjectDoesNotExist, ValueError):
    15         raise http.Http404("Content type %s object %s doesn't exist" % (content_type_id, object_id))
     16        raise http.Http404(_(u"Content type %(type)s object %(id)s doesn't exist") % {
     17            'type': content_type_id, 'id': object_id})
    1618    try:
    1719        absurl = obj.get_absolute_url()
    1820    except AttributeError:
    19         raise http.Http404("%s objects don't have get_absolute_url() methods" % content_type.name)
     21        raise http.Http404(_(u"%s objects don't have get_absolute_url() methods") % content_type.name)
    2022
    2123    # Try to figure out the object's domain, so we can do a cross-site redirect
    2224    # if necessary.
  • django/contrib/gis/sitemaps/views.py

    diff --git a/django/contrib/gis/sitemaps/views.py b/django/contrib/gis/sitemaps/views.py
    index eb2454c..3a9acad 100644
    a b from django.contrib.gis.db.models.fields import GeometryField  
    77from django.db import connections, DEFAULT_DB_ALIAS
    88from django.db.models import get_model
    99from django.utils.encoding import smart_str
     10from django.utils.translation import ugettext as _
    1011
    1112from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz
    1213
    def sitemap(request, sitemaps, section=None):  
    4041    maps, urls = [], []
    4142    if section is not None:
    4243        if section not in sitemaps:
    43             raise Http404("No sitemap available for section: %r" % section)
     44            raise Http404(_(u"No sitemap available for section: %r") % section)
    4445        maps.append(sitemaps[section])
    4546    else:
    4647        maps = sitemaps.values()
    def sitemap(request, sitemaps, section=None):  
    5455            else:
    5556                urls.extend(site.get_urls(page=page, site=current_site))
    5657        except EmptyPage:
    57             raise Http404("Page %s empty" % page)
     58            raise Http404(_(u"Page %s empty") % page)
    5859        except PageNotAnInteger:
    59             raise Http404("No page '%s'" % page)
     60            raise Http404(_(u"No page '%s'") % page)
    6061    xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls}))
    6162    return HttpResponse(xml, content_type='application/xml')
    6263
  • django/contrib/gis/views.py

    diff --git a/django/contrib/gis/views.py b/django/contrib/gis/views.py
    index 0e17210..fc51a0b 100644
    a b  
    11from django.http import Http404
     2from django.utils.translation import ugettext as _
    23
    34def feed(request, url, feed_dict=None):
    45    """Provided for backwards compatibility."""
    56    if not feed_dict:
    6         raise Http404("No feeds are registered.")
     7        raise Http404(_(u"No feeds are registered."))
    78
    89    try:
    910        slug, param = url.split('/', 1)
    def feed(request, url, feed_dict=None):  
    1314    try:
    1415        f = feed_dict[slug]
    1516    except KeyError:
    16         raise Http404("Slug %r isn't registered." % slug)
     17        raise Http404(_(u"Slug %r isn't registered.") % slug)
    1718
    1819    instance = f()
    1920    instance.feed_url = getattr(f, 'feed_url', None) or request.path
  • django/views/static.py

    diff --git a/django/views/static.py b/django/views/static.py
    index 387b7da..f227980 100644
    a b import urllib  
    1414from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified
    1515from django.template import loader, Template, Context, TemplateDoesNotExist
    1616from django.utils.http import http_date, parse_http_date
     17from django.utils.translation import ugettext as _, ugettext_noop
    1718
    1819def serve(request, path, document_root=None, show_indexes=False):
    1920    """
    def serve(request, path, document_root=None, show_indexes=False):  
    4849    if os.path.isdir(fullpath):
    4950        if show_indexes:
    5051            return directory_index(newpath, fullpath)
    51         raise Http404("Directory indexes are not allowed here.")
     52        raise Http404(_(u"Directory indexes are not allowed here."))
    5253    if not os.path.exists(fullpath):
    53         raise Http404('"%s" does not exist' % fullpath)
     54        raise Http404(_(u'"%s" does not exist') % fullpath)
    5455    # Respect the If-Modified-Since header.
    5556    statobj = os.stat(fullpath)
    5657    mimetype, encoding = mimetypes.guess_type(fullpath)
    def serve(request, path, document_root=None, show_indexes=False):  
    6970
    7071
    7172DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
     73{% load i18n %}
    7274<!DOCTYPE html>
    7375<html lang="en">
    7476  <head>
    7577    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    7678    <meta http-equiv="Content-Language" content="en-us" />
    7779    <meta name="robots" content="NONE,NOARCHIVE" />
    78     <title>Index of {{ directory }}</title>
     80    <title>{% blocktrans %}Index of {{ directory }}{% endblocktrans %}</title>
    7981  </head>
    8082  <body>
    81     <h1>Index of {{ directory }}</h1>
     83    <h1>{% blocktrans %}Index of {{ directory }}{% endblocktrans %}</h1>
    8284    <ul>
    8385      {% ifnotequal directory "/" %}
    8486      <li><a href="../">../</a></li>
    DEFAULT_DIRECTORY_INDEX_TEMPLATE = """  
    9092  </body>
    9193</html>
    9294"""
     95template_translatable = ugettext_noop(u"Index of %(directory)s")
    9396
    9497def directory_index(path, fullpath):
    9598    try:
Back to Top