import pdfkit from django.shortcuts import render from django.template.loader import get_template from datetime import datetime from datetime import date from MNF.settings import BasePath from users.models import Certificate basepath = BasePath() # doc_fname = ( # (str(x.translated_ppt.upload_ppt).split("/"))[-1]).split(".")[0] # x.lpp_invoice_dialogue = f'{doc_fname}_Invoice.pdf' # x.save() # str1 = str(datetime.now()).split("-") # from .utils import render_to_pdf def certificateGenrate(name,file_from,Hash,projectname="NAN",matic=0): main = Certificate.objects.filter(user_name="MyNextFilm") if main: main1 = Certificate.objects.get(user_name="MyNextFilm") ids = main1.id # blockchain_obj = UserCredentialsForBlockchain.objects.get(user=request.user) ids = ids+1 main.update(id=ids) else: ids = 0 serializer = Certificate() serializer.user_name = "MyNextFilm" serializer.id= 0 serializer.save() context = { "name": name, "file_from": file_from, "date": date.today(), "hash": Hash, "id": ids, 'Matic':matic, 'File_name':projectname, } template = get_template( f'{basepath}/lpp/templates/lpp/blockchainCertificate.html') html = template.render(context) options = { 'page-size': 'A4', 'margin-top': '0.0in', 'margin-right': '0.0in', 'margin-bottom': '0.0in', 'margin-left': '0.0in', 'enable-local-file-access': '' } pdfkit.from_string( html, f'{basepath}/lpp/certificate/certificate.pdf', options=options,verbose=True) return f'{basepath}/lpp/certificate/certificate.pdf' # certificateGenrate("pravesh yadav","PPT Conversiom", "qwefgfdsdfgdsdcvxs")