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): def task_assigner(taskid, source):
x = LPPTASKDatabase.objects.get(task_id=taskid) x = LPPTASKDatabase.objects.get(task_id=taskid)
#Sending Alert to user about his request for vetting #Sending Alert to user about his request for vetting
to = x.user_id.email # if x.status == ""
key_value = { # to = x.user_id.email
"User": x.user_id.username, # key_value = {
} # "User": x.user_id.username,
sendmail(to_email=[to], email_code="PP1", key_value=key_value) # }
# sendmail(to_email=[to], email_code="PP1", key_value=key_value)
# Subtitling # Subtitling
@ -2311,16 +2312,19 @@ def task_assigner(taskid, source):
and x.translated_script.dial_dest_script in i.scripts and x.translated_script.dial_dest_script in i.scripts
): ):
if count < 3: if count < 3:
x.possiblelpp_dialogue.add(i) if x.assignedlpp_action == i:
# x.date_task_assigned = datetime.now() pass
count += 1 else:
# Send mail to assigned LPP x.possiblelpp_dialogue.add(i)
# x.date_task_assigned = datetime.now()
count += 1
# Send mail to assigned LPP
to = i.lpp_email to = i.lpp_email
key_value = { key_value = {
"User": i.user_id.username, "User": i.user_id.username,
} }
sendmail(to_email=[to], email_code="PP2", key_value=key_value) sendmail(to_email=[to], email_code="PP2", key_value=key_value)
# with open(rf"{basepath}/lpp/templates/lpp/body.txt") as f: # with open(rf"{basepath}/lpp/templates/lpp/body.txt") as f:
# body = f.read() # body = f.read()
@ -2359,78 +2363,134 @@ def task_assigner(taskid, source):
except: except:
pass pass
x.save() x.save()
convert_to_pdf(str(basepath) + "/media/" + str(x.outputfile), # convert_to_pdf(str(basepath) + "/media/" + str(x.outputfile),
str(basepath) + "/media/" + "lpptaskfolder") # str(basepath) + "/media/" + "lpptaskfolder")
pathspecific = "" # pathspecific = ""
for i in (str(x.outputfile).split('.'))[:-1]: # for i in (str(x.outputfile).split('.'))[:-1]:
pathspecific = pathspecific + "." + str(i) # pathspecific = pathspecific + "." + str(i)
saveFile = pathspecific[1:] + ".pdf" # saveFile = pathspecific[1:] + ".pdf"
x.outputfile.name = saveFile # x.outputfile.name = saveFile
x.save() # x.save()
# Blockchain
"""Blockchain Upload Starts here"""
# sys.stdout = original_stdout
scriptconversion = {}
try: try:
temp1 = str(x.translated_script.script_link_id.script_title) print("trying blockchain 1")
temp2 = str(x.outputfile) current_datetime = datetime.now()
uploaded_script = f"{basepath}/media/{temp1}" if UserCredentialsForBlockchain.objects.filter(user=x.user_id).exists():
translated_script = f"{basepath}/media/{temp2}" 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_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] if obj.converted_audit_id:
print("Function 11") print("audit blockchain")
files, timestamp = upload_multiFile_to_ipfs( print("blockchain script conversion 5.1")
data, str(x.translated_script.script_link_id.script_title).split("/")[-1], "convertScript", x.translated_script.user_id.email) # blockchain upload of csv-json data
x.translated_script.timestamp = timestamp adit_id = obj.converted_audit_id
x.translated_script.uploaded_script_encoded = files[0]
x.translated_script.translated_script_encoded = files[1]
x.save()
# blockchain here file_to_audit = File.objects.get(
if UserCredentialsForBlockchain.objects.filter(user_id=x.user_id).exists(): script=adit_id,
print("condition>>>>>>>>>>>>>>>>>>condition run") type="script-csv"
blockchain_obj = UserCredentialsForBlockchain.objects.get(user_id=x.user_id) )
privatekey = blockchain_obj.privateKey csv_script_path = file_to_audit.file.path
print(privatekey) df = pd.read_csv(csv_script_path)
# user_id =blockchain_obj.user_id df = df.loc[:, ["content", "script_element"]]
# Project = x.translated_ppt.ppt_id script_json: dict = json.loads(utilities.csv_to_json(df))
# private_Key = decryptionOfPrivate(privatekey) with tempfile.TemporaryDirectory() as temp_dir:
# status,getData = getPPTConversion(private_Key.decode('utf-8'),user_id,str(Project)) print("Temporary directory created:", temp_dir)
# if status == True: temp_filename = os.path.join(temp_dir, 'script_json_file.json')
# data1 = getData[1] print(temp_filename)
# pptconversion1 = eval(data1) with open(temp_filename, 'w') as json_file:
# temp2 = str(x.outputfile) json.dump(script_json, json_file, indent=4)
# translated_ppt = f"{basepath}/media/{temp2}" script_json = {}
# with open(translated_ppt, 'rb') as _file: script_path1 = temp_filename
# hash = uploadDataToIPFSNode(_file) # script_size = file_to_audit_docx.file.size
# pptconversion1["vetted_file_hash"] = hash with open(script_path1, 'rb') as _file:
# pptconversion1["vetted_file_path"] = translated_ppt hash2 = uploadDataToIPFSNode(_file)
# pptconversion1["vetted_file"] = temp2 script_json["script_file_path"] = script_path1
# Data = str(pptconversion1) script_json["script_file"] = hash2
# response=UploadPPTConversionData(private_Key.decode('utf-8'),user_id, str(Project),Data) script_json["type"] = "script-json"
# print("Response_final :",response) scriptconversion["script-json"] = script_json
except: print("blockchain script conversion 5.2")
pass
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: if x.assignedlpp_dialogue:
# create a docx # create a docx
@ -2490,22 +2550,22 @@ def task_assigner(taskid, source):
rupees_amount = float( rupees_amount = float(
Decimal(x.amoutgiventolpp_dialogue)) * usd_inr_rate Decimal(x.amoutgiventolpp_dialogue)) * usd_inr_rate
try: # try:
central_wallet = Wallet.objects.get(user=lpp.user_id) # central_wallet = Wallet.objects.get(user=lpp.user_id)
central_wallet.balance = float( # central_wallet.balance = float(
central_wallet.balance) + float(rupees_amount) # central_wallet.balance) + float(rupees_amount)
central_wallet.lpp_balance = float( # central_wallet.lpp_balance = float(
central_wallet.lpp_balance) + float(rupees_amount) # central_wallet.lpp_balance) + float(rupees_amount)
central_wallet.save() # central_wallet.save()
except Exception as e: # except Exception as e:
print("Error: ", e) # print("Error: ", e)
central_wallet = Wallet() # central_wallet = Wallet()
central_wallet.id = int( # central_wallet.id = int(
Wallet.objects.all().last().id) + 1 # Wallet.objects.all().last().id) + 1
central_wallet.user = lpp.user_id # central_wallet.user = lpp.user_id
central_wallet.balance = 0.0 + float(rupees_amount) # central_wallet.balance = 0.0 + float(rupees_amount)
central_wallet.lpp_balance = 0.0 + float(rupees_amount) # central_wallet.lpp_balance = 0.0 + float(rupees_amount)
central_wallet.save() # central_wallet.save()
# from .utils import render_to_pdf # from .utils import render_to_pdf
if x.assignedlpp_dialogue.accountno: if x.assignedlpp_dialogue.accountno:
@ -2546,15 +2606,28 @@ def task_assigner(taskid, source):
'margin-bottom': '0.0in', 'margin-bottom': '0.0in',
'margin-left': '0.0in', 'margin-left': '0.0in',
} }
if domain == "mynextfilm.ai": if domain == "app.mynextfilm.ai":
options["enable-local-file-access"] = "" options["enable-local-file-access"] = ""
elif domain == "1.6.141.104": elif domain == "1.6.141.104":
options["enable-local-file-access"] = "" options["enable-local-file-access"] = ""
if not os.path.exists(f'{basepath}/media/lpp_invoice'): if not os.path.exists(f'{basepath}/media/lpp_invoice'):
os.makedirs(f'{basepath}/media/lpp_invoice', mode=0o777) os.makedirs(f'{basepath}/media/lpp_invoice', mode=0o777)
pdfkit.from_string( try:
html, f'{basepath}/media/lpp_invoice/{doc_fname}_Invoice.pdf', options=options, verbose=True) 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!" # subject = "A task has been assigned to you!"
# from_email = settings.EMAIL_HOST_USER # from_email = settings.EMAIL_HOST_USER
@ -2826,13 +2899,14 @@ def task_assigner(taskid, source):
else: else:
pass pass
x.save() x.save()
return True return True
# send mail to LPP that a task is assigned # send mail to LPP that a task is assigned
def reassign_task(taskid, forwhichlines, fromeleigible): def reassign_task(taskid, forwhichlines, fromeleigible):
x = LPPTASKDatabase.objects.get(task_id=taskid) x = LPPTASKDatabase.objects.get(task_id=taskid)
# x.ratingonmachinetranslation = 0 # x.ratingonmachinetranslation = 0