Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#15320 closed (wontfix)

staticfiles allows change of storage backend on collection but not when searching for files

Reported by: imbaczek@… Owned by:
Component: contrib.staticfiles Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

the culprits are:

finders.py:

64	        for prefix, root in self.locations:
65	            filesystem_storage = FileSystemStorage(location=root)

i need the FileSystemFinder to think that some files are always modified (i want to use them as overrides for a simple skin system.)

here's the storage i'm want to use (in django 1.2 and backported staticfiles, but everything is still applicaple):

import os.path
from datetime import datetime

from django.conf import settings

from staticfiles.storage import StaticFileStorage


class SkinAwareStorage(StaticFileStorage):
    def __init__(self, *args, **kwargs):
        super(SkinAwareStorage, self).__init__(*args, **kwargs)


    def modified_time(self, name):
        '''Always return current time for non-default skins'''
        p = self.path(name)
        if p.startswith(os.path.join(settings.STATIC_ROOT, 'skins')) \
                and not p.startswith(os.path.join(settings.STATIC_ROOT, 'skins', 'default')):
            return datetime.now()
        else:
            return super(SkinAwareStorage, self).modified_time(name)

my suggestion: a STATICFILES_FINDER_STORAGE settings parameter.

Change History (4)

comment:1 by Jannis Leidel, 14 years ago

Resolution: wontfix
Status: newclosed

This seems like an edge case to me (hence closing), but for the record that's pretty easy to do already:

class SkinAwareFinder(FileSystemFinder):
    def __init__(self, *args, **kwargs):
        super(SkinAwareFinder, self).__init__(*args, **kwargs)
        for prefix, root in self.locations:
            skinaware_storage = SkinAwareStorage(location=root)
            skinaware_storage.prefix = prefix
            self.storages[root] = skinaware_storage

Also, you probably don't want your SkinAwareStorage class to subclass StaticFileStorage but simply FileSystemStorage since that's only used for the collection.

comment:2 by imbaczek@…, 14 years ago

i was following the comment in django-staticfiles docs about finder interface being private - don't want an api change to blow up in my face when least expeceted. it's going to be a bit scary if you suddenly decide to change self.storages into something else.

anyway, thanks for the tip.

in reply to:  2 comment:3 by Jannis Leidel, 14 years ago

Replying to imbaczek@…:

i was following the comment in django-staticfiles docs about finder interface being private - don't want an api change to blow up in my face when least expeceted. it's going to be a bit scary if you suddenly decide to change self.storages into something else.

I understand your concern, and in fact I did some changes on the API in the last couple of months. Once 1.3 is out we can revisit the decision about making the finder API private.

comment:4 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top