Fix extension packaging when referencing static files in a .less.

Review Request #7437 - Created June 18, 2015 and submitted

Christian Hammond
Djblets
release-0.8.x
6ecb381...
djblets

When Django processes a static file (either a .css file that was already
in the tree, or one that was compiled from a .less file), it will look
for certain references to other static files, through calls to @import
or url(...). It then attempts to load these in to generate a suitable
path to a version with a hash in the filename. The assumption it makes
is that this referenced static file lives in the same static storage as
the file referencing it, which is a bad assumption for extensions.

We now have a custom storage for static files that tries to determine if
the file referenced is in a different storage. If so, that storage is
used to compute the path. Otherwise, it falls back on the standard logic
of checking the parent file's storage.

This shouldn't require any changes to extensions, particularly since
they weren't working before in this regard.

The one change that may impact .less files doing something funky is that
@{STATIC_ROOT} is no longer blank when packaging, and the include paths
no longer include the static/ directory. If extensions were properly
using @{STATIC_ROOT} for all .less file references, then this won't
break anything. References to other files, like image backgrounds in
stylesheets, can now use @{STATIC_ROOT} as well and expect a proper path
back.

One important note is that we have no way of generating paths that are
relative to the root of the application. For subdirectory installs,
these paths are not going to be correct. It's pretty important that
sites host on the top of their domain instead.

Modified rbmotd to reference header_bg.png in Djblets, and tried building
it. Prior to this change, it would fail, being unable to look up the path
in a different app. After this change, it succeeded, generating the correct
URL in the CSS file.

Unit tests pass.

  • 0
  • 0
  • 0
  • 1
  • 1
Description From Last Updated
Review Bot
  1. Tool: Pyflakes
    Processed Files:
        djblets/extensions/staticfiles.py
        djblets/extensions/packaging.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/extensions/staticfiles.py
        djblets/extensions/packaging.py
    
    
  2. 
      
David Trowbridge
  1. 
      
  2. djblets/extensions/staticfiles.py (Diff revision 1)
     
     

    This needs a docstring.

    1. There's nothing useful in here to document. It's only really useful if it's going to differ from that of the class, or has specific arguments we want to document.

  3. 
      
Christian Hammond
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-0.8.x (c8a7e24)
Loading...