Appy Views¶
Views¶
A TemplateView that allows to set
desired output format
Content-Disposition on the response using
output_name
output file name
Usage examples¶
Directly in urls.py
:
urlpatterns = [
path('', views.IndexView.as_view(), name="appy-examples"),
path('pdf/simple', AppyTemplateView.as_view(
template_name='examples/simple.odt'), name='pdf-simple'),
path('odt/simple', AppyTemplateView.as_view(
template_name='examples/simple.odt', output_type='odt'), name='odt-simple'),
path('odt/context', views.OdtContextView.as_view(), name='odt-context'),
path('pdf/context', views.PdfContextView.as_view(), name='pdf-context'),
]
Or in views.py
as:
class PdfContextView(AppyTemplateView):
template_name = 'examples/context.odt'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['name'] = 'Sandro'
return context
class OdtContextView(PdfContextView):
output_type = 'odt'
-
class
thx.appy.views.
AppyTemplateView
(**kwargs)[sorgente]¶ A templateView that just need a template_name and an output_format
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
-
class
thx.appy.views.
AppyTemplateMixin
[sorgente]¶ Mixin that tries to be smart understanding how to handle an OpenDocument File as far as:
- Content_type
desumed from
output_format
- Output_name
desumed from
template_name
andoutput_format
-
content_type
= None¶ the content type used in the response
-
external
= None¶ forces/blocks use of external service for conversion if POD_CONVERTER is defines
-
get_content_type
()[sorgente]¶ Return the deesired output_format according
-
get_output_name
()[sorgente]¶ Return the output_file_name or build a suitable one
-
output_file_name
= None¶ the desired output name. Default is built using template_name and changing the suffix according to the output_format
-
output_format
= 'pdf'¶ the desired output type: pdf, odt, ods are supported
-
render_to_response
(context, **response_kwargs)[sorgente]¶ Return a response, using the response_class for this view, with a template rendered with the given context. Pass response_kwargs to the constructor of the response class.
-
response_class
¶ alias per
AppyTemplateResponse