From 1d32bdd3c9586ff10d0799264105850fa7e3f512 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 11 Aug 2011 14:07:39 +0000 Subject: [PATCH] Fixed #15252 -- Added static template tag and CachedStaticFilesStorage to staticfiles contrib app. Many thanks to Florian Apolloner and Jacob Kaplan-Moss for reviewing and eagle eyeing. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16594 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/helpers.py | 3 +- django/contrib/admin/options.py | 13 +- .../admin/auth/user/change_password.html | 2 +- .../contrib/admin/templates/admin/base.html | 2 +- .../admin/templates/admin/change_form.html | 2 +- .../admin/templates/admin/change_list.html | 2 +- .../templates/admin/change_list_results.html | 2 +- .../templates/admin/edit_inline/stacked.html | 2 +- .../templates/admin/edit_inline/tabular.html | 2 +- .../contrib/admin/templates/admin/index.html | 2 +- .../contrib/admin/templates/admin/login.html | 2 +- .../admin/templates/admin/search_form.html | 2 +- .../contrib/admin/templatetags/admin_list.py | 2 +- .../admin/templatetags/admin_static.py | 11 + django/contrib/admin/widgets.py | 34 +-- django/contrib/staticfiles/finders.py | 2 +- .../management/commands/collectstatic.py | 84 +++++--- django/contrib/staticfiles/storage.py | 171 +++++++++++++++- .../staticfiles/templatetags/__init__.py | 0 .../staticfiles/templatetags/staticfiles.py | 13 ++ django/contrib/staticfiles/utils.py | 14 +- docs/howto/static-files.txt | 44 ++-- docs/ref/contrib/staticfiles.txt | 143 ++++++++++++- docs/ref/templates/builtins.txt | 17 +- docs/releases/1.4.txt | 23 +++ .../project/documents/cached/absolute.css | 1 + .../project/documents/cached/denorm.css | 1 + .../project/documents/cached/other.css | 0 .../project/documents/cached/relative.css | 2 + .../project/documents/cached/styles.css | 1 + .../project/documents/cached/url.css | 1 + .../project/site_media/static/testfile.txt | 1 + .../staticfiles_tests/tests.py | 193 +++++++++++++----- 33 files changed, 646 insertions(+), 148 deletions(-) create mode 100644 django/contrib/admin/templatetags/admin_static.py create mode 100644 django/contrib/staticfiles/templatetags/__init__.py create mode 100644 django/contrib/staticfiles/templatetags/staticfiles.py create mode 100644 tests/regressiontests/staticfiles_tests/project/documents/cached/absolute.css create mode 100644 tests/regressiontests/staticfiles_tests/project/documents/cached/denorm.css create mode 100644 tests/regressiontests/staticfiles_tests/project/documents/cached/other.css create mode 100644 tests/regressiontests/staticfiles_tests/project/documents/cached/relative.css create mode 100644 tests/regressiontests/staticfiles_tests/project/documents/cached/styles.css create mode 100644 tests/regressiontests/staticfiles_tests/project/documents/cached/url.css create mode 100644 tests/regressiontests/staticfiles_tests/project/site_media/static/testfile.txt diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index d15716b909..04a3492e1c 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -1,6 +1,7 @@ from django import forms from django.contrib.admin.util import (flatten_fieldsets, lookup_field, display_for_field, label_for_field, help_text_for_field) +from django.contrib.admin.templatetags.admin_static import static from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.db.models.fields.related import ManyToManyRel @@ -75,7 +76,7 @@ class Fieldset(object): def _media(self): if 'collapse' in self.classes: js = ['jquery.min.js', 'jquery.init.js', 'collapse.min.js'] - return forms.Media(js=['admin/js/%s' % url for url in js]) + return forms.Media(js=[static('admin/js/%s' % url) for url in js]) return forms.Media() media = property(_media) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 35c3cde0fc..81e8ae5614 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -6,6 +6,7 @@ from django.forms.models import (modelform_factory, modelformset_factory, from django.contrib.contenttypes.models import ContentType from django.contrib.admin import widgets, helpers from django.contrib.admin.util import unquote, flatten_fieldsets, get_deleted_objects, model_format_dict +from django.contrib.admin.templatetags.admin_static import static from django.contrib import messages from django.views.decorators.csrf import csrf_protect from django.core.exceptions import PermissionDenied, ValidationError @@ -350,7 +351,8 @@ class ModelAdmin(BaseModelAdmin): return self.get_urls() urls = property(urls) - def _media(self): + @property + def media(self): js = [ 'core.js', 'admin/RelatedObjectLookups.js', @@ -363,8 +365,7 @@ class ModelAdmin(BaseModelAdmin): js.extend(['urlify.js', 'prepopulate.min.js']) if self.opts.get_ordered_objects(): js.extend(['getElementsBySelector.js', 'dom-drag.js' , 'admin/ordering.js']) - return forms.Media(js=['admin/js/%s' % url for url in js]) - media = property(_media) + return forms.Media(js=[static('admin/js/%s' % url) for url in js]) def has_add_permission(self, request): """ @@ -1322,14 +1323,14 @@ class InlineModelAdmin(BaseModelAdmin): if self.verbose_name_plural is None: self.verbose_name_plural = self.model._meta.verbose_name_plural - def _media(self): + @property + def media(self): js = ['jquery.min.js', 'jquery.init.js', 'inlines.min.js'] if self.prepopulated_fields: js.extend(['urlify.js', 'prepopulate.min.js']) if self.filter_vertical or self.filter_horizontal: js.extend(['SelectBox.js', 'SelectFilter2.js']) - return forms.Media(js=['admin/js/%s' % url for url in js]) - media = property(_media) + return forms.Media(js=[static('admin/js/%s' % url) for url in js]) def get_formset(self, request, obj=None, **kwargs): """Returns a BaseInlineFormSet class for use in admin add/change views.""" diff --git a/django/contrib/admin/templates/admin/auth/user/change_password.html b/django/contrib/admin/templates/admin/auth/user/change_password.html index c280f50d60..b18b0aabf3 100644 --- a/django/contrib/admin/templates/admin/auth/user/change_password.html +++ b/django/contrib/admin/templates/admin/auth/user/change_password.html @@ -1,5 +1,5 @@ {% extends "admin/base_site.html" %} -{% load i18n static admin_modify %} +{% load i18n admin_static admin_modify %} {% load url from future %} {% block extrahead %}{{ block.super }} {% url 'admin:jsi18n' as jsi18nurl %} diff --git a/django/contrib/admin/templates/admin/base.html b/django/contrib/admin/templates/admin/base.html index 928244053f..4b3c42934f 100644 --- a/django/contrib/admin/templates/admin/base.html +++ b/django/contrib/admin/templates/admin/base.html @@ -1,4 +1,4 @@ -{% load static %}{% load url from future %} +{% load admin_static %}{% load url from future %} {% block title %}{% endblock %} diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html index c5e428d174..56661e9a8e 100644 --- a/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -1,5 +1,5 @@ {% extends "admin/base_site.html" %} -{% load i18n static admin_modify %} +{% load i18n admin_static admin_modify %} {% load url from future %} {% block extrahead %}{{ block.super }} diff --git a/django/contrib/admin/templates/admin/change_list.html b/django/contrib/admin/templates/admin/change_list.html index 29af47ff79..24c6d8cced 100644 --- a/django/contrib/admin/templates/admin/change_list.html +++ b/django/contrib/admin/templates/admin/change_list.html @@ -1,5 +1,5 @@ {% extends "admin/base_site.html" %} -{% load i18n static admin_list %} +{% load i18n admin_static admin_list %} {% load url from future %} {% block extrastyle %} {{ block.super }} diff --git a/django/contrib/admin/templates/admin/change_list_results.html b/django/contrib/admin/templates/admin/change_list_results.html index 233d4e12d0..b1db6470c9 100644 --- a/django/contrib/admin/templates/admin/change_list_results.html +++ b/django/contrib/admin/templates/admin/change_list_results.html @@ -1,4 +1,4 @@ -{% load i18n static %} +{% load i18n admin_static %} {% if result_hidden_fields %}
{# DIV for HTML validation #} {% for item in result_hidden_fields %}{{ item }}{% endfor %} diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html index 7e69450866..476e2613c5 100644 --- a/django/contrib/admin/templates/admin/edit_inline/stacked.html +++ b/django/contrib/admin/templates/admin/edit_inline/stacked.html @@ -1,4 +1,4 @@ -{% load i18n static %} +{% load i18n admin_static %}

{{ inline_admin_formset.opts.verbose_name_plural|title }}

{{ inline_admin_formset.formset.management_form }} diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html index 829422711d..29db95a171 100644 --- a/django/contrib/admin/templates/admin/edit_inline/tabular.html +++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html @@ -1,4 +1,4 @@ -{% load i18n static admin_modify %} +{% load i18n admin_static admin_modify %}