You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
...
classMyAwesomeView(DetailView, PDFTemplateResponseMixin):
model= ....
trigger='pdf'# Naming it's not my strength# ordefget_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 😅
The text was updated successfully, but these errors were encountered:
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)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 😅
The text was updated successfully, but these errors were encountered: