fix --> error of weasy priny
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
import typing
|
||||
|
||||
from django.db import transaction
|
||||
from django.http import HttpResponse
|
||||
from django.template.loader import render_to_string
|
||||
from rest_framework import status
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.exceptions import APIException
|
||||
from rest_framework.filters import SearchFilter
|
||||
from rest_framework.response import Response
|
||||
from weasyprint import HTML
|
||||
|
||||
from apps.authentication.api.v1.api import GeneralOTPViewSet
|
||||
from apps.authorization import models as authorize_models
|
||||
@@ -32,6 +29,9 @@ from .serializers import (
|
||||
)
|
||||
|
||||
|
||||
# from weasyprint import HTML
|
||||
|
||||
|
||||
class TagViewSet(BaseViewSet, TagService, SoftDeleteMixin, DynamicSearchMixin, viewsets.ModelViewSet):
|
||||
""" Tag View Set """
|
||||
queryset = tag_models.Tag.objects.all()
|
||||
@@ -712,36 +712,36 @@ class TagDistributionBatchViewSet(
|
||||
|
||||
return Response(dashboard_data, status=status.HTTP_200_OK)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=True,
|
||||
url_path='distribution_pdf_view',
|
||||
url_name='distribution_pdf_view',
|
||||
name='distribution_pdf_view',
|
||||
)
|
||||
def distribution_pdf_view(self, request, pk=None):
|
||||
batch = tag_models.TagDistributionBatch.objects.select_related(
|
||||
'assigner_org', 'assigned_org'
|
||||
).prefetch_related('distributions').get(id=pk)
|
||||
|
||||
html_string = render_to_string(
|
||||
'pdf/tag_distribution.html', # noqa
|
||||
{'batch': batch}
|
||||
)
|
||||
|
||||
html = HTML(
|
||||
string=html_string,
|
||||
base_url=request.build_absolute_uri('/')
|
||||
)
|
||||
|
||||
pdf = html.write_pdf()
|
||||
|
||||
response = HttpResponse(pdf, content_type='application/pdf')
|
||||
response['Content-Disposition'] = (
|
||||
f'inline; filename="distribution_{batch.dist_batch_identity}.pdf"'
|
||||
)
|
||||
|
||||
return response
|
||||
# @action(
|
||||
# methods=['get'],
|
||||
# detail=True,
|
||||
# url_path='distribution_pdf_view',
|
||||
# url_name='distribution_pdf_view',
|
||||
# name='distribution_pdf_view',
|
||||
# )
|
||||
# def distribution_pdf_view(self, request, pk=None):
|
||||
# batch = tag_models.TagDistributionBatch.objects.select_related(
|
||||
# 'assigner_org', 'assigned_org'
|
||||
# ).prefetch_related('distributions').get(id=pk)
|
||||
#
|
||||
# html_string = render_to_string(
|
||||
# 'pdf/tag_distribution.html', # noqa
|
||||
# {'batch': batch}
|
||||
# )
|
||||
#
|
||||
# html = HTML(
|
||||
# string=html_string,
|
||||
# base_url=request.build_absolute_uri('/')
|
||||
# )
|
||||
#
|
||||
# pdf = html.write_pdf()
|
||||
#
|
||||
# response = HttpResponse(pdf, content_type='application/pdf')
|
||||
# response['Content-Disposition'] = (
|
||||
# f'inline; filename="distribution_{batch.dist_batch_identity}.pdf"'
|
||||
# )
|
||||
#
|
||||
# return response
|
||||
|
||||
@action(
|
||||
methods=['post', ],
|
||||
@@ -770,6 +770,7 @@ class TagDistributionBatchViewSet(
|
||||
|
||||
@action(
|
||||
methods=['post'],
|
||||
detail=True,
|
||||
url_path='accept_exit_doc',
|
||||
url_name='accept_exit_doc',
|
||||
name='accept_exit_doc',
|
||||
|
||||
Reference in New Issue
Block a user