Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
revert my attempts to work with https
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegler committed Jun 18, 2010
1 parent 51938cb commit 44e0f40
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
25 changes: 15 additions & 10 deletions compressor/__init__.py
Expand Up @@ -10,6 +10,7 @@
from sha import new as sha1
from django import template
from django.conf import settings as django_settings
from django.template.loader import render_to_string
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from django.utils.encoding import smart_str
Expand Down Expand Up @@ -68,26 +69,24 @@ def split_contents(self):
raise NotImplementedError('split_contents must be defined in a subclass')

def get_filename(self, url):
url = url.replace("https://","http://")
if not url.startswith(settings.MEDIA_URL):
raise UncompressableFileError('"%s" is not in COMPRESS_URL ("%s") and can not be compressed' % (url, settings.MEDIA_URL))
basename = url[len(settings.MEDIA_URL):]
filename = os.path.join(settings.MEDIA_ROOT, basename)
return filename

@property
def cachebits(self):
for hunk in self.split_contents():
if hunk[0] == 'file':
yield hunk[0]
yield os.path.getmtime(hunk[1])
def mtimes(self):
return (os.path.getmtime(h[1]) for h in self.split_contents() if h[0] == 'file')

@property
def cachekey(self):
"""
cachekey for this block of css or js.
"""
cachestr = "".join((str(c) for c in self.cachebits))
cachebits = [self.content]
cachebits.extend([str(m) for m in self.mtimes])
cachestr = "".join(cachebits)
return "%s.django_compressor.%s.%s" % (DOMAIN, get_hexdigest(cachestr)[:12], settings.COMPRESS)

@property
Expand Down Expand Up @@ -149,6 +148,8 @@ def new_filepath(self):
return filepath

def save_file(self):
if default_storage.exists(self.new_filepath):
return False
default_storage.save(self.new_filepath, ContentFile(self.combined))
return True

Expand All @@ -172,9 +173,13 @@ def output(self):
"""
if not settings.COMPRESS:
return self.return_compiled_content(self.content)
url = "/".join((settings.MEDIA_URL.rstrip('/'), self.new_filepath))
self.save_file()
return self.new_filepath

context = getattr(self, 'extra_context', {})
context['url'] = url
context['xhtml'] = self.xhtml
return render_to_string(self.template_name, context)


class CssCompressor(Compressor):

Expand Down
6 changes: 5 additions & 1 deletion compressor/templates/compressor/css.html
@@ -1 +1,5 @@
<link rel="stylesheet" href="{{ MEDIA_URL }}{{ filepath }}" type="text/css" {% if xhtml %}/>{% else %}>{% endif %}
{% if xhtml %}
<link rel="stylesheet" href="{{ url }}" type="text/css" />
{% else %}
<link rel="stylesheet" href="{{ url }}" type="text/css">
{% endif %}
2 changes: 1 addition & 1 deletion compressor/templates/compressor/js.html
@@ -1 +1 @@
<script type="text/javascript" src="{{ MEDIA_URL }}{{ filepath }}"></script>
<script type="text/javascript" src="{{ url }}"></script>
10 changes: 4 additions & 6 deletions compressor/templatetags/compress.py
@@ -1,6 +1,5 @@
from django import template
from django.core.cache import cache
from django.template.loader import render_to_string

try:
from django.contrib.sites.models import Site
Expand All @@ -26,8 +25,10 @@ def render(self, context):
compressor = CssCompressor(content, xhtml=self.xhtml)
if self.kind == 'js':
compressor = JsCompressor(content, xhtml=self.xhtml)
output = cache.get(compressor.cachekey)
if output is None:
in_cache = cache.get(compressor.cachekey)
if in_cache:
return in_cache
else:
# do this to prevent dog piling
in_progress_key = '%s.django_css.in_progress.%s' % (DOMAIN, compressor.cachekey)
added_to_cache = cache.add(in_progress_key, True, 300)
Expand All @@ -39,9 +40,6 @@ def render(self, context):
while cache.get(in_progress_key):
sleep(0.1)
output = cache.get(compressor.cachekey)
if settings.COMPRESS:
return render_to_string(compressor.template_name, {'filepath':output, 'xhtml':self.xhtml}, context)
else:
return output

@register.tag
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -8,7 +8,7 @@ def read(fname):

setup(
name = "django-css",
version = "2.2.3",
version = "2.2.2",
description='django-css provides an easy way to use CSS compilers with Django projects, and an automated system for compressing CSS and JavaScript files',
url = 'http://github.com/dziegler/django-css',
license = 'BSD',
Expand Down

0 comments on commit 44e0f40

Please sign in to comment.