A static site generator for Django views
Convert your Django views into a collection of static HTML files. Or, put another way, a Django based static-site-generator with few opinions.
This is my attempt at a different type of static site renderer, instead leveraging the availability of Django’s staticfiles functionality to leave specifics to someone else :) The theory is thus that you could choose a third party storage from, say, django-storages and plug it into jackfrost and have things Just Work.
I don’t actually know if that’s true though.
pip installing the latest release via PyPI:
pip install django-jackfrost==0.4.0
If you want to get the latest, unstable version, you can use something like this (again with pip) I think:
pip install git+https://github.com/kezabelle/django-jackfrost.git#egg=django-jackfrost
Put jackfrost into your INSTALLED_APPS:
INSTALLED_APPS = ( 'django.contrib.auth', # ... 'jackfrost', # ... )
which will enable the management command:
python manage.py collectstaticsite --processes=N
Set JACKFROST_STORAGE to whatever storage backend you’d like to use, in your project’s settings. By default, a subclass of django.contrib.staticfiles.storage.StaticFilesStorage which puts output into a jackfrost directory will be used.
If your storage backend needs any arguments that can’t be gleaned from individual settings, you can set JACKFROST_STORAGE_KWARGS to a dictionary of arguments to be used when instantiating the JACKFROST_STORAGE
Add a JACKFROST_RENDERERS setting, which should be a list or tuple of dotted paths to python classes or functions, much like MIDDLEWARE_CLASSES, TEMPLATE_CONTEXT_PROCESSORS etc:
JACKFROST_RENDERERS = ( 'myapp.renderers.MyModelRenderer', 'my_other_app.utils.SomeOtherRenderer', )
In theory, I don’t care whether your JACKFROST_RENDERERS are functions or classes; if it’s a class it must implement __call__. Either way, it should, when called, return a number of URL paths to be consumed.
If you have a model which has a get_absolute_url method, your renderer can be as simple as:
from jackfrost.models import ModelRenderer class MyModelRenderer(ModelRenderer): def get_model(self): return MyModel
If you need to customise the queryset, there is a get_queryset method which can be replaced. There is also a get_urls method, if you need to go totally off-reservation.
Giving jackfrost the dotted path to a standard Django sitemap as one of the JACKFROST_RENDERERS should do the right thing, and get the URLs out of the sitemap itself without you needing to do anything or write a new renderer.
In theory, giving jackfrost the dotted path to a subclass of the django-medusa BaseStaticSiteRenderer should do the right thing, and get the URLs out of the medusa renderer itself, without you doing anything. It will avoid going through the medusa rendering process, instead it’ll go through mine.
The most basic renderer would be:
def myrenderer_yielding(): yield reverse('app:name')
def myrenderer(): return [reverse('app:name')]
Renderers may also be classes:
class MyRenderer(object): __slots__ = () def __init__(self): pass def __call__(self): yield reverse('app:name')
There are 8 signals in total:
Additionally, there is a listener, jackfrost.utils.build_page_for_obj which is suitable for being used as a pre_save or post_save receiver for a Model instance, and will attempt to build just the get_absolute_url for that object.
If a Model instance implements a jackfrost_can_build method, this is checked before building the static page. If jackfrost_can_build returns False, the page won’t get built. Any other value will result in it being built.
If a Model instance implements a jackfrost_urls method, this is used instead of the get_absolute_url, and should return an iterable of all the URLs to consider building.
If the Model instance has a get_list_url method, that page will also be built. Useful for updating any ListView pages, etc.
Where possible, jackfrost will attempt to compensate for redirects (301, 302 etc)
by writing an HTML page with a <meta refresh> tag pointing at the final
endpoint. The template used is called
Additionally, static pages for 401, 403, 404 and 500 errors will be built from their respective templates, if they exist. Useful if you want to wire up Apache ErrorDocument directives or whatever.
Given a complete clone:
python setup.py test
django-jackfrost 0.4.0 is available under the terms of the Simplified BSD License (alternatively known as the FreeBSD License, or the 2-clause License):
Copyright (c) 2015, Keryn Knight All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|django_jackfrost-0.4.0-py2.py3-none-any.whl (39.7 kB) Copy SHA256 Checksum SHA256||py2.py3||Wheel||Jul 13, 2015|
|django-jackfrost-0.4.0.tar.gz (22.5 kB) Copy SHA256 Checksum SHA256||–||Source||Jul 13, 2015|