Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Last active January 2, 2016 09:29
Show Gist options
  • Save kezabelle/8283005 to your computer and use it in GitHub Desktop.
Save kezabelle/8283005 to your computer and use it in GitHub Desktop.
Implement a semistatic handler app for Django?
  • Provide middleware;
    • If user is anonymous, look for file in BUILD_DIR
      • If it exists, return it immediately
      • If it doesn't exist, call the view
      • If it doesn't exist and it returns a 2xx, write it to the builder
      • If it doesn't exist and it returns a 3xx, write the 30x.html template to the builder, pointing at the redirect endpoint
      • If it doesn't exist and it returns a 404, write the 404.html to the builder
    • If the user is not anonymous, render the original view, including other middlewares etc.
    • Middleware has an inclusions regex -- see django-moreloaders for regex ideas.
  • Provide builders;
    • Attachable to a view or a model
    • Builders use one of the staticfiles storage engines
    • See implementation of django-bakery and django-medusa for useful ideas.
    • Builders are attached like so: `class MyView(View): builder = StorageBuilder(storage=??)
      • Builders fall back to a default storage
    • writing the files should try and follow the django-medusa/bakery pathing format (which I think is just index.html if ends with /)
  • Provide management commands;
    • for doing a build of all urlconf views which have a builder
    • If possible, provide stdout output for putting passthroughs in into Apache/NGINX??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment