1070 lines
41 KiB
Python
Executable File
1070 lines
41 KiB
Python
Executable File
import re
|
|
from mnfapp.models import MNFScriptDatabase
|
|
from mnfapp.models import SampleScript, PaymentData
|
|
|
|
# from mnfapp.views import PaymentDetails
|
|
#from scriptAudit.script_audit_codes.script_audit import do_script_audit
|
|
#from neutralAudit.mnf_script_audit_v8 import call_script_audit_for_conversion
|
|
#from neutralAudit.views import audit1
|
|
from payment.models import conversionPayment, privilegedUser1
|
|
from forex_python.converter import CurrencyRates
|
|
from mnfapp.models import *
|
|
from users.models import *
|
|
import stripe
|
|
from django.shortcuts import redirect
|
|
from PyPDF2 import PdfFileReader
|
|
from .forms import CScript
|
|
from .models import UploadScript,StoryConversion
|
|
from MNF.settings import BasePath
|
|
import subprocess
|
|
from django.shortcuts import render
|
|
from django.contrib.auth.decorators import login_required
|
|
from .detection import getInputs
|
|
import random
|
|
from subprocess import Popen
|
|
|
|
# from conversion.translation import final_translation
|
|
from conversion.translation.twostepconversion import translate_function
|
|
from mnfapp.models import MNFScriptDatabase, Notifications
|
|
#from page_script.models import MNFScriptDatabase_2,Conversions, Conversion_link
|
|
from django.contrib.auth.decorators import login_required
|
|
from pymongo import MongoClient
|
|
from django.core.mail import EmailMessage
|
|
from django.conf import settings
|
|
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
|
|
from pathlib import Path
|
|
from django.core.files.storage import FileSystemStorage
|
|
from django.core.mail import EmailMultiAlternatives
|
|
from django.template.loader import render_to_string
|
|
from django.utils.html import strip_tags
|
|
import os
|
|
import datetime
|
|
import razorpay
|
|
from pytz import timezone
|
|
from django.contrib.auth.models import User
|
|
from lpp.models import LPPTASKDatabase
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
from lpp.views import task_assigner
|
|
from .storytranslator.trans import convert_story
|
|
# Create your views here.
|
|
# Create your views here.
|
|
basePath = BasePath()
|
|
# Create your views here.
|
|
#
|
|
|
|
|
|
# This is your real test secret API key.
|
|
# stripe.api_key = "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"
|
|
# stripe.api_key = "sk_test_51JT8ahSF9vzGWnggJT1M69LDT0Q8tCqvHzuWd9Fih5YO2guIpMpUd58swbDrJYocpQZAn3nY8k3Ymyw8QZ8dLeEF00VxfBmMWI"
|
|
stripe.api_key = settings.STRIPE_SECRET_KEY
|
|
# STRIPE_PUB_KEY ="pk_test_51JT8ahSF9vzGWngg9ik0jueTIilHhCQomixBFOiNzCuo4Wwc5oRm73d05vdcboMgNwhyNcNTa2si8idqbB5msvwe006q3S96tM"
|
|
# STRIPE_PUB_KEY ="pk_live_51JT8ahSF9vzGWngg4N8fwhTPk5jq8fqBFdokqSMe7AVaOvH6BdyTwAfAoY79qkeJTFA0OdT5qkAk2FCNWCu6W9l000STNnHa7H"
|
|
STRIPE_PUB_KEY = settings.STRIPE_PUBLISHABLE_KEY
|
|
keyID = settings.RAZORPAY_KEY_ID
|
|
keySecret = settings.RAZORPAY_KEY_SECRET
|
|
languages = {
|
|
"hi": "Hindi",
|
|
"en": "English",
|
|
"ur": "Urdu",
|
|
"ar": "Arabic",
|
|
"bn": "Bengali",
|
|
"kn": "Kannada",
|
|
"ta": "Tamil",
|
|
"bg": "Bulgarian",
|
|
"bn": "Bengali",
|
|
"ml": "Malayalam",
|
|
"ru": "Russian",
|
|
"sr": "Serbian",
|
|
"uk": "Ukranian",
|
|
"hr": "Croatian",
|
|
"ga": "Irish",
|
|
"sq": "Albanian",
|
|
"mr": "Marathi",
|
|
"fa": "Persian",
|
|
"te": "Telugu",
|
|
"tr": "Turkish",
|
|
"hu": "Hungarian",
|
|
"it": "Italian",
|
|
"ro": "Romanian",
|
|
"pa": "Punjabi",
|
|
"gu": "Gujarati",
|
|
"or": "Oriya",
|
|
"zh-CN": "Chinese-Simplified",
|
|
"zh-TW": "Chinese-Traditional",
|
|
"ne": "Nepali",
|
|
"fr": "French",
|
|
"es": "Spanish",
|
|
"id": "Indonesian",
|
|
"el": "Greek",
|
|
"ja": "Japanese",
|
|
"jv": "Javanese",
|
|
"ko": "Korean",
|
|
"be": "Belarusian",
|
|
"uz": "Uzbek",
|
|
"sd": "Sindhi",
|
|
"af": "Afrikaans",
|
|
"de": "German",
|
|
"is": "Icelandic",
|
|
"ig": "Igbo",
|
|
"la": "Latin",
|
|
"pt": "Portugese",
|
|
"my": "Myanmar",
|
|
"th": "Thai",
|
|
"su": "Sundanese",
|
|
"lo": "Lao",
|
|
"am": "amharic",
|
|
"si": "Sinhala",
|
|
"az": "Azerbaijani",
|
|
"kk": "Kazakh",
|
|
"mk": "Macedonian",
|
|
"bs": "Bosnian",
|
|
"ps": "Pashto",
|
|
"mg": "Malagasy",
|
|
"ms": "Malay",
|
|
"yo": "Yoruba",
|
|
"cs": "Czech",
|
|
"da": "Danish",
|
|
"nl": "Dutch",
|
|
"tl": "Tagalog",
|
|
"no": "Norwegian",
|
|
"sl": "Slovenian",
|
|
"sv": " Swedish",
|
|
"vi": "Vietnamese",
|
|
"cy": "Welsh",
|
|
"he": "Hebrew",
|
|
"hy": "Armenian",
|
|
"km": "Khmer",
|
|
"ka": "Georgian",
|
|
"mn": "Mongolian",
|
|
"ku": "Kurdish",
|
|
"ky": "Kyrgyz",
|
|
"tk": "Turkmen",
|
|
"fi": "Finnish",
|
|
"ht": "Haitian Creole",
|
|
"haw": "Hawaiian",
|
|
"lt": "Lithuanian",
|
|
"lb": "Luxembourgish",
|
|
"mt": "Maltese",
|
|
"pl": "Polish",
|
|
"eo": "Esperanto",
|
|
"tt": "Tatar",
|
|
"ug": "Uyghur",
|
|
"ha": "Hausa",
|
|
"so": "Somali",
|
|
"sw": "Swahili",
|
|
"yi": "Yiddish",
|
|
"eu": "Basque",
|
|
"ca": "Catalan",
|
|
"ceb": "Cebuano",
|
|
"co": "Corsican",
|
|
"et": "Estonian",
|
|
"fy": "Frisian",
|
|
"gl": "Galician",
|
|
"hmn": "Hmong",
|
|
"rw": "Kinyarwanda",
|
|
"lv": "Latvian",
|
|
"mi": "Maori",
|
|
"sm": "Samoan",
|
|
"gd": "Scots Gaelic",
|
|
"st": "Sesotho",
|
|
"sn": "Shona",
|
|
"sk": "Slovak",
|
|
"xh": "Xhosa",
|
|
"zu": "Zulu",
|
|
}
|
|
|
|
|
|
def convert_to_pdf(input_docx, out_folder):
|
|
p = subprocess.Popen(
|
|
[
|
|
"libreoffice",
|
|
"--headless",
|
|
"--convert-to",
|
|
"pdf",
|
|
"--outdir",
|
|
out_folder,
|
|
input_docx,
|
|
]
|
|
)
|
|
print(["--convert-to", "pdf", input_docx])
|
|
p.communicate()
|
|
|
|
|
|
def countPages(docfile, pdfname):
|
|
convert_to_pdf(docfile, rf"{basePath}/media/PdfFiles/")
|
|
|
|
pdf = PdfFileReader(open(rf"{basePath}/media/PdfFiles/{pdfname}", "rb"))
|
|
number_of_pages = pdf.getNumPages()
|
|
return number_of_pages
|
|
|
|
|
|
def conversion(request):
|
|
print("************************************777777777777777777777888888888888888888889999999999999999999---------------")
|
|
print("Entered ConversionFunction")
|
|
number = ReferUser.objects.filter(reffered_by=request.user).count()
|
|
# print(funcname)
|
|
M = MNFScriptDatabase()
|
|
|
|
sampleList = SampleScript.objects.all()
|
|
MyURL = ""
|
|
dial_src_script = ""
|
|
dial_src_lang = ""
|
|
non_dial_src_lang = ""
|
|
non_dial_src_script = ""
|
|
script_title = ""
|
|
author_name = ""
|
|
numPages = 0
|
|
option3 = ""
|
|
option4 = ""
|
|
option5 = ""
|
|
option6 = ""
|
|
context = {}
|
|
UScript = CScript()
|
|
id = ""
|
|
x = datetime.datetime.now(timezone("UTC")).astimezone(timezone("Asia/Kolkata"))
|
|
# print("MY base path is " ,str(BASE_DIR))
|
|
UploadedScript = UploadScript()
|
|
if request.method == "POST":
|
|
# y = Conversion_link()
|
|
M.script = request.FILES["script"]
|
|
M.save()
|
|
MyURL = M.script.url
|
|
print("***************************-----------------------urlllllllll-------------------**************")
|
|
print(MyURL)
|
|
# UScript = CScript(request.POST, request.FILES)
|
|
# if UScript.is_valid():
|
|
# UploadedScript.script = UScript.cleaned_data.get("script")
|
|
# MyURL = UploadedScript.script.url
|
|
print(MyURL)
|
|
# UploadedScript.save()
|
|
# script_title = MyURL[7:-5] + str(x.strftime("%d"))+ "_"+ str(x.strftime("%b"))+ "_"+ str(x.strftime("%H"))+ str(x.strftime("%I"))
|
|
author_name = str(request.user.username)
|
|
script_title = M.script.name
|
|
# script_title = script_title[8:]
|
|
# auditedfilepath_docx,auditedfilepath_pdf = call_script_audit_for_conversion(basePath+"/media/scripts/",script_title.split('/')[-1])
|
|
# anf = audit1(request)
|
|
# M.audited_script_path_docx = auditedfilepath_docx
|
|
|
|
|
|
|
|
|
|
|
|
if script_title[-3:] == "pdf":
|
|
print(do_script_audit(basePath + MyURL, "1234", "scripts"))
|
|
pdf = PdfFileReader(open(rf"{basePath}/{MyURL}", "rb"))
|
|
numPages = pdf.getNumPages()
|
|
# MyURL = MyURL[:-3]+"docx"
|
|
else:
|
|
numPages = countPages(
|
|
str(BASE_DIR)+"/media/" + script_title, script_title[8:-4]+"pdf")
|
|
|
|
MyURL = MyURL.replace(".pdf", ".docx")
|
|
|
|
formInput = getInputs(str(BASE_DIR) + MyURL)
|
|
dial_src_script = formInput[2]
|
|
dial_src_lang = formInput[1]
|
|
non_dial_src_lang = formInput[0]
|
|
non_dial_src_script = formInput[3]
|
|
option3 = formInput[4]
|
|
option4 = formInput[5]
|
|
option5 = formInput[6]
|
|
option6 = formInput[7]
|
|
print("The Data of formInput is:",formInput)
|
|
print("done")
|
|
print("*********************-----------------------**********************")
|
|
print(M.id)
|
|
context = {
|
|
'id': M.id,
|
|
'numPages': numPages,
|
|
'fileName': MyURL,
|
|
'non_dial_src_script': non_dial_src_script,
|
|
'author_name': author_name,
|
|
'script_title': script_title,
|
|
'UScript': UScript,
|
|
'dial_src_script': dial_src_script,
|
|
'dial_src_lang': dial_src_lang,
|
|
'dial_src_lang_full': languages.get(dial_src_lang),
|
|
'non_dial_src_lang_full': languages.get(non_dial_src_lang),
|
|
'non_dial_src_lang': non_dial_src_lang,
|
|
'list': sampleList,
|
|
'option3': option3,
|
|
'option4': option4,
|
|
'option5': option5,
|
|
'option6': option6
|
|
}
|
|
|
|
return render(request, 'conversion/conversion.html', context)
|
|
return render(request, 'conversion/conversion.html', {'list': sampleList})
|
|
|
|
# numPages = countPages(str(auditedfilepath_pdf))
|
|
# pdf = PdfFileReader(open(rf"{auditedfilepath_pdf}", "rb"))
|
|
# pdf = PdfFileReader(open(rf"{basePath}/{MyURL}", "rb"))
|
|
|
|
# numPages = pdf.getNumPages()
|
|
# MyURL = MyURL.replace(".pdf", ".docx")
|
|
# formInput = getInputs(str(BASE_DIR) + MyURL)
|
|
# formInput = getInputs(auditedfilepath_docx)
|
|
|
|
# dial_src_script = formInput[2]
|
|
# dial_src_lang = formInput[1]
|
|
# non_dial_src_lang = formInput[0]
|
|
# non_dial_src_script = formInput[3]
|
|
# option3 = formInput[4]
|
|
# option4 = formInput[5]
|
|
# option5 = formInput[6]
|
|
# option6 = formInput[7]
|
|
# print("The Data of formInput is:", formInput)
|
|
# print("done")
|
|
# context = {
|
|
# "id": M.id,
|
|
# "numPages": numPages,
|
|
# "fileName": MyURL,
|
|
# # "fileName":auditedfilepath_docx,
|
|
# "non_dial_src_script": non_dial_src_script,
|
|
# "author_name": author_name,
|
|
# "script_title": script_title,
|
|
# "UScript": UScript,
|
|
# "dial_src_script": dial_src_script,
|
|
# "dial_src_lang": dial_src_lang,
|
|
# "dial_src_lang_full": languages.get(dial_src_lang),
|
|
# "non_dial_src_lang_full": languages.get(non_dial_src_lang),
|
|
# "non_dial_src_lang": non_dial_src_lang,
|
|
# "list": sampleList,
|
|
# "option3": option3,
|
|
# "option4": option4,
|
|
# "option5": option5,
|
|
# "option6": option6,
|
|
# "number" : number,
|
|
|
|
# }
|
|
|
|
# return render(request, "conversion/conversion.html", context)
|
|
# return render(request, "conversion/conversion.html", {"list": sampleList,"number":number})
|
|
|
|
|
|
def is_converted(request):
|
|
script_id = request.GET["script_id"]
|
|
obj = MNFScriptDatabase.objects.get(script_id=script_id)
|
|
print("****************************---------------------------*****************************")
|
|
print(script_id)
|
|
print("obj.script convetred function", obj.translated_script_path)
|
|
if obj.translated_script_path:
|
|
return JsonResponse({"status": "success"}, status=200)
|
|
else:
|
|
return JsonResponse({"status": "pending"}, status=202)
|
|
|
|
|
|
def make_conversion(request):
|
|
print("********************************444444444444444444555555555555555556666666666666666666666----------------------")
|
|
print("MAke Conversion mein hu")
|
|
# print(funcname)
|
|
script_file_path = request.GET["script_file_path"]
|
|
|
|
str1 = str(script_file_path)
|
|
print(str1[41:45])
|
|
if str1[41:45] == "user":
|
|
script_file_path = "/home/" + str(str1[41:])
|
|
print(script_file_path)
|
|
script_id = request.GET["script_id"]
|
|
# script_id2 = request.GET["script_id2"]
|
|
dial_conv_script = request.GET["dial_conv_script"]
|
|
dial_src_lang = request.GET["dial_src_lang"]
|
|
print("from_ui_dial_src_lang", dial_src_lang)
|
|
non_dial_src_lang = request.GET["non_dial_src_lang"]
|
|
print("from_ui_non_dial_src_lang", non_dial_src_lang)
|
|
dial_src_script = request.GET["dial_src_script"]
|
|
restrict_to_five = request.GET["restrict_to_five"]
|
|
option3 = request.GET.get("option3")
|
|
option4 = request.GET.get("option4")
|
|
option5 = request.GET.get("option5")
|
|
option6 = request.GET.get("option6")
|
|
# script_name= request.GET['script_title']
|
|
# dual_dial = request.GET['dual_dial_script']
|
|
# dial_dest = request.GET['dial_dest_script']
|
|
print("Inside conversion function of views")
|
|
|
|
#MongoDBUrl = "mongodb+srv://MNF:root@cluster0.gbkxi.gcp.mongodb.net/DB?retryWrites=true&w=majority"
|
|
MongoDBUrl="mongodb+srv://mynextfilm:mnf123@cluster0.ojasb.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
|
|
global client, script_title, db
|
|
client = MongoClient(MongoDBUrl)
|
|
db = client.DB
|
|
# global client,script_title,db
|
|
# script_id = "scr_1612524497" # for testing and then we will pass it through cli
|
|
script_id = script_id
|
|
print("script_id", script_id)
|
|
user_script_data = db["mnfapp_mnfscriptdatabase"].find_one({"script_id": script_id})
|
|
print("user_script_data",user_script_data)
|
|
# filename1 = sys.argv[1]
|
|
|
|
script_title = user_script_data.get("script_title")
|
|
filename1 = script_file_path
|
|
print("Script File name ", filename1)
|
|
# dial_dest_lang = sys.argv[2]
|
|
dial_dest_lang = user_script_data.get("dial_dest_language")
|
|
print("selected_dialouge lanaguage ", dial_dest_lang)
|
|
# dial_dest_script = sys.argv[3]
|
|
dial_dest_script = user_script_data.get("dial_dest_script")
|
|
print("selected_dialouge script name", dial_dest_script)
|
|
# non_dial_dest_lang = sys.argv[4]
|
|
non_dial_dest_lang = user_script_data.get("nondial_dest_language")
|
|
print("selected_actionline language", non_dial_dest_lang)
|
|
# dual_dial_script = sys.argv[5]
|
|
dual_dial_script = user_script_data.get("dual_dial_script") # Yes,No
|
|
print(dual_dial_script)
|
|
print("Translation suru ho rha hai")
|
|
print(
|
|
"Yahan dekho",
|
|
script_file_path,
|
|
script_id,
|
|
dial_conv_script,
|
|
dial_src_lang,
|
|
non_dial_src_lang,
|
|
dial_src_script,
|
|
dial_src_script,
|
|
restrict_to_five,
|
|
)
|
|
print(
|
|
rf'translate_function("{script_file_path}", "{script_id}", "{dial_conv_script}", "{dial_src_lang}","{non_dial_src_lang}", "{dial_src_script}", "{restrict_to_five}", "{option3}", "{option4}", "{option5}", "{option6}")'
|
|
)
|
|
try:
|
|
# final_translation.translate_function(script_file_path, script_id, dial_conv_script, dial_src_lang,
|
|
# non_dial_src_lang, dial_src_script, restrict_to_five, option3, option4, option5, option6)
|
|
# translate_function(script_file_path, script_id, dial_conv_script, dial_src_lang,non_dial_src_lang, dial_src_script, restrict_to_five, option3, option4, option5, option6)
|
|
print("123455667788------------------------------------45644848484344345434843438--------------***************")
|
|
print(script_id)
|
|
filename = translate_function(
|
|
script_file_path,
|
|
script_id,
|
|
dial_src_lang,
|
|
non_dial_src_lang,
|
|
dial_src_script,
|
|
restrict_to_five,
|
|
option3,
|
|
option4,
|
|
option5,
|
|
option6
|
|
)
|
|
|
|
print(
|
|
"111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222244444444444444444444444444444444444444444444444444444411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
|
|
# print(script_id2)
|
|
# if script_id2 == "":
|
|
# print("4545")
|
|
# pass
|
|
# else:
|
|
# print("5454")
|
|
# print(MNFScriptDatabase_2.objects.get(script_id=str(script_id2)))
|
|
# print(Conversion_link.objects.filter(script_idd=MNFScriptDatabase_2.objects.get(script_id=str(script_id2))))
|
|
# if Conversion_link.objects.filter(
|
|
# script_idd=MNFScriptDatabase_2.objects.get(script_id=str(script_id2))).exists():
|
|
# y = Conversion_link.objects.filter(
|
|
# script_idd=MNFScriptDatabase_2.objects.get(script_id=str(script_id2)))
|
|
# else:
|
|
# print("412412")
|
|
# y = Conversion_link()
|
|
# y.script_idd = MNFScriptDatabase_2.objects.get(script_id=str(script_id2))
|
|
# y.save()
|
|
#
|
|
# z = Conversions()
|
|
#
|
|
# z.created_on = datetime.datetime.now()
|
|
#
|
|
# z.dial_src_language = dial_src_lang
|
|
#
|
|
# z.dial_dest_language = dial_dest_lang
|
|
#
|
|
# z.dial_dest_script = dial_dest_script
|
|
#
|
|
# z.nondial_dest_language = non_dial_dest_lang
|
|
#
|
|
# z.nondial_src_script = non_dial_src_lang
|
|
#
|
|
# z.dial_src_script = dial_src_script
|
|
#
|
|
# z.dual_dial_script = dual_dial_script
|
|
#
|
|
# z.translated_script_path = str(filename)
|
|
# print("10")
|
|
# z.save()
|
|
# print(
|
|
# "111111111111111111111111111111111111111dssdsqwertqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq44444444444444444444111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
|
|
#
|
|
# y.conversions.add(z)
|
|
|
|
print("see whats in script file path conversion", script_file_path)
|
|
if request.GET.get("to_be_vetted_by_lpp"):
|
|
print(3 * "###############")
|
|
obj = MNFScriptDatabase.objects.get(script_id=script_id)
|
|
X = LPPTASKDatabase()
|
|
X.user_id = obj.user_id
|
|
X.translated_file = obj.translated_script_path
|
|
X.taskname = obj.script_file_path.replace(basePath, "")
|
|
X.firstLanguage = languages[obj.dial_src_language]
|
|
X.secondLanguage = languages[obj.dial_dest_language]
|
|
X.usernote = "Kindly check if the translated file is correct as per the Uploaded Document!"
|
|
X.save()
|
|
task_assigner(int(X.id))
|
|
|
|
print("Script Translated successfully")
|
|
# context = {'status': "Success"}
|
|
user = request.user
|
|
subject = "Conversion Generated Successfully " + "."
|
|
from_email = settings.EMAIL_HOST_USER
|
|
to = request.user.email
|
|
print("user is", user)
|
|
print("from email", from_email)
|
|
print("to email", to)
|
|
print("script_name", script_title)
|
|
print("dialogue destination language", languages.get(dial_dest_lang))
|
|
print("non dialogue destination language", languages.get(non_dial_dest_lang))
|
|
print("non dialogue source script", languages.get(non_dial_src_lang))
|
|
response = redirect("narration").url
|
|
|
|
path = request.build_absolute_uri(response)
|
|
context = {
|
|
"Name": user,
|
|
"script_id": script_id,
|
|
"script_name": script_title,
|
|
"dual_dial": dual_dial_script,
|
|
"dial_src_lang": dial_src_script,
|
|
"dial_dest_lang": languages.get(dial_dest_lang),
|
|
"non_dial_dest_lang": languages.get(non_dial_dest_lang),
|
|
"non_dial_src_lang": languages.get(non_dial_src_lang),
|
|
"dial_dest_script": dial_dest_script,
|
|
"status": "Success",
|
|
"path": path,
|
|
}
|
|
html_content = render_to_string(
|
|
"conversion/email.html", context
|
|
) # render with dynamic value
|
|
print(html_content, "this is a html content ****************** ")
|
|
# Strip the html tag. So people can see the pure text at least.
|
|
text_content = strip_tags(html_content)
|
|
# create the email, and attach the HTML version as well.
|
|
print("email process started")
|
|
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
|
|
msg.attach_alternative(html_content, "text/html")
|
|
msg.send()
|
|
print("after mail has been sent my context is", context)
|
|
|
|
return JsonResponse(context, status=200)
|
|
except:
|
|
print(
|
|
"Script translation failed due to some internal error. If you have made any payment for conversion that will be refunded"
|
|
)
|
|
payment_intent_id = user_script_data.get("payment_intent_id")
|
|
print(
|
|
"translated script file path in except",
|
|
user_script_data.get("translated_script_path"),
|
|
)
|
|
obj = MNFScriptDatabase.objects.get(script_id=script_id)
|
|
print("obj.script convetred function", obj.translated_script_path)
|
|
|
|
# if obj.translated_script_path:
|
|
# print("Script Translated successfully")
|
|
# context = {'status': "Success"}
|
|
# user = request.user
|
|
# # email = user.email
|
|
# # message = "Hi " + str(user) + ",\nThe conversion for your script "+script_title + \
|
|
# # " is ready. You will find it in the My Conversions section of the MyNextFilm website. For any queries, feel free to reach us at support@mynextfilm.com.\nHappy Filming!\nMy Next Film"
|
|
# # email_message = EmailMessage(
|
|
# # "Conversion generated successfully", message, settings.EMAIL_HOST_USER, [email])
|
|
# # email_message.send()
|
|
# # var = Notifications(user_id=request.user, notification=str(
|
|
# # "Conversion generated successfully for "+script_title))
|
|
# # var.save()
|
|
|
|
# subject= "Conversion Generated Successfully "+ "."
|
|
# from_email = settings.EMAIL_HOST_USER
|
|
# to = user.email
|
|
# context = {
|
|
|
|
# 'Name': user,
|
|
# 'script_name':script_title,
|
|
# 'dual_dial':dual_dial_script,
|
|
# 'dial_dest':dial_dest_script,
|
|
# 'status': "Success",
|
|
|
|
# }
|
|
# html_content = render_to_string('conversion/email.html', context) # render with dynamic value
|
|
# # Strip the html tag. So people can see the pure text at least.
|
|
# text_content = strip_tags(html_content)
|
|
# # create the email, and attach the HTML version as well.
|
|
# print('email process started')
|
|
# msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
|
|
# msg.attach_alternative(html_content, "text/html")
|
|
# msg.send()
|
|
|
|
# return JsonResponse(context, status=200)
|
|
|
|
if payment_intent_id:
|
|
if payment_intent_id[0:4] == "pay":
|
|
client = razorpay.Client(auth=(keyID, keySecret))
|
|
payment_id = payment_intent_id
|
|
total_amount = request.POST.get("total_amount")
|
|
c = CurrencyRates()
|
|
rate = c.get_rate("USD", "INR")
|
|
payment_amount = int(float(total_amount) * 100 * rate)
|
|
resp = client.payment.refund(payment_id, payment_amount)
|
|
else:
|
|
stripe.Refund.create(payment_intent_id)
|
|
|
|
return JsonResponse({}, status=505)
|
|
|
|
|
|
@login_required
|
|
def view_conversion(request):
|
|
number = ReferUser.objects.filter(reffered_by=request.user).count()
|
|
obj = MNFScriptDatabase.objects.filter(user_id=request.user).order_by("-date_at")
|
|
|
|
script_path = []
|
|
pq = 0
|
|
for i in obj:
|
|
if i.translated_script_path != "":
|
|
script_path.append(i.translated_script_path)
|
|
pq += 1
|
|
|
|
print(script_path)
|
|
lenV = len(script_path)
|
|
print(len(script_path))
|
|
return render(
|
|
request, "conversion/stored_conversions.html", {"script_path": obj, "pq": pq, "number": number}
|
|
)
|
|
|
|
|
|
def delete_script(request, id):
|
|
MNFScriptDatabase.objects.get(id=id).delete()
|
|
return HttpResponseRedirect("/conversion/view_conversion")
|
|
|
|
|
|
def demo(request):
|
|
number = ReferUser.objects.filter(reffered_by=request.user).count()
|
|
return render(request, "conversion/demo.html", {"number":number})
|
|
|
|
|
|
def announce(request):
|
|
message = ""
|
|
user = User.objects.all()
|
|
cUser = request.user
|
|
if cUser.is_superuser == True:
|
|
if request.method == "POST":
|
|
notification = request.POST.get("message")
|
|
for i in user:
|
|
var = Notifications(user_id=i, notification=notification)
|
|
var.save()
|
|
messgae = "notification sent successfull."
|
|
return render(request, "conversion/announce.html", {"message": message})
|
|
else:
|
|
return render(request, "conversion/announce.html", {})
|
|
else:
|
|
message = " you need to be superuser"
|
|
return render(request, "conversion/announce.html", {"message": message})
|
|
|
|
|
|
def sampleConversion():
|
|
dict = {"id": 1, "title": "Deepika"}
|
|
|
|
|
|
def conversionCheckout(request):
|
|
# print(funcname)
|
|
if request.method == "POST":
|
|
if request.POST.get("want_to_be_vetted"):
|
|
total_amount = request.session["lppamount"]
|
|
else:
|
|
total_amount = request.session["amount"]
|
|
request.session["want_to_be_vetted"] = request.POST.get("want_to_be_vetted")
|
|
request.session["interested_to_be_lpp"] = request.POST.get(
|
|
"interested_to_be_lpp"
|
|
)
|
|
if request.POST.get("country") == "IN":
|
|
c = CurrencyRates()
|
|
rate = c.get_rate("USD", "INR")
|
|
amtINR = round(float(float(total_amount) * rate), 2)
|
|
client = razorpay.Client(auth=(keyID, keySecret))
|
|
payment_intent = client.order.create(
|
|
{
|
|
"amount": int(float(total_amount) * 100 * rate),
|
|
"currency": "INR",
|
|
"payment": {
|
|
"capture": "automatic",
|
|
"capture_options": {"refund_speed": "normal"},
|
|
},
|
|
}
|
|
)
|
|
request.session['CurrencyRate'] = rate
|
|
pid = payment_intent["id"]
|
|
context = {
|
|
"pk": keyID,
|
|
"amtINR": amtINR,
|
|
"pid": pid,
|
|
"amount": total_amount,
|
|
}
|
|
return render(request, "conversion/checkoutC_RazorPay.html", context)
|
|
|
|
else:
|
|
c = CurrencyRates()
|
|
rate = c.get_rate("USD", "INR")
|
|
amtINR = round(float(float(total_amount) * rate), 2)
|
|
payment_intent = stripe.PaymentIntent.create(
|
|
amount=int(float(total_amount) * 100 * rate),
|
|
currency="INR",
|
|
payment_method_types=["card"],
|
|
)
|
|
request.session["payment_intent_id"] = payment_intent.id
|
|
context = {
|
|
"pk": STRIPE_PUB_KEY,
|
|
"total_amount": total_amount,
|
|
"amtINR": amtINR,
|
|
}
|
|
return render(request, "conversion/checkoutC.html", context)
|
|
return render(request, "conversion/conversion.html")
|
|
|
|
|
|
@login_required
|
|
def conversioncard(request):
|
|
if request.method == "POST":
|
|
payment_method_id = request.POST["payment_method_id"]
|
|
payment_intent_id = request.session["payment_intent_id"]
|
|
|
|
customer = stripe.Customer.create(
|
|
email=request.user.email,
|
|
payment_method=payment_method_id,
|
|
invoice_settings={"default_payment_method": payment_method_id},
|
|
)
|
|
|
|
stripe.PaymentIntent.modify(
|
|
payment_intent_id, payment_method=payment_method_id, customer=customer.id
|
|
)
|
|
ret = stripe.PaymentIntent.confirm(payment_intent_id)
|
|
pi = stripe.PaymentIntent.retrieve(payment_intent_id)
|
|
if ret.status == "requires_action":
|
|
context = {
|
|
"pk": STRIPE_PUB_KEY,
|
|
"payment_intent_secret": pi.client_secret,
|
|
}
|
|
return render(request, "conversion/3dsecuredConversion.html", context)
|
|
return render(request, "payments/paymentdone.html")
|
|
|
|
|
|
def paymentDoneC(request):
|
|
|
|
if request.method == "POST":
|
|
|
|
script_id = request.session["script_id"]
|
|
script_title = request.session["script_title"]
|
|
script_file_path = request.session["script_file_path"]
|
|
dial_conv_script = request.session["dial_conv_script"]
|
|
nondial_dest_language = request.session["nondial_dest_language"]
|
|
dial_dest_language = request.session["dial_dest_language"]
|
|
dial_dest_script = request.session["dial_dest_script"]
|
|
dial_src_lang = request.session["dial_src_lang"]
|
|
non_dial_src_lang = request.session["non_dial_src_lang"]
|
|
dial_src_script = request.session["dial_src_script"]
|
|
non_dial_src_script = request.session["non_dial_src_script"]
|
|
dual_dial_script = request.session["dual_dial_script"]
|
|
if request.session.get("want_to_be_vetted"):
|
|
total_amount = request.session["lppamount"]
|
|
else:
|
|
total_amount = request.session["amount"]
|
|
to_be_vetted_by_lpp = request.session.get("want_to_be_vetted")
|
|
option3 = request.session["option3"]
|
|
option4 = request.session["option4"]
|
|
option5 = request.session["option5"]
|
|
option6 = request.session["option6"]
|
|
payment_intent_id = request.session["payment_intent_id"]
|
|
pi = stripe.PaymentIntent.retrieve(payment_intent_id)
|
|
|
|
if pi.status == "succeeded":
|
|
c = conversionPayment()
|
|
s = MNFScriptDatabase()
|
|
s.user_id = request.user
|
|
s.script_id = script_id
|
|
s.script_title = script_title
|
|
s.author_name = request.user.first_name
|
|
s.dial_dest_language = dial_dest_language
|
|
s.dial_dest_script = dial_dest_script
|
|
s.nondial_dest_language = nondial_dest_language
|
|
s.dual_dial_script = dual_dial_script
|
|
s.script_file_path = script_file_path
|
|
s.payment_intent_id = payment_intent_id
|
|
s.nondial_src_script = non_dial_src_script
|
|
s.dial_src_script = dial_src_script
|
|
s.dial_src_language = dial_src_lang
|
|
s.nondial_src_language = non_dial_src_lang
|
|
s.save()
|
|
|
|
# -----------Adding Details to payment Details--------------------------
|
|
currencyrate = request.session['CurrencyRate']
|
|
user_id = request.user
|
|
payment_id = payment_intent_id
|
|
services_used = 'Conversion'
|
|
script_info = s
|
|
number_of_pages = request.session['numPages']
|
|
total_amounts = round((request.session['numPages'] * settings.CONVERSION_PER_PAGE * currencyrate),2)
|
|
discount = round((request.session['discount'] * currencyrate),2)
|
|
amount_charged = round((total_amount * currencyrate),2)
|
|
gateway_fee = round(((settings.STRIPE_PLATFORM_FEE / 100) * amount_charged),2)
|
|
currency = 'INR'
|
|
pay_method = 'Card'
|
|
payment_status = 'Success'
|
|
payment_gateway = 'Stripe'
|
|
PaymentData.objects.create(
|
|
user_id=user_id,
|
|
services_used = services_used,
|
|
payment_id = payment_id,
|
|
script_info = script_info,
|
|
amount_charged = amount_charged,
|
|
total_amount = total_amounts,
|
|
number_of_pages = number_of_pages,
|
|
gateway_fee = gateway_fee,
|
|
discount = discount,
|
|
currency = currency,
|
|
pay_method = pay_method,
|
|
payment_status = payment_status,
|
|
payment_gateway = payment_gateway,
|
|
)
|
|
|
|
# c.pid = privilegedUser1.objects.get(user= request.user)
|
|
# c.script_title = script_title
|
|
# c.script_id = script_id
|
|
# c.to_be_vetted_by_lpp = to_be_vetted_by_lpp
|
|
# c.payment_intent_id = payment_intent_id
|
|
# c.total_amount = str(total_amount)
|
|
# c.script_file_path = script_file_path
|
|
# c.has_paid = 'yes'
|
|
# c.save()
|
|
context = {
|
|
"script_id": script_id,
|
|
"script_title": script_title,
|
|
"script_file_path": script_file_path,
|
|
"dial_conv_script": dial_conv_script,
|
|
"nondial_dest_language": nondial_dest_language,
|
|
"dial_dest_language": dial_dest_language,
|
|
"dial_dest_script": dial_dest_script,
|
|
"dial_src_lang": dial_src_lang,
|
|
"non_dial_src_lang": non_dial_src_lang,
|
|
"dial_src_script": dial_src_script,
|
|
"dual_dial_script": dual_dial_script,
|
|
"total_amount": total_amount,
|
|
"to_be_vetted_by_lpp": to_be_vetted_by_lpp,
|
|
"restrict_to_five": "no",
|
|
"option3": option3,
|
|
"option4": option4,
|
|
"option5": option5,
|
|
"option6": option6,
|
|
}
|
|
return render(request, "conversion/my_conversions.html", context)
|
|
else:
|
|
return render(request, "payments/failed.html")
|
|
|
|
|
|
def paymentDoneC_RazorPay(request):
|
|
if request.method == "POST":
|
|
script_id = request.session["script_id"]
|
|
script_title = request.session["script_title"]
|
|
script_file_path = request.session["script_file_path"]
|
|
dial_conv_script = request.session["dial_conv_script"]
|
|
nondial_dest_language = request.session["nondial_dest_language"]
|
|
dial_dest_language = request.session["dial_dest_language"]
|
|
dial_dest_script = request.session["dial_dest_script"]
|
|
dial_src_lang = request.session["dial_src_lang"]
|
|
non_dial_src_lang = request.session["non_dial_src_lang"]
|
|
dial_src_script = request.session["dial_src_script"]
|
|
dual_dial_script = request.session["dual_dial_script"]
|
|
non_dial_src_script = request.session["non_dial_src_script"]
|
|
if request.session.get("want_to_be_vetted"):
|
|
total_amount = request.session["lppamount"]
|
|
else:
|
|
total_amount = request.session["amount"]
|
|
to_be_vetted_by_lpp = request.session.get("want_to_be_vetted")
|
|
option3 = request.session["option3"]
|
|
option4 = request.session["option4"]
|
|
option5 = request.session["option5"]
|
|
option6 = request.session["option6"]
|
|
razorpay_order_id = request.POST["razorpay_order_id"]
|
|
razorpay_payment_id = request.POST["razorpay_payment_id"]
|
|
razorpay_signature = request.POST["razorpay_signature"]
|
|
client = razorpay.Client(auth=(keyID, keySecret))
|
|
params_dict = {
|
|
"razorpay_order_id": razorpay_order_id,
|
|
"razorpay_payment_id": razorpay_payment_id,
|
|
"razorpay_signature": razorpay_signature,
|
|
}
|
|
try:
|
|
client.utility.verify_payment_signature(params_dict)
|
|
except:
|
|
return render(request, "payments/failed.html")
|
|
c = conversionPayment()
|
|
s = MNFScriptDatabase()
|
|
s.user_id = request.user
|
|
s.script_id = script_id
|
|
s.script_title = script_title
|
|
s.author_name = request.user.first_name
|
|
s.dial_dest_language = dial_dest_language
|
|
s.dial_dest_script = dial_dest_script
|
|
s.nondial_dest_language = nondial_dest_language
|
|
s.dual_dial_script = dual_dial_script
|
|
s.script_file_path = script_file_path
|
|
s.payment_intent_id = razorpay_payment_id
|
|
s.nondial_src_script = non_dial_src_script
|
|
s.dial_src_script = dial_src_script
|
|
s.dial_src_language = dial_src_lang
|
|
s.nondial_src_language = non_dial_src_lang
|
|
s.save()
|
|
# c.pid = privilegedUser1.objects.get(user= request.user)
|
|
# c.script_title = script_title
|
|
# c.script_id = script_id
|
|
# c.to_be_vetted_by_lpp = to_be_vetted_by_lpp
|
|
# c.payment_intent_id = razorpay_payment_id
|
|
# c.total_amount = str(total_amount)
|
|
# c.script_file_path = script_file_path
|
|
# c.has_paid = 'yes'
|
|
# c.save()
|
|
|
|
#payFetch = client.payment.fetch(razorpay_payment_id,({'expand[]':'card'}))
|
|
if client.payment.fetch(razorpay_payment_id,{'expand[]':'card'}):
|
|
pay_method='CARD'
|
|
else:
|
|
pay_method = 'NOTCard'
|
|
# -----------Adding Details to payment Details--------------------------
|
|
currencyrate = request.session['CurrencyRate']
|
|
user_id = request.user
|
|
payment_id = razorpay_payment_id
|
|
services_used = 'Conversion'
|
|
script_info = s
|
|
total_amounts = round((request.session['numPages'] * settings.CONVERSION_PER_PAGE *currencyrate),2)
|
|
discount = round((request.session['discount'] * currencyrate),2)
|
|
amount_charged = round((total_amount * currencyrate),2)
|
|
gateway_fee = round(((settings.RAZORPAY_PLATFORM_FEE / 100) * amount_charged),2)
|
|
currency = 'INR'
|
|
#pay_method = 'NOTCard'
|
|
payment_status = 'Success'
|
|
payment_gateway = 'RazorPay'
|
|
number_of_pages = request.session['numPages']
|
|
print("totalamount:",total_amounts)
|
|
print("amountcharge:",amount_charged)
|
|
print("discount:",discount)
|
|
PaymentData.objects.create(
|
|
user_id = user_id,
|
|
payment_id = payment_id,
|
|
total_amount = total_amounts,
|
|
services_used = services_used,
|
|
script_info = script_info,
|
|
discount = discount,
|
|
amount_charged = amount_charged,
|
|
gateway_fee = gateway_fee,
|
|
currency = currency,
|
|
number_of_pages = number_of_pages,
|
|
pay_method = pay_method,
|
|
payment_status = payment_status,
|
|
payment_gateway = payment_gateway,
|
|
)
|
|
|
|
context = {
|
|
"script_id": script_id,
|
|
"script_title": script_title,
|
|
"script_file_path": script_file_path,
|
|
"dial_conv_script": dial_conv_script,
|
|
"nondial_dest_language": nondial_dest_language,
|
|
"dial_dest_language": dial_dest_language,
|
|
"dial_dest_script": dial_dest_script,
|
|
"dial_src_lang": dial_src_lang,
|
|
"non_dial_src_lang": non_dial_src_lang,
|
|
"dial_src_script": dial_src_script,
|
|
"dual_dial_script": dual_dial_script,
|
|
"total_amount": total_amount,
|
|
"to_be_vetted_by_lpp": to_be_vetted_by_lpp,
|
|
"restrict_to_five": "no",
|
|
"option3": option3,
|
|
"option4": option4,
|
|
"option5": option5,
|
|
"option6": option6,
|
|
}
|
|
return render(request, "conversion/my_conversions.html", context)
|
|
else:
|
|
return render(request, "payments/failed.html")
|
|
|
|
def is_story_converted(request):
|
|
story_id = request.GET["story_id"]
|
|
obj = StoryConversion.objects.get(story_id=story_id)
|
|
print("obj.script convetred function", obj.translated_story_docx)
|
|
if obj.translated_story_docx:
|
|
return JsonResponse({"status": "success"}, status=200)
|
|
else:
|
|
return JsonResponse({"status": "pending"}, status=202)
|
|
|
|
def my_story(request):
|
|
y = StoryConversion.objects.get(story_id=str(request.GET["story_id"]))
|
|
|
|
filename = basePath + "/media/" + str(y.upload_story)
|
|
src_lang = str(y.source_language)
|
|
target_lang = str(y.target_language)
|
|
filename_true = filename.replace("(", "")
|
|
filename_true2 = filename_true.replace(")", "")
|
|
try:
|
|
output = convert_story(filename_true2, src_lang, target_lang)
|
|
# some_translated_script_path = output
|
|
y.translated_story_docx = str(output)[27:]
|
|
y.save()
|
|
return JsonResponse({"status": "success"}, status=200)
|
|
|
|
except:
|
|
return JsonResponse({}, status=505)
|
|
|
|
|
|
|
|
def convert_storyy(request):
|
|
if request.method =="POST":
|
|
from mnfapp.views import languages as lang
|
|
y = StoryConversion()
|
|
y.user_id = request.user
|
|
|
|
now = datetime.datetime.now()
|
|
rightNow = str(now)
|
|
dash_splited = rightNow.split("-")
|
|
str1 = ""
|
|
for i in dash_splited:
|
|
str1 += str(i)
|
|
dash_splited1 = str1.split(" ")
|
|
str2 = ""
|
|
for i in dash_splited1:
|
|
str2 += str(i)
|
|
dash_splited2 = str2.split(":")
|
|
str3 = ""
|
|
for i in dash_splited2:
|
|
str3 += str(i)
|
|
dash_splited3 = str3.split(".")
|
|
str4 = dash_splited3[0]
|
|
|
|
y.story_id = "story_" + str(str4)
|
|
y.upload_story = request.FILES["story"]
|
|
y.target_language = lang[request.POST.get('target_lang')]
|
|
y.source_language = lang[request.POST.get('src_lang')]
|
|
y.save()
|
|
|
|
return render(request, "conversion/my_stories.html", {"story_id":y.story_id})
|
|
|
|
return render(request, "conversion/convertStory.html")
|
|
|
|
from mnfapp.views import languages as lang
|
|
|
|
|
|
|
|
def view_converted_stories(request):
|
|
number = ReferUser.objects.filter(reffered_by=request.user).count()
|
|
obj = StoryConversion.objects.filter(user_id=request.user).order_by("-date_at")
|
|
|
|
script_path = []
|
|
pq = 0
|
|
for i in obj:
|
|
if i.translated_story_docx != "":
|
|
script_path.append(i.translated_story_docx)
|
|
pq += 1
|
|
|
|
return render(request, "conversion/viewStory.html", {"script_path": obj, "pq": pq, "number":number})
|
|
|
|
def delete_converted_story(request, id):
|
|
StoryConversion.objects.get(id=id).delete()
|
|
return HttpResponseRedirect("/conversion/view_converted_stories")
|
|
|