lpp views updated with counter views

This commit is contained in:
Ubuntu 2024-08-21 11:12:55 +00:00
parent a2a64bac87
commit f37ffa1742
1 changed files with 176 additions and 102 deletions

View File

@ -1724,11 +1724,12 @@ def Table1(request):
def task_assigner(taskid, source):
x = LPPTASKDatabase.objects.get(task_id=taskid)
#Sending Alert to user about his request for vetting
to = x.user_id.email
key_value = {
"User": x.user_id.username,
}
sendmail(to_email=[to], email_code="PP1", key_value=key_value)
# if x.status == ""
# to = x.user_id.email
# key_value = {
# "User": x.user_id.username,
# }
# sendmail(to_email=[to], email_code="PP1", key_value=key_value)
# Subtitling
@ -2311,6 +2312,9 @@ def task_assigner(taskid, source):
and x.translated_script.dial_dest_script in i.scripts
):
if count < 3:
if x.assignedlpp_action == i:
pass
else:
x.possiblelpp_dialogue.add(i)
# x.date_task_assigned = datetime.now()
count += 1
@ -2359,78 +2363,134 @@ def task_assigner(taskid, source):
except:
pass
x.save()
convert_to_pdf(str(basepath) + "/media/" + str(x.outputfile),
str(basepath) + "/media/" + "lpptaskfolder")
pathspecific = ""
for i in (str(x.outputfile).split('.'))[:-1]:
pathspecific = pathspecific + "." + str(i)
saveFile = pathspecific[1:] + ".pdf"
x.outputfile.name = saveFile
x.save()
# convert_to_pdf(str(basepath) + "/media/" + str(x.outputfile),
# str(basepath) + "/media/" + "lpptaskfolder")
# pathspecific = ""
# for i in (str(x.outputfile).split('.'))[:-1]:
# pathspecific = pathspecific + "." + str(i)
# saveFile = pathspecific[1:] + ".pdf"
# x.outputfile.name = saveFile
# x.save()
# Blockchain
"""Blockchain Upload Starts here"""
# sys.stdout = original_stdout
scriptconversion = {}
try:
temp1 = str(x.translated_script.script_link_id.script_title)
print("trying blockchain 1")
current_datetime = datetime.now()
if UserCredentialsForBlockchain.objects.filter(user=x.user_id).exists():
obj = x.translated_script
obj2 = x.translated_script.script_link_id
temp1 = str(obj2.script.name)
temp2 = str(x.outputfile)
uploaded_script = f"{basepath}/media/{temp1}"
translated_script = f"{basepath}/media/{temp2}"
translated_scripttt = f"{basepath}/media/{temp2}"
print("blockchain script conversion 3", uploaded_script, translated_scripttt)
with open(uploaded_script, 'rb') as f:
hash = uploadDataToIPFSNode(f)
scriptconversion["original_scriptFile_hash"] = hash
scriptconversion["original_scriptFile_path"] = uploaded_script
scriptconversion["date_at"] = current_datetime.strftime("%Y-%m-%d %H:%M:%S")
print("blockchain script conversion 4")
with open(translated_scripttt, 'rb') as f1:
hash = uploadDataToIPFSNode(f1)
scriptconversion["translated_scriptFile_hash"] = hash
scriptconversion["translated_scriptFile_path"] = translated_scripttt
print("blockchain script conversion 5")
data = [uploaded_script, translated_script]
print("Function 11")
files, timestamp = upload_multiFile_to_ipfs(
data, str(x.translated_script.script_link_id.script_title).split("/")[-1], "convertScript", x.translated_script.user_id.email)
x.translated_script.timestamp = timestamp
x.translated_script.uploaded_script_encoded = files[0]
x.translated_script.translated_script_encoded = files[1]
x.save()
if obj.converted_audit_id:
print("audit blockchain")
print("blockchain script conversion 5.1")
# blockchain upload of csv-json data
adit_id = obj.converted_audit_id
# blockchain here
if UserCredentialsForBlockchain.objects.filter(user_id=x.user_id).exists():
print("condition>>>>>>>>>>>>>>>>>>condition run")
blockchain_obj = UserCredentialsForBlockchain.objects.get(user_id=x.user_id)
privatekey = blockchain_obj.privateKey
print(privatekey)
# user_id =blockchain_obj.user_id
# Project = x.translated_ppt.ppt_id
# private_Key = decryptionOfPrivate(privatekey)
# status,getData = getPPTConversion(private_Key.decode('utf-8'),user_id,str(Project))
# if status == True:
# data1 = getData[1]
# pptconversion1 = eval(data1)
# temp2 = str(x.outputfile)
# translated_ppt = f"{basepath}/media/{temp2}"
# with open(translated_ppt, 'rb') as _file:
# hash = uploadDataToIPFSNode(_file)
# pptconversion1["vetted_file_hash"] = hash
# pptconversion1["vetted_file_path"] = translated_ppt
# pptconversion1["vetted_file"] = temp2
# Data = str(pptconversion1)
# response=UploadPPTConversionData(private_Key.decode('utf-8'),user_id, str(Project),Data)
# print("Response_final :",response)
file_to_audit = File.objects.get(
script=adit_id,
type="script-csv"
)
csv_script_path = file_to_audit.file.path
df = pd.read_csv(csv_script_path)
df = df.loc[:, ["content", "script_element"]]
script_json: dict = json.loads(utilities.csv_to_json(df))
with tempfile.TemporaryDirectory() as temp_dir:
print("Temporary directory created:", temp_dir)
temp_filename = os.path.join(temp_dir, 'script_json_file.json')
print(temp_filename)
with open(temp_filename, 'w') as json_file:
json.dump(script_json, json_file, indent=4)
script_json = {}
script_path1 = temp_filename
# script_size = file_to_audit_docx.file.size
with open(script_path1, 'rb') as _file:
hash2 = uploadDataToIPFSNode(_file)
script_json["script_file_path"] = script_path1
script_json["script_file"] = hash2
script_json["type"] = "script-json"
scriptconversion["script-json"] = script_json
print("blockchain script conversion 5.2")
blockchain_obj = UserCredentialsForBlockchain.objects.get(user=x.user_id)
UserId = blockchain_obj.user_id
Project = obj.translation_id
Data = str(scriptconversion)
userPrivateKey = blockchain_obj.privateKey
userkey = decryptionOfPrivate(userPrivateKey)
tx_id, tx_gas_fee = UploadConversionData(OWNER_KEY, blockchain_obj.publicKey, UserId,
str(Project),
Data)
# x.translated_script.blockchain_txhash = tx_id
try:
objectt = ScriptTranslations.objects.get(translation_id=x.translated_script.translation_id)
objectt.blockchain_txhash = tx_id
objectt.save()
except:
pass
print("Tx id -> ", tx_id, tx_gas_fee)
# user_infos = user_info(tx_hash=tx_id, service="Conversion", gas_fee=2345432345123456)
# addition_result = user_infos.update_info(request)
name_script = (((uploaded_script.split("/"))[-1]).split("."))[0]
try:
user_infos = user_info(tx_hash=tx_id, service="Conversion", gas_fee=tx_gas_fee,
script_name=name_script)
request = Request(x.user_id)
addition_result = user_infos.update_info(request)
print("Blockchain Result -> ", addition_result)
except Exception as e:
print("Error in blockchain is:", e)
print("blockchain script conversion 6")
certificatepath = certificateGenrate(x.user_id.username, "script conversion", hash)
hash = hash_decrypation(hash)
to_email = [x.user_id.email]
email_code = 'BL1'
key_value = {
"service": "script conversion",
"hash": hash,
"public key": blockchain_obj.publicKey,
"private key": userkey.decode('utf-8'),
"Transaction Hash": tx_id
}
sendmail(to_email=to_email, email_code=email_code, key_value=key_value,
filePath=certificatepath)
import boto3
s3_client = boto3.client('s3',
aws_access_key_id="AKIAQVLBBGCB45RMLKVW",
aws_secret_access_key="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",
region_name="ap-south-1"
)
bucket = "conversion-kitchen"
file_name = str(((x.translated_script.translated_script_pdf).split("OUTPUT/"))[1])
object_key = "OUTPUT/" + file_name
s3_client.delete_object(Bucket=bucket, Key=object_key)
except Exception as e:
print("Error in blockchain is", e)
"""Blockchain Upload Ends here"""
# -> Generating Invoice
# invoice_values = {
# "pdf_name": f'{((str(x.translated_script.script).split("/"))[-1]).split(".")[0]}_Invoice.pdf',
# "lpp_name": f'{x.assignedlpp_action.first_name} {x.assignedlpp_action.last_name}',
# "lpp_contact": x.assignedlpp_action.contact,
# "source_lang": x.translated_script.dial_src_language,
# "target_lang": x.translated_script.dial_dest_language,
# "source_script": x.translated_script.dial_src_script,
# "target_script": x.translated_script.dial_dest_script,
# "date_of_assign": x.date_task_assigned,
# "duration": duration,
# "task_id": x.task_id,
# "file_name": x.translated_script.script_title,
# "type_of_work": "Only Dialogues Script Vetting",
# "task_origin": "Conversion",
# "amount": amount,
#
# }
#
#
# Invoice = Invoice_Generator(invoice_values)
# Invoice.generate_invoice()
if x.assignedlpp_dialogue:
# create a docx
@ -2490,22 +2550,22 @@ def task_assigner(taskid, source):
rupees_amount = float(
Decimal(x.amoutgiventolpp_dialogue)) * usd_inr_rate
try:
central_wallet = Wallet.objects.get(user=lpp.user_id)
central_wallet.balance = float(
central_wallet.balance) + float(rupees_amount)
central_wallet.lpp_balance = float(
central_wallet.lpp_balance) + float(rupees_amount)
central_wallet.save()
except Exception as e:
print("Error: ", e)
central_wallet = Wallet()
central_wallet.id = int(
Wallet.objects.all().last().id) + 1
central_wallet.user = lpp.user_id
central_wallet.balance = 0.0 + float(rupees_amount)
central_wallet.lpp_balance = 0.0 + float(rupees_amount)
central_wallet.save()
# try:
# central_wallet = Wallet.objects.get(user=lpp.user_id)
# central_wallet.balance = float(
# central_wallet.balance) + float(rupees_amount)
# central_wallet.lpp_balance = float(
# central_wallet.lpp_balance) + float(rupees_amount)
# central_wallet.save()
# except Exception as e:
# print("Error: ", e)
# central_wallet = Wallet()
# central_wallet.id = int(
# Wallet.objects.all().last().id) + 1
# central_wallet.user = lpp.user_id
# central_wallet.balance = 0.0 + float(rupees_amount)
# central_wallet.lpp_balance = 0.0 + float(rupees_amount)
# central_wallet.save()
# from .utils import render_to_pdf
if x.assignedlpp_dialogue.accountno:
@ -2546,16 +2606,29 @@ def task_assigner(taskid, source):
'margin-bottom': '0.0in',
'margin-left': '0.0in',
}
if domain == "mynextfilm.ai":
if domain == "app.mynextfilm.ai":
options["enable-local-file-access"] = ""
elif domain == "1.6.141.104":
options["enable-local-file-access"] = ""
if not os.path.exists(f'{basepath}/media/lpp_invoice'):
os.makedirs(f'{basepath}/media/lpp_invoice', mode=0o777)
pdfkit.from_string(
html, f'{basepath}/media/lpp_invoice/{doc_fname}_Invoice.pdf', options=options, verbose=True)
try:
pdfkit.from_string(html, f'{basepath}/media/lpp_invoice/{doc_fname}_Invoice.pdf',
options=options, verbose=True)
except:
config = pdfkit.configuration(wkhtmltopdf='/bin/wkhtmltopdf')
pdfkit.from_string(html, f'{basepath}/media/lpp_invoice/{doc_fname}_Invoice.pdf',
options=options, verbose=True, configuration=config)
to = x.translated_script.user_id.email
key_value = {
"User": x.translated_script.user_id.username,
"title": x.translated_script.script_link_id.script_title
}
sendmail(to_email=[to], email_code="PP18", key_value=key_value)
# subject = "A task has been assigned to you!"
# from_email = settings.EMAIL_HOST_USER
@ -2833,6 +2906,7 @@ def task_assigner(taskid, source):
def reassign_task(taskid, forwhichlines, fromeleigible):
x = LPPTASKDatabase.objects.get(task_id=taskid)
# x.ratingonmachinetranslation = 0