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