Permalink
Browse files

Fixed #5211 -- Added paths starting with '/' to the list of paths tha…

…t are preserved as-is by the widget media framework.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5986 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent c49f2d2 commit 88987ed0ac6c29b78e2321e6f6687cb1385510fc @freakboy3742 freakboy3742 committed Aug 20, 2007
Showing with 106 additions and 99 deletions.
  1. +4 −1 django/newforms/widgets.py
  2. +5 −1 docs/newforms.txt
  3. +97 −97 tests/regressiontests/forms/media.py
@@ -14,6 +14,7 @@
from django.utils.translation import ugettext
from django.utils.encoding import StrAndUnicode, force_unicode
from util import flatatt
+from urlparse import urljoin
__all__ = (
'Media', 'Widget', 'TextInput', 'PasswordInput',
@@ -62,7 +63,9 @@ def render_css(self):
for medium in media])
def absolute_path(self, path):
- return (path.startswith(u'http://') or path.startswith(u'https://')) and path or u''.join([settings.MEDIA_URL,path])
+ if path.startswith(u'http://') or path.startswith(u'https://') or path.startswith(u'/'):
+ return path
+ return urljoin(settings.MEDIA_URL,path)
def __getitem__(self, name):
"Returns a Media object that only contains media of the given type"
View
@@ -2139,17 +2139,21 @@ Paths in media definitions
--------------------------
Paths used to specify media can be either relative or absolute. If a path
-starts with 'http://' or 'https://', it will be interpreted as an absolute
+starts with '/', 'http://' or 'https://', it will be interpreted as an absolute
path, and left as-is. All other paths will be prepended with the value of
``settings.MEDIA_URL``. For example, if the MEDIA_URL for your site was
``http://media.example.com/``::
class CalendarWidget(forms.TextInput):
class Media:
+ css = {
+ 'all': ('/css/pretty.css',),
+ }
js = ('animations.js', 'http://othersite.com/actions.js')
>>> w = CalendarWidget()
>>> print w.media
+ <link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="http://media.example.com/animations.js"></script>
<script type="text/javascript" src="http://othersite.com/actions.js"></script>
Oops, something went wrong.

0 comments on commit 88987ed

Please sign in to comment.