[PATCH 0 of 1] Fix theme_static fallback from theme-specific to default content

2 views
Skip to first unread message

Ben Jackson

unread,
Nov 27, 2009, 11:40:11 PM11/27/09
to byteflow-hackers
The addition of THEME_STATIC_* had a bad default for THEME_STATIC_ROOT.
It was not the matching local path of THEME_STATIC_URL. This wouldn't
have mattered to people who explicitly set them correctly. When I
reordered the defaults to automatically incorporate THEME I didn't realize
there was a problem until...

theme_js (and all of theme_static) was broken because when THEME_STATIC_*
was added it was changed to *only* search the THEME_STATIC_* paths and
not fall back to STATIC_* where all the stock javascript and css are
kept. This was surprisingly subtle (since I didn't know what any of
byteflow or the themes was even supposed to look like) but did manifest
as 404s due to bad js/css paths and broken things like the comment
'preview' button.

The following patch fixes both problems.

--
Ben Jackson AD7GD
<b...@ben.com>
http://www.ben.com/

Ben Jackson

unread,
Nov 27, 2009, 11:40:12 PM11/27/09
to byteflow-hackers
# HG changeset patch
# User b...@ben.com
# Date 1259383109 28800
# Node ID 640779799f544294b03fda74a608218a24ef1b3e
# Parent ca2fdf9b5e162a7b9695089c9d34aee186396ca2
Fix theme_static fallback from theme-specific to default content

Changes default THEME_STATIC_ROOT to be the matching local path of
the URL THEME_STATIC_URL. Changes theme_static to search both
THEME_STATIC_* and STATIC_* to properly allow for theme overrides
and default files.

diff -r ca2fdf9b5e16 -r 640779799f54 apps/lib/templatetags/theme.py
--- a/apps/lib/templatetags/theme.py Fri Nov 27 13:29:25 2009 -0800
+++ b/apps/lib/templatetags/theme.py Fri Nov 27 20:38:29 2009 -0800
@@ -11,16 +11,18 @@
return strftime('%Y%m%d%H%M', time)

def theme_static(kind, filename):
- candidates = [[settings.THEME, kind, '%s.%s' % (filename, kind)],
- [kind, '%s.%s' % (filename, kind)]]
+ file = '%s.%s' % (filename, kind)
+ candidates = [[settings.THEME_STATIC_URL, settings.THEME_STATIC_ROOT, kind, file],
+ [settings.STATIC_URL, settings.STATIC_ROOT, settings.THEME, kind, file],
+ [settings.STATIC_URL, settings.STATIC_ROOT, kind, file]]

for candidate in candidates:
- full_path = join(settings.THEME_STATIC_ROOT, *candidate)
+ full_path = join(*candidate[1:])
if exists(full_path) and not isdir(full_path):
- url = '/'.join(candidate)
+ url = '/'.join(candidate[2:])
if settings.APPEND_MTIME_TO_STATIC:
url = '%s?%s' % (url, gettime(full_path))
- return {'STATIC_URL': settings.THEME_STATIC_URL, 'include': True, 'url': url}
+ return {'STATIC_URL': candidate[0], 'include': True, 'url': url}

return {'include': False}

diff -r ca2fdf9b5e16 -r 640779799f54 settings.py
--- a/settings.py Fri Nov 27 13:29:25 2009 -0800
+++ b/settings.py Fri Nov 27 20:38:29 2009 -0800
@@ -246,7 +246,7 @@
ADDITIONAL_APPS = ('pingback', 'watchlist')

if not hasattr(globals(), 'THEME_STATIC_ROOT'):
- THEME_STATIC_ROOT = STATIC_ROOT
+ THEME_STATIC_ROOT = os.path.join(STATIC_ROOT, THEME + '/')

if not hasattr(globals(), 'THEME_STATIC_URL'):
THEME_STATIC_URL = os.path.join(STATIC_URL, THEME + '/')

Alexander Solovyov

unread,
Nov 28, 2009, 1:48:56 AM11/28/09
to byteflow...@googlegroups.com
On Sat, Nov 28, 2009 at 6:40 AM, Ben Jackson <b...@ben.com> wrote:
>
> # HG changeset patch
> # User b...@ben.com
> # Date 1259383109 28800
> # Node ID 640779799f544294b03fda74a608218a24ef1b3e
> # Parent  ca2fdf9b5e162a7b9695089c9d34aee186396ca2
> Fix theme_static fallback from theme-specific to default content

Thanks, pushed.

--
Alexander

Reply all
Reply to author
Forward
0 new messages