Giter Club home page Giter Club logo

Comments (4)

danizen avatar danizen commented on August 16, 2024

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

from django-bakery.

danizen avatar danizen commented on August 16, 2024

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.

from django-bakery.

danizen avatar danizen commented on August 16, 2024

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.

from django-bakery.

danizen avatar danizen commented on August 16, 2024

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

from django-bakery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.