[outreachy][cadasta] Generating the PDF out of questionnaire

After generating the HTML representation of the questionnaire. Next target was to generate the PDF out of the generated HTML. I have evaluated several libraries to generate pdf out of the generated HTML. Brian who is one of my mentor suggest to use WeasyPrint library for the task. I have used reder_to_string function of the django which takes django template and data to generates the HTML of the template which output as a string. This HTML string then inserted to WeasyPrint library API to generate the PDF. Following code segment use to generate the PDF and respond back to the user.

def post(self, request, *args, **kwargs):

pdfform = self.get_object()
project = self.get_project()
questionnaire = None
questions_list = None
questionnaire = Questionnaire.objects.get(
questions_list = Question.objects.filter(questionnaire=questionnaire)
for question in questions_list:
question_option_list = question.options.all()
question.question_option_list = question_option_list
except Questionnaire.DoesNotExist:

html_string = render_to_string('questionnaires/pdf_form_generator.html',
{'questionnaire' : questionnaire,
'questions_list' : questions_list, 'pdfform' : pdfform})
html = HTML(string=html_string, base_url=request.build_absolute_uri())
pdf = html.write_pdf(stylesheets=[
CSS(string='@page { size: A4; margin: 2cm };'
'* { float: none !important; };'
'@media print { nav { display: none; } }'
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename='+pdfform.name+'.pdf'

The sample PDF which generated from the standard cadasta questionnaire can be found in here.