Comments (8)
Related to #44
from django-bakery.
For what it's worth, this is the approach that I took to use Django Bakery to build the site in a subdirectory. It uses monkey patching, so be warned. I put this code inside a Fabric task. This might be a workable hack for those who need to do this until this issue gets resolved:
from django.conf import settings
old_build_dir = settings.BUILD_DIR
old_static_url = settings.STATIC_URL
old_initial_reuters_deflection = settings.INITIAL_REUTERS_DEFLECTION;
settings.INITIAL_REUTERS_DEFLECTION = 'cache'
settings.BUILD_DIR = os.path.join(settings.BUILD_DIR, settings.ARCHIVE_PATH)
settings.STATIC_URL = posixpath.join('/', settings.ARCHIVE_PATH,
settings.STATIC_URL.strip('/')) + '/'
# HACK: Monkey patch django.core.urlresolvers.reverse to prefix generated URLs with
# settings.ARCHIVE_PATH
import django.core.urlresolvers
old_reverse = django.core.urlresolvers.reverse
def reverse_patched(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current_app=None):
url = old_reverse(viewname, urlconf, args, kwargs, prefix, current_app)
return '/' + settings.ARCHIVE_PATH + url
setattr(django.core.urlresolvers, 'reverse', reverse_patched)
# Call Django Bakery's build management command. Skip copying the static
# files because the way the management command calculates the target
# directory based on settings.BUILD_DIR and settings.STATIC_URL doesn't
# work with the way we've altered these things here.
management.call_command('build', skip_static=True)
# Copy static assets to the the build directory. We do this explicitly
# here because the ``build`` management command won't calculate the
# correct directory with our settings.STATIC_URL
target_dir = os.path.join(old_build_dir, settings.STATIC_URL[1:])
if getattr(settings, 'BAKERY_GZIP', False):
# The build management command class has a nice method copytree_and_gzip,
# but we have to create call it directly if we want to specify the target directory
cmd = Command()
cmd.verbosity = 1
cmd.copytree_and_gzip(settings.STATIC_ROOT, target_dir)
# if gzip isn't enabled, just copy the tree straight over
else:
shutil.copytree(settings.STATIC_ROOT, target_dir)
# Undo our monkey patches and patched settings
# This gives the next task a clean slate in case we chain Fabric
# tasks, e.g. fab chicago archive_build_local archive_publish_local
settings.BUILD_DIR = old_build_dir
settings.STATIC_URL = old_static_url
setattr(django.core.urlresolvers, 'reverse', old_reverse)
from django-bakery.
Very interesting. Can you point me to the live example so I can see how it turns out?
from django-bakery.
Let me get back to you on that. I'm in the process of rolling a new elections.chicagotribune.com which will have the 2014-11-04 election results archived in a "subdirectory" of the S3 bucket.
from django-bakery.
Example of site baked by dynamically adjusting settings and monkey-patching django.core.urlresolvers.reverse
as described in my previous comment: http://elections.chicagotribune.com/2014-11-04/
from django-bakery.
I think I'm going to stop pretending I will ever solve this.
from django-bakery.
There is the new --aws-bucket-prefix
option on publish
. I think that's as far as I will ever get unless someone else comes through.
from django-bakery.
I forgot this thread happened!
from django-bakery.
Related Issues (20)
- Relative path to the build directory is treated like absolute HOT 5
- BuildableModel doesn't work HOT 1
- Allow rendering function views HOT 1
- Bakery doesn't run `MIDDLEWARE_CLASSES`/`MIDDLEWARES` on build HOT 3
- InvalidCharsInPath error for BUILD_DIR while attempting to build project HOT 15
- Build fails when I add messages HOT 2
- Incremental builds through change detection? HOT 1
- Excluding model media from build HOT 1
- Gzip corrupts buildserver response
- Working with Digital Ocean Spaces
- Need some way to figure out if the page is being generated statically HOT 4
- Integration with django-storages (AWS S3)
- page parameters
- Scaling memory consumption?
- Fix build command on Windows HOT 6
- Add Django 4.0 support
- Broken link HOT 1
- BUILD_DIR fails if it you give it a `pathlib.Path`
- Add an option to run AutoPublishingBuildableModel tasks without celery
- Integrate publish command with django-storages
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-bakery.