django-static-sitemaps
django-static-sitemaps copied to clipboard
When using s3 boto storage, path gets prepended to the filename twice
The value of SITEMAP_ROOT_DIR gets prepended to the filename twice. I had do use a custom storage to avoid this happening:
class S3SitemapStorage(S3BotoStorage):
def __init__(self, *args, **kwargs):
super(S3SitemapStorage, self).__init__(*args, **kwargs)
self.location = ''
Used an alteration of the above to fix this for the normal storage method.
Add to settings.py
STATICSITEMAPS_STORAGE = 'myproject.sitemaps.SitemapStorage'
Add to myproject/sitemaps.py
from django.core.files.storage import FileSystemStorage
class SitemapStorage(FileSystemStorage):
def __init__(self, *args, **kwargs):
super(SitemapStorage, self).__init__(*args, **kwargs)
self.location = ''
As @lsemel says, this fixes the duplication of a custom SITEMAP_ROOT_DIR
@digitaltommy Can you make a pull request out of it? It would be appreciated. Thx
@xaralis sorry just seen this comment - do these pull requests need doing still?
It's because SitemapGenerator.storage
is initialized with location=conf.ROOT_DIR
(https://github.com/xaralis/django-static-sitemaps/commit/5ede702d8f8cd99d7f1987c9a8fd41bf7262060a#diff-3d35d9fe93e9b30725df9b15374bea77R27)
- storage = _lazy_load(conf.STORAGE_CLASS)()
+ self.storage = _lazy_load(conf.STORAGE_CLASS)(location=conf.ROOT_DIR)
and S3 storage prepends self.location
to every path you want to access. (https://github.com/jschneier/django-storages/blob/1.7.1/storages/backends/s3boto.py#L363)
return safe_join(self.location, name)
Before fixing it, we should find out the original intent of location=conf.ROOT_DIR
in the first place. @xaralis
@puzzlet Correct. I've reviewed the code and don't see any specific reason why this line (self.storage = _lazy_load(conf.STORAGE_CLASS)(location=conf.ROOT_DIR)
) should have location
argument in the call. Simply beacuse when writing using the storage, full path is provided too.
It's probably some old thing that noone noticed. It should be safe to remove.
still not fixed?