Skip to content
This repository has been archived by the owner on Jan 9, 2018. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed Aug 22, 2011
2 parents a79ebad + 0bb5a93 commit bdaa116
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 262 deletions.
3 changes: 1 addition & 2 deletions .gitignore
@@ -1,6 +1,5 @@
*.pyc
*.pyo
*~
*.swp
*.orig
*.kpf
Expand All @@ -20,6 +19,6 @@ downloads/*
bin/*
develop-eggs/*.egg-link
docs/_build
tests/project/site_media/*
tests/project/site_media/static/*
.tox/
*.egg
3 changes: 2 additions & 1 deletion AUTHORS
Expand Up @@ -4,4 +4,5 @@ Brian Beck <exogen@gmail.com>
Brian Rosner <brosner@gmail.com>
Chris Beaven <smileychris@gmail.com>
Carl Meyer <carl@dirtcircle.com>
Luke Lee <durdenmisc@gmail.com>
Luke Lee <durdenmisc@gmail.com>
Sébastien Fievet <zyegfryed@gmail.com>
13 changes: 10 additions & 3 deletions setup.py
Expand Up @@ -97,11 +97,9 @@ def find_package_data(
return out


VERSION = __import__("staticfiles").__version__

setup(
name="django-staticfiles",
version=VERSION,
version=":versiontools:staticfiles:",
description="A Django app that provides helpers for serving static files.",
long_description=read("README.rst"),
author="Jannis Leidel",
Expand All @@ -117,7 +115,16 @@ def find_package_data(
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
"Framework :: Django",
],
zip_safe=False,
install_requires=[
'django-appconf >= 0.2.2',
],
setup_requires=[
'versiontools >= 1.6',
],
)
18 changes: 2 additions & 16 deletions staticfiles/__init__.py
@@ -1,16 +1,2 @@
VERSION = (1, 1, 0, "f", 0) # following PEP 386
DEV_N = None


def get_version():
version = "%s.%s" % (VERSION[0], VERSION[1])
if VERSION[2]:
version = "%s.%s" % (version, VERSION[2])
if VERSION[3] != "f":
version = "%s%s%s" % (version, VERSION[3], VERSION[4])
if DEV_N:
version = "%s.dev%s" % (version, DEV_N)
return version


__version__ = get_version()
# following PEP 386, versiontools will pick it up
__version__ = (1, 1, 1, "final", 0)
57 changes: 55 additions & 2 deletions staticfiles/models.py
@@ -1,5 +1,58 @@
# Initialize the settings.
from staticfiles import settings
"""
Initializes the settings
"""
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from appconf import AppConf


class StaticFilesConf(AppConf):
# The directory in which the static files are collected in
ROOT = ''
# The URL path to STATIC_ROOT
URL = None
# A tuple of two-tuples with a name and the path of additional directories
# which hold static files and should be taken into account
DIRS = ()
# Apps that shouldn't be taken into account when collecting app media
EXCLUDED_APPS = ()
# Destination storage
STORAGE = 'staticfiles.storage.StaticFilesStorage'
# List of finder classes that know how to find static files in
# various locations.
FINDERS = (
'staticfiles.finders.FileSystemFinder',
'staticfiles.finders.AppDirectoriesFinder',
# 'staticfiles.finders.DefaultStorageFinder',
)

def configure_root(self, value):
"""
Use STATIC_ROOT since it doesn't has the default prefix
"""
root = value or getattr(settings, 'STATIC_ROOT', None)
if (self.MEDIA_ROOT and root) and (self.MEDIA_ROOT == root):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
"settings must have different values")
self.STATIC_ROOT = root
return root

def configure_url(self, value):
"""
Use STATIC_URL since it doesn't has the default prefix
"""
url = value or getattr(settings, 'STATIC_URL', None)
if not url:
raise ImproperlyConfigured("You're using the staticfiles app "
"without having set the required "
"STATIC_URL setting.")
if url == self.MEDIA_URL:
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values")
self.STATIC_URL = url
return url


# Okay, this is ugly, but I don't see another way except adding a registry
# pattern thingie to Django which seems like overengineering. Meh.
Expand Down
51 changes: 0 additions & 51 deletions staticfiles/settings.py

This file was deleted.

27 changes: 18 additions & 9 deletions staticfiles/storage.py
Expand Up @@ -97,8 +97,8 @@ def __init__(self, *args, **kwargs):
def hashed_name(self, name, content=None):
if content is None:
if not self.exists(name):
raise ValueError("The file '%s' could not be found with %r." %
(name, self))
raise ValueError(
"The file '%s' could not be found with %r." % (name, self))
try:
content = self.open(name)
except IOError:
Expand Down Expand Up @@ -144,13 +144,22 @@ def converter(matchobj):
return matched
name_parts = name.split('/')
# Using posix normpath here to remove duplicates
result = url_parts = posixpath.normpath(url).split('/')
level = url.count('..')
if level:
result = name_parts[:-level - 1] + url_parts[level:]
elif name_parts[:-1]:
result = name_parts[:-1] + url_parts[-1:]
joined_result = '/'.join(result)
url = posixpath.normpath(url)
url_parts = url.split('/')
parent_level, sub_level = url.count('..'), url.count('/')
if url.startswith('/'):
sub_level -= 1
url_parts = url_parts[1:]
if parent_level or not url.startswith('/'):
start, end = parent_level + 1, parent_level
else:
if sub_level:
if sub_level == 1:
parent_level -= 1
start, end = parent_level, sub_level - 1
else:
start, end = 1, sub_level - 1
joined_result = '/'.join(name_parts[:-start] + url_parts[end:])
hashed_url = self.url(joined_result, force=True)
# Return the hashed and normalized version to the file
return 'url("%s")' % hashed_url
Expand Down

0 comments on commit bdaa116

Please sign in to comment.