diff --git a/django_medusa/management/commands/staticsitegen.py b/django_medusa/management/commands/staticsitegen.py index a592b8e..9540dce 100644 --- a/django_medusa/management/commands/staticsitegen.py +++ b/django_medusa/management/commands/staticsitegen.py @@ -1,5 +1,4 @@ from django.core.management.base import BaseCommand -from django_medusa.renderers import StaticSiteRenderer from django_medusa.utils import get_static_renderers @@ -10,10 +9,14 @@ class Command(BaseCommand): 'a class for processing one or more URL paths into static files.' def handle(self, *args, **options): - StaticSiteRenderer.initialize_output() + renderers = get_static_renderers() - for Renderer in get_static_renderers(): + for Renderer in renderers: + Renderer.initialize_output() + + for Renderer in renderers: r = Renderer() r.generate() - StaticSiteRenderer.finalize_output() + for Renderer in renderers: + Renderer.finalize_output() diff --git a/django_medusa/renderers/__init__.py b/django_medusa/renderers/__init__.py index 2200369..fb0c441 100644 --- a/django_medusa/renderers/__init__.py +++ b/django_medusa/renderers/__init__.py @@ -1,5 +1,10 @@ from django.conf import settings -from django.utils import importlib +try: + # Django versions < 1.9 + from django.utils.importlib import import_module +except ImportError: + # Django versions >= 1.9 + from django.utils.module_loading import import_module from .base import BaseStaticSiteRenderer from .disk import DiskStaticSiteRenderer from .appengine import GAEStaticSiteRenderer @@ -12,7 +17,7 @@ def get_cls(renderer_name): mod_path, cls_name = renderer_name.rsplit('.', 1) - mod = importlib.import_module(mod_path) + mod = import_module(mod_path) return getattr(mod, cls_name) diff --git a/django_medusa/renderers/disk.py b/django_medusa/renderers/disk.py index 76821e5..7301384 100644 --- a/django_medusa/renderers/disk.py +++ b/django_medusa/renderers/disk.py @@ -35,6 +35,9 @@ def _disk_render_path(args): outpath = os.path.join(DEPLOY_DIR, realpath) resp = client.get(path) + if resp.status_code == 301 or resp.status_code == 302: + print('%s - redirect - skipping...' % path) + return None if resp.status_code != 200: raise Exception if needs_ext: @@ -53,7 +56,11 @@ def _disk_render_path(args): outpath += "index.html" print(outpath) with open(outpath, 'wb') as f: - f.write(resp.content) + if resp.streaming: + for chunk in resp.streaming_content: + f.write(chunk) + else: + f.write(resp.content) class DiskStaticSiteRenderer(BaseStaticSiteRenderer):