Permalink
Browse files

Fixed #15252 -- Added static template tag and CachedStaticFilesStorag…

…e 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
  • Loading branch information...
1 parent e9a909e commit 1d32bdd3c9586ff10d0799264105850fa7e3f512 @jezdez jezdez committed Aug 11, 2011
Showing with 643 additions and 145 deletions.
  1. +2 −1 django/contrib/admin/helpers.py
  2. +7 −6 django/contrib/admin/options.py
  3. +1 −1 django/contrib/admin/templates/admin/auth/user/change_password.html
  4. +1 −1 django/contrib/admin/templates/admin/base.html
  5. +1 −1 django/contrib/admin/templates/admin/change_form.html
  6. +1 −1 django/contrib/admin/templates/admin/change_list.html
  7. +1 −1 django/contrib/admin/templates/admin/change_list_results.html
  8. +1 −1 django/contrib/admin/templates/admin/edit_inline/stacked.html
  9. +1 −1 django/contrib/admin/templates/admin/edit_inline/tabular.html
  10. +1 −1 django/contrib/admin/templates/admin/index.html
  11. +1 −1 django/contrib/admin/templates/admin/login.html
  12. +1 −1 django/contrib/admin/templates/admin/search_form.html
  13. +1 −1 django/contrib/admin/templatetags/admin_list.py
  14. +11 −0 django/contrib/admin/templatetags/admin_static.py
  15. +22 −12 django/contrib/admin/widgets.py
  16. +1 −1 django/contrib/staticfiles/finders.py
  17. +56 −28 django/contrib/staticfiles/management/commands/collectstatic.py
  18. +161 −4 django/contrib/staticfiles/storage.py
  19. 0 django/contrib/staticfiles/templatetags/__init__.py
  20. +13 −0 django/contrib/staticfiles/templatetags/staticfiles.py
  21. +9 −5 django/contrib/staticfiles/utils.py
  22. +20 −24 docs/howto/static-files.txt
  23. +140 −3 docs/ref/contrib/staticfiles.txt
  24. +14 −3 docs/ref/templates/builtins.txt
  25. +23 −0 docs/releases/1.4.txt
  26. +1 −0 tests/regressiontests/staticfiles_tests/project/documents/cached/absolute.css
  27. +1 −0 tests/regressiontests/staticfiles_tests/project/documents/cached/denorm.css
  28. 0 tests/regressiontests/staticfiles_tests/project/documents/cached/other.css
  29. +2 −0 tests/regressiontests/staticfiles_tests/project/documents/cached/relative.css
  30. +1 −0 tests/regressiontests/staticfiles_tests/project/documents/cached/styles.css
  31. +1 −0 tests/regressiontests/staticfiles_tests/project/documents/cached/url.css
  32. +1 −0 tests/regressiontests/staticfiles_tests/project/site_media/static/testfile.txt
  33. +146 −47 tests/regressiontests/staticfiles_tests/tests.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 @@ def __init__(self, form, name=None, readonly_fields=(), fields=(), classes=(),
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)
@@ -6,6 +6,7 @@
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 @@ def urls(self):
return self.get_urls()
urls = property(urls)
- def _media(self):
+ @property
+ def media(self):
js = [
'core.js',
'admin/RelatedObjectLookups.js',
@@ -363,8 +365,7 @@ def _media(self):
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 @@ def __init__(self, parent_model, admin_site):
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."""
@@ -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 %}
@@ -1,4 +1,4 @@
-{% load static %}{% load url from future %}<!DOCTYPE html>
+{% load admin_static %}{% load url from future %}<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
<title>{% block title %}{% endblock %}</title>
@@ -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 }}
@@ -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 }}
@@ -1,4 +1,4 @@
-{% load i18n static %}
+{% load i18n admin_static %}
{% if result_hidden_fields %}
<div class="hiddenfields">{# DIV for HTML validation #}
{% for item in result_hidden_fields %}{{ item }}{% endfor %}
@@ -1,4 +1,4 @@
-{% load i18n static %}
+{% load i18n admin_static %}
<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
<h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2>
{{ inline_admin_formset.formset.management_form }}
@@ -1,4 +1,4 @@
-{% load i18n static admin_modify %}
+{% load i18n admin_static admin_modify %}
<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
{{ inline_admin_formset.formset.management_form }}
@@ -1,5 +1,5 @@
{% extends "admin/base_site.html" %}
-{% load i18n static %}
+{% load i18n admin_static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}" />{% endblock %}
@@ -1,5 +1,5 @@
{% extends "admin/base_site.html" %}
-{% load i18n static %}
+{% load i18n admin_static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/login.css" %}" />{% endblock %}
@@ -1,4 +1,4 @@
-{% load i18n static %}
+{% load i18n admin_static %}
{% if cl.search_fields %}
<div id="toolbar"><form id="changelist-search" action="" method="get">
<div><!-- DIV needed for valid HTML -->
@@ -3,9 +3,9 @@
from django.contrib.admin.util import lookup_field, display_for_field, label_for_field
from django.contrib.admin.views.main import (ALL_VAR, EMPTY_CHANGELIST_VALUE,
ORDER_VAR, PAGE_VAR, SEARCH_VAR)
+from django.contrib.admin.templatetags.admin_static import static
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
-from django.templatetags.static import static
from django.utils import formats
from django.utils.html import escape, conditional_escape
from django.utils.safestring import mark_safe
@@ -0,0 +1,11 @@
+from django.conf import settings
+from django.template import Library
+
+register = Library()
+
+if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
+ from django.contrib.staticfiles.templatetags.staticfiles import static
+else:
+ from django.templatetags.static import static
+
+static = register.simple_tag(static)
@@ -4,36 +4,40 @@
import copy
from django import forms
+from django.contrib.admin.templatetags.admin_static import static
from django.core.urlresolvers import reverse
from django.forms.widgets import RadioFieldRenderer
from django.forms.util import flatatt
-from django.templatetags.static import static
from django.utils.html import escape
from django.utils.text import Truncator
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
+
class FilteredSelectMultiple(forms.SelectMultiple):
"""
A SelectMultiple with a JavaScript filter interface.
Note that the resulting JavaScript assumes that the jsi18n
catalog has been loaded in the page
"""
- class Media:
- js = ["admin/js/%s" % path
- for path in ["core.js", "SelectBox.js", "SelectFilter2.js"]]
+ @property
+ def media(self):
+ js = ["core.js", "SelectBox.js", "SelectFilter2.js"]
+ return forms.Media(js=[static("admin/js/%s" % path) for path in js])
def __init__(self, verbose_name, is_stacked, attrs=None, choices=()):
self.verbose_name = verbose_name
self.is_stacked = is_stacked
super(FilteredSelectMultiple, self).__init__(attrs, choices)
def render(self, name, value, attrs=None, choices=()):
- if attrs is None: attrs = {}
+ if attrs is None:
+ attrs = {}
attrs['class'] = 'selectfilter'
- if self.is_stacked: attrs['class'] += 'stacked'
+ if self.is_stacked:
+ attrs['class'] += 'stacked'
output = [super(FilteredSelectMultiple, self).render(name, value, attrs, choices)]
output.append(u'<script type="text/javascript">addEvent(window, "load", function(e) {')
# TODO: "id_" is hard-coded here. This should instead use the correct
@@ -43,15 +47,21 @@ def render(self, name, value, attrs=None, choices=()):
return mark_safe(u''.join(output))
class AdminDateWidget(forms.DateInput):
- class Media:
- js = ["admin/js/calendar.js", "admin/js/admin/DateTimeShortcuts.js"]
+
+ @property
+ def media(self):
+ js = ["calendar.js", "admin/DateTimeShortcuts.js"]
+ return forms.Media(js=[static("admin/js/%s" % path) for path in js])
def __init__(self, attrs={}, format=None):
super(AdminDateWidget, self).__init__(attrs={'class': 'vDateField', 'size': '10'}, format=format)
class AdminTimeWidget(forms.TimeInput):
- class Media:
- js = ["admin/js/calendar.js", "admin/js/admin/DateTimeShortcuts.js"]
+
+ @property
+ def media(self):
+ js = ["calendar.js", "admin/DateTimeShortcuts.js"]
+ return forms.Media(js=[static("admin/js/%s" % path) for path in js])
def __init__(self, attrs={}, format=None):
super(AdminTimeWidget, self).__init__(attrs={'class': 'vTimeField', 'size': '8'}, format=format)
@@ -232,9 +242,9 @@ def __deepcopy__(self, memo):
memo[id(self)] = obj
return obj
- def _media(self):
+ @property
+ def media(self):
return self.widget.media
- media = property(_media)
def render(self, name, value, *args, **kwargs):
rel_to = self.rel.to
@@ -28,7 +28,7 @@ def find(self, path, all=False):
"""
raise NotImplementedError()
- def list(self, ignore_patterns=[]):
+ def list(self, ignore_patterns):
"""
Given an optional list of paths to ignore, this should return
a two item iterable consisting of the relative path and storage
Oops, something went wrong. Retry.

0 comments on commit 1d32bdd

Please sign in to comment.