-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need some way to figure out if the page is being generated statically #144
Comments
Work-around below allows a developer using one DJANGO_SETTINGS_MODULE, or QA using a "preview" button, to see what the page will look like when generated "for the public". This is made a bit orthogonal to django-bakery, but remains a work-around. class IsPublicMixin:
def create_request(self, path):
request = RequestFactory().get(path)
request.GET = QueryDict('public=%s' % str(settings.IS_PUBLIC))
return request
def is_public(self):
public = self.request.GET.get('public', 'false').lower()
if public not in {'1', '0', 'yes', 'no', 'false', 'true'}:
logger.warning('public CGI parameter is not truthy')
return settings.IS_PUBLIC or public in {'1', 'yes', 'true'}
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
'public': self.is_public()
})
return context |
So, my plan is to shadow the "build" management command with one of my own which overrides the setings.IS_PUBLIC. I think a context manager that returns whether you are in a static context would also be a good idea here. |
I don't need to do that - I've overridden create_request already... I guess its been awhile since I looked at this issue. I've been waiting for operations to make a mount point on the batch server so I can add this to my scheduled tasks. |
So, to generalize this, we need to send custom meta-data to the request by default, by sending a custom header X-Bakery: 1 here https://github.com/datadesk/django-bakery/blob/2c9c495e4e8faca7b81fa57635d1631933f14171/bakery/views/base.py#L44 |
CURRENT BEHAVIOR
The project includes no additional context processors or request headers which I can re-skin the pages to look different when generated statically.
DESIRED BEHAVIOR
Custom request.META such as "HTTP_X_BAKERY: True" or something.
POTENTIAL SOLUTIONS
settings.BAKERY_REQUEST_HEADER
defaults to'X-Generator'
. The request will have therequest.META[settings.BAKERY_REQUEST_HEADER]
set to positive during build process.bakery.context_processors.baking
provides template context "baking" set to True ifBAKERY_REQUEST_HEADER
is set, and to False otherwise.MOTIVATING EXAMPLE
The internal reports/dashboards will have different navigation options than their public, static counterparts.
The text was updated successfully, but these errors were encountered: