Skip to content
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

Conditional PDF rendering based on query parameters #62

Open
richin13 opened this issue Jul 12, 2018 · 0 comments
Open

Conditional PDF rendering based on query parameters #62

richin13 opened this issue Jul 12, 2018 · 0 comments

Comments

@richin13
Copy link

Hello there 👋,

I want to propose a new feature.

Use case

I have a view that recently 'got converted' to PDFTemplateView but that view only works for a few scenarios. There is still and scenario where I need the view to be a plain HTML response. Being able to configure PDFTemplateView to render the view as a PDF file based on some configured query parameter comes in handy to achieve such behavior.

Say for example I have a view at the endpoint /invoices/123. The idea is that if I fetch /invoices/123 it returns a plain HTML response. But if I fetch /invoices/123?pdf or /invoices/123?format=pdf the PDFTemplateView will do its job.

Of course this would break the existing behavior but we can make it work without the need to make a major version bump.

Implementation

Taking into consideration backwards compatibility as the most important aspect I was thinking that we should add an extra view property (and its corresponding get method)

...


class MyAwesomeView(DetailView, PDFTemplateResponseMixin):
    model = ....
    trigger = 'pdf' # Naming it's not my strength

    # or
    def get_trigger(self): # Again, naming...
        return 'pdf'

This way, existing implementations that do not include a trigger option will behave exactly the same as a None value for trigger would normally render the view as a PDF file.

PR

I already went ahead and forked the repo to start working on this. Any comment or thought will be appreciated. And If anyone can come with a better naming for the class' property I will highly grateful 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant