Opened 4 years ago

Closed 4 years ago

Last modified 4 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: UI/UX:

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 Changed 4 years ago by jezdez

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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 follow-up: Changed 4 years ago by 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.

anyway, thanks for the tip.

comment:3 in reply to: ↑ 2 Changed 4 years ago by jezdez

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 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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