Conversion_Kitchen_Code/kitchen_counter/lpp/certificate/createCertificate.py

64 lines
1.9 KiB
Python
Raw Normal View History

2024-04-27 09:33:09 +00:00
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
2024-08-08 11:07:22 +00:00
def certificateGenrate(name,file_from,Hash,projectname="NAN",matic="0"):
2024-04-27 09:33:09 +00:00
main = Certificate.objects.filter(user_name="MyNextFilm")
2024-08-08 11:07:22 +00:00
matic = int(matic)
matic = matic/10**18
2024-04-27 09:33:09 +00:00
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,
2024-05-11 10:33:37 +00:00
"id": ids,
2024-08-08 11:07:22 +00:00
'Matic':"{:.4f}".format(matic),
2024-05-11 10:33:37 +00:00
'File_name':projectname,
2024-08-08 11:07:22 +00:00
"basepath":basepath,
2024-04-27 09:33:09 +00:00
}
template = get_template(
f'{basepath}/lpp/templates/lpp/blockchainCertificate.html')
html = template.render(context)
options = {
'page-size': 'A4',
'zoom': 12.5,
2024-04-27 09:33:09 +00:00
'margin-top': '0.0in',
'margin-right': '0.0in',
'margin-bottom': '0.0in',
'margin-left': '0.0in',
2024-08-08 11:07:22 +00:00
'enable-local-file-access': '',
'orientation': 'Landscape',
'page-height': '11in',
2024-04-27 09:33:09 +00:00
}
pdfkit.from_string(
2024-08-08 11:07:22 +00:00
html, f'{basepath}/lpp/certificate/certificate.pdf', options=options)
2024-04-27 09:33:09 +00:00
return f'{basepath}/lpp/certificate/certificate.pdf'
# certificateGenrate("pravesh yadav","PPT Conversiom", "qwefgfdsdfgdsdcvxs")