ValueError: The file could not be found with staticfiles.storage.CachedStaticFilesStorage
zyegfryed opened this issue · comments
Hi Janis,
I'm trying the new nice CachedStaticFilesStorage backend shipped on 1.1 release, but i'm facing an issue.
On a css file (from TinyMCE) there is the following css definition:
background:url(img/horizontal.gif) no-repeat 0 -75px;
[...]
When collecting the staticfile a ValueError is raised.
Here are the original path :
- js/tiny_mce/plugins/inlinepopups/skins/clearlooks2/window.css
- js/tiny_mce/plugins/inlinepopups/skins/clearlooks2/img/horizontal.gif
The converter is looking for the file : js/tiny_mce/plugins/inlinepopups/skins/clearlooks2/horizontal.gif. Thus the error. (The img path part is missing.)
IMHO, the issue is in https://github.com/jezdez/django-staticfiles/blob/master/staticfiles/storage.py#L152 where :
result = name_parts[:-1] + url_parts[-1:]
should be replaced by :
result = name_parts[:-1] + url_parts
What do you think ?
or:
result = name_parts[:-1] + url_parts[level:]
I wanted to provide a patch through a pull-request, but i don't know how to run the test suite...
What do you think ?
Seems like modifying the following lines:
if level: result = name_parts[:-level - 1] + url_parts[level:] elif name_parts[:-1]: result = name_parts[:-1] + url_parts[-1:]
with :
result = name_parts[:-level - 1] + url_parts[level:]
...does the trick.
Running the test suite is as easy as installing tox and running tox
in the tests directory.
Nice, i'll try it right now.
Nope, i can't manage to get the test suite to run.
I created a tests/project/site_media/ folder since it was missing, and now i've got a bunch of:
IOError: [Errno 2] No such file or directory: u'/var/folders/NI/NIDXZQTHG+eGxueu+xqDZU+++TI/-Tmp-/tmplSscqz/subdir/test.txt'
# replace test.txt with all text files tested.
Any idea, so i can ran the test suite ?
Here's what i did to install/run tox:
$ sudo pip install tox # installs on my global Mac Python
$ cd tests && tox -e py26-1.3.X # since i only have py26 on my Mac
[...]
Ran 69 tests in 2.538s
FAILED (failures=10, errors=19)
Destroying test database for alias 'default'...
[TOX] ERROR: InvocationError: '/Users/sebastien/dev/django-apps/django-staticfiles/tests/.tox/py26-1.3.X/bin/django-admin.py test tests --settings=tests.settings'
___________________________________________________________ [tox summary] ___________________________________________________________
[TOX] ERROR: py26-1.3.X: commands failed
uh, weird, mind pasting the full test traceback somewhere?
Sure, here it is: http://friendpaste.com/6ClEjUJDh0nZ3fqTHf09Dr
Wait a sec, it was my refactoring and me not correctly resetting my environment. Fix forthcoming..
OK, let me know by leaving a comment.
Thks.
Okay, fixed the tests in 5797b4f.
\o/ The test suite is OK.
Closing this ticket, i'll make a pull-request instead. Way more easy for you to review/merge.
Thanks.