Ticket #13764: admin-cutom-jsi18n.patch

File admin-cutom-jsi18n.patch, 6.7 KB (added by Sebastian Noack, 14 years ago)
  • django/django/contrib/admin/options.py

    diff --git a/django/django/contrib/admin/options.py b/django/django/contrib/admin/options.py
    index ad5c2f1..7f9183e 100644
    a b from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_ob  
    88from django.core.exceptions import PermissionDenied
    99from django.db import models, transaction
    1010from django.db.models.fields import BLANK_CHOICE_DASH
     11from django.conf import settings
    1112from django.http import Http404, HttpResponse, HttpResponseRedirect
    1213from django.shortcuts import get_object_or_404, render_to_response
    1314from django.utils.datastructures import SortedDict
    class ModelAdmin(BaseModelAdmin):  
    220221    def get_urls(self):
    221222        from django.conf.urls.defaults import patterns, url
    222223
    223         def wrap(view):
     224        def wrap(view, cacheable=False):
    224225            def wrapper(*args, **kwargs):
    225                 return self.admin_site.admin_view(view)(*args, **kwargs)
     226                return self.admin_site.admin_view(view, cacheable)(*args, **kwargs)
    226227            return update_wrapper(wrapper, view)
    227228
    228229        info = self.model._meta.app_label, self.model._meta.module_name
    class ModelAdmin(BaseModelAdmin):  
    240241            url(r'^(.+)/delete/$',
    241242                wrap(self.delete_view),
    242243                name='%s_%s_delete' % info),
     244            url(r'^jsi18n/$',
     245                wrap(self.i18n_javascript, cacheable=True),
     246                name='%s_%s_jsi18n' % info),
    243247            url(r'^(.+)/$',
    244248                wrap(self.change_view),
    245249                name='%s_%s_change' % info),
    class ModelAdmin(BaseModelAdmin):  
    251255    urls = property(urls)
    252256
    253257    def _media(self):
    254         from django.conf import settings
    255 
    256258        js = ['js/core.js', 'js/admin/RelatedObjectLookups.js']
    257259        if self.actions is not None:
    258260            js.extend(['js/getElementsBySelector.js', 'js/actions.js'])
    class ModelAdmin(BaseModelAdmin):  
    10911093            "admin/object_history.html"
    10921094        ], context, context_instance=context_instance)
    10931095
     1096    def i18n_javascript(self, request):
     1097        """
     1098        Displays the i18n JavaScript that the Django admin requires.
     1099
     1100        This takes into account the USE_I18N setting. If it's set to False, the
     1101        generated JavaScript will be leaner and faster.
     1102        """
     1103        if settings.USE_I18N:
     1104            from django.views.i18n import javascript_catalog
     1105        else:
     1106            from django.views.i18n import null_javascript_catalog as javascript_catalog
     1107
     1108        for package in settings.INSTALLED_APPS:
     1109            if self.opts.app_label == package.split('.')[-1]:
     1110                break
     1111
     1112        return javascript_catalog(request, packages=('django.conf', package))
     1113
    10941114    #
    10951115    # DEPRECATED methods.
    10961116    #
    class InlineModelAdmin(BaseModelAdmin):  
    11471167            self.verbose_name_plural = self.model._meta.verbose_name_plural
    11481168
    11491169    def _media(self):
    1150         from django.conf import settings
    11511170        js = []
    11521171        if self.prepopulated_fields:
    11531172            js.append('js/urlify.js')
  • django/django/contrib/admin/sites.py

    diff --git a/django/django/contrib/admin/sites.py b/django/django/contrib/admin/sites.py
    index 031cf36..3e612ae 100644
    a b class AdminSite(object):  
    207207            url(r'^password_change/done/$',
    208208                wrap(self.password_change_done, cacheable=True),
    209209                name='password_change_done'),
    210             url(r'^jsi18n/$',
    211                 wrap(self.i18n_javascript, cacheable=True),
    212                 name='jsi18n'),
    213210            url(r'^r/(?P<content_type>\d+)/(?P<object_id>.+)/$',
    214211                'django.views.defaults.shortcut'),
    215212            url(r'^(?P<app_label>\w+)/$',
    class AdminSite(object):  
    270267        from django.contrib.auth.views import password_change_done
    271268        return password_change_done(request)
    272269
    273     def i18n_javascript(self, request):
    274         """
    275         Displays the i18n JavaScript that the Django admin requires.
    276 
    277         This takes into account the USE_I18N setting. If it's set to False, the
    278         generated JavaScript will be leaner and faster.
    279         """
    280         if settings.USE_I18N:
    281             from django.views.i18n import javascript_catalog
    282         else:
    283             from django.views.i18n import null_javascript_catalog as javascript_catalog
    284         return javascript_catalog(request, packages='django.conf')
    285 
    286270    def logout(self, request):
    287271        """
    288272        Logs out the user for the given HttpRequest.
  • django/django/contrib/admin/templates/admin/auth/user/change_password.html

    diff --git a/django/django/contrib/admin/templates/admin/auth/user/change_password.html b/django/django/contrib/admin/templates/admin/auth/user/change_password.html
    index d28dd0f..3ee4e1b 100644
    a b  
    11{% extends "admin/base_site.html" %}
    22{% load i18n admin_modify adminmedia %}
    33{% block extrahead %}{{ block.super }}
    4 <script type="text/javascript" src="../../../../jsi18n/"></script>
     4<script type="text/javascript" src="../../jsi18n/"></script>
    55{% endblock %}
    66{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />{% endblock %}
    77{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
  • django/django/contrib/admin/templates/admin/change_form.html

    diff --git a/django/django/contrib/admin/templates/admin/change_form.html b/django/django/contrib/admin/templates/admin/change_form.html
    index a650261..e4a0529 100644
    a b  
    22{% load i18n admin_modify adminmedia %}
    33
    44{% block extrahead %}{{ block.super }}
    5 <script type="text/javascript" src="../../../jsi18n/"></script>
     5<script type="text/javascript" src="../jsi18n/"></script>
    66{{ media }}
    77{% endblock %}
    88
  • django/django/contrib/admin/templates/admin/change_list.html

    diff --git a/django/django/contrib/admin/templates/admin/change_list.html b/django/django/contrib/admin/templates/admin/change_list.html
    index 7d110e4..9840382 100644
    a b  
    66  <link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" />
    77  {% if cl.formset %}
    88    <link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />
    9     <script type="text/javascript" src="../../jsi18n/"></script>
     9    <script type="text/javascript" src="./jsi18n/"></script>
    1010  {% endif %}
    1111  {{ media }}
    1212  {% if not actions_on_top and not actions_on_bottom %}
Back to Top