Conversion_Kitchen_Code/kitchen_counter/mnfapp/views.py

912 lines
38 KiB
Python
Raw Permalink Normal View History

2024-04-27 09:33:09 +00:00
from django.shortcuts import render,redirect
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth import get_user_model
import random
from PyPDF2 import PdfReader
from rest_framework import serializers
from users.models import ReferUser
from mnfapp.models import Refer,NonAuthenticatedRefer, SampleScript, centralDatabase
User = get_user_model()
from django.http import JsonResponse
from django.shortcuts import redirect
from django.views.decorators.csrf import csrf_exempt
from rest_framework.views import APIView
from rest_framework.response import Response
from auto_email.views import sendmail
from centralizePayment.models import *
# from centralizePayment.utils import create_juggernaut_models
from centralizePayment.views import callback, create_indent, centralPayment_get_discounts
from django.http import HttpResponse
import MNF.settings as settings
from MNF.settings import BasePath
basepath = BasePath()
import razorpay
from django.contrib.auth.decorators import login_required
from rest_framework_simplejwt.authentication import JWTAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import (api_view, authentication_classes,
permission_classes)
from django.contrib.auth.models import User
import random
import json
class ReferMail(APIView):
def post(self, request, *args, **kwargs):
print(request.data.get("email"))
if User.objects.filter(email=request.data.get("email")).last():
print("is_authenticated", request.data.get("email"))
user = User.objects.get(email=request.data.get("email"))
random_id = str(random.randint(111111, 999999))
if ReferUser.objects.filter(user=user).exists():
rId = ReferUser.objects.get(user=user).referId
else:
y = ReferUser()
rId = random_id
y.user = user
y.referId = rId
y.save()
if request.method == "POST":
referList = request.data.get("emailid", [])
listofuser = []
alreadyReferred = []
alreadyUser = []
refer_user_instance = ReferUser.objects.get(user=user)
email_list = []
print("referList", referList)
key_value = {
"sender": user.email,
}
sendmail(to_email=[referList[0]] , email_code='GT8' , key_value=key_value)
print("mail sent to auth user refer", referList[0])
for i in referList:
try:
if (
i is not None
and i != "undefined"
and not Refer.objects.filter(refer_email1=str(i)).exists()
and not User.objects.filter(email=str(i)).exists()
):
listofuser.append(i)
x = Refer()
x.refer_user = user
x.Refer_id = refer_user_instance.referId
x.refer_email1 = str(i)
x.refer_name1 = i.split("@")[0]
x.save()
to3 = i
email_list.append(i)
else:
if User.objects.filter(email=str(i)).exists():
alreadyUser.append(i)
print("already user", alreadyUser)
elif Refer.objects.filter(refer_email1=str(i)).exists() :
alreadyReferred.append(i)
print("alreadyReferred", alreadyReferred)
except:
print("Some Error")
# print("testing mail, ", email_list)
# key_value = {
# "sender": user.email,
# }
# sendmail(to_email=email_list , email_code='GT8' , key_value=key_value)
# print("mail sent to auth user refer")
temp = []
for i in alreadyReferred:
if i not in alreadyUser:
temp.append(i)
alreadyReferred = temp
to3 = user.email
print(listofuser)
if len(listofuser) >= 1:
print("testing mail, ", to3)
listofuser_str = ", ".join(listofuser)
key_value = {
"sender": to3,
"listofuser": listofuser_str
}
sendmail(to_email=[to3] , email_code='GT9' , key_value=key_value)
print("mail sent to auth user")
request.session["affmessage"] = "Referred Successfully"
elif len(listofuser) == 0:
request.session["affmessage"] = "Referred Successfully"
else:
request.session["affmessage"] = "Referred Successfully "
data = {'data': "successs", "alreadyUser": alreadyUser, "alreadyReferred": alreadyReferred, "listofuser": listofuser}
return JsonResponse(data, safe=False)
else:
if request.method == "POST":
print("In Refer Your Friend As Anonymous User")
referList = request.data.get("emailid", [])
_email = request.data.get("email", '')
_name = request.data.get("name", '')
_phone = request.data.get("phone", '')
print(request.data)
refer_user, created = NonAuthenticatedRefer.objects.get_or_create(
email=_email,
phone=_phone,
name=_name
)
ReferId = random.randint(111111, 999999)
refer_user_instance, created = ReferUser.objects.get_or_create(non_auth_user_email=refer_user.email)
if not created:
print("Refer user already exists")
listofuser = []
alreadyReferred = []
alreadyUser = []
if len(referList) == 0 or not _email:
data = {'data': "false"}
return JsonResponse(data, safe=False)
email_list = []
print("referList", referList)
key_value = {
"sender": refer_user.email,
"listofuser": ",".join(listofuser),
}
sendmail(to_email=referList[0] , email_code='GT8' , key_value=key_value)
print("mail sent to auth user refer", referList[0])
for i in referList:
print(i)
if (
i is not None
and i != "undefined"
and not Refer.objects.filter(refer_email1=str(i))
and not NonAuthenticatedRefer.objects.filter(email=str(i))
):
listofuser.append(str(i))
to3 = i
email_list.append(str(i))
refer_user.save()
print(listofuser)
print(refer_user, refer_user_instance.referId, i.split("@")[0], str(i))
x = Refer()
x.non_auth_refer = refer_user
x.Refer_id = refer_user_instance.referId
x.refer_name1 = i.split("@")[0]
x.refer_email1 = str(i)
x.save()
print("Referrrrrr", x.Refer_id)
else:
if User.objects.filter(email=str(i)).exists():
alreadyUser.append(i)
print("already user", alreadyUser)
if Refer.objects.filter(refer_email1=str(i)).exists():
alreadyReferred.append(i)
print("already referred", alreadyReferred)
# user = User.objects.get(email=request.data.get("email"))
# print("testing mail, ", email_list)
# key_value = {
# "sender": refer_user.email,
# }
# sendmail(to_email=email_list , email_code='GT8' , key_value=key_value)
# print("mail sent to auth user refer")
temp = []
print("testing mail, ", refer_user.email)
key_value = {
"sender": refer_user.email,
"listofuser": ",".join(listofuser),
}
sendmail(to_email=[refer_user.email] , email_code='GT9' , key_value=key_value)
print("mail sent to nonauth user")
for i in alreadyReferred:
if i not in alreadyUser:
temp.append(i)
alreadyReferred = temp
request.session["affmessage"] = "Referred Successfully"
context = {"affmessage": request.session.get("affmessage", None)}
data = {'data': "successs", "alreadyUser": alreadyUser, "alreadyReferred": alreadyReferred, "listofuser": listofuser}
return JsonResponse(data, safe=False)
# @csrf_exempt
# def ReferMail(request):
# if request.user.is_authenticated:
# if ReferUser.objects.filter(user=request.user).exists():
# rId = ReferUser.objects.get(user=request.user)
# else:
# y = ReferUser()
# rId = str(random.randint(111111, 999999))
# y.user = request.user
# y.referId = rId
# y.save()
# if request.method == "POST":
# referList = request.POST.getlist("emailid")
# listofuser = []
# alreadyReferred = []
# alreadyUser = []
# for i in referList:
# if (
# i is not None
# and i != "undefined"
# and not refer.objects.filter(refer_email1=str(i)).exists()
# and not User.objects.filter(email=str(i)).exists()
# ):
# listofuser.append(i)
# x = refer()
# x.refer_user = request.user
# x.refer_email1 = str(i)
# x.save()
# subject3 = "Someone trusts you"
# from_email = settings.EMAIL_HOST_USER
# to3 = i
# if request.user.first_name and request.user.last_name:
# sender = (
# str(request.user.first_name)
# + " "
# + str(request.user.last_name)
# )
# else:
# sender = request.user.email
# context3 = {
# "sender": sender,
# "user": i.split("@")[0],
# "referid": rId,
# }
# # mnfnsendemail(
# # to3,
# # subject3,
# # "payment/templates/payments/MR19.html",
# # context3,
# # from_email,
# # )
# else:
# if User.objects.filter(email=str(i)).exists():
# alreadyUser.append(str(i))
# elif refer.objects.filter(refer_email1=str(i)).exists() and str(i):
# alreadyReferred.append(str(i))
# # get unique email ids of user
# temp = []
# for i in alreadyReferred:
# if i not in alreadyUser:
# temp.append(i)
# alreadyReferred = temp
# # mail to user
# subject3 = "You have a big heart !!"
# from_email = settings.EMAIL_HOST_USER
# to3 = request.user.email
# context3 = {
# "sender": request.user.username,
# "listofuser": ",".join(listofuser),
# }
# print("manojpoornima@2226")
# print(listofuser)
# if len(listofuser) > 1:
# subject3 = "You are really marvellous"
# # mnfnsendemail(
# # to3,
# # subject3,
# # "payment/templates/payments/MR20.html",
# # context3,
# # from_email,
# # )
# request.session["affmessage"] = "Referred Successfully"
# elif len(listofuser) == 0:
# request.session["affmessage"] = "Referred Successfully"
# else:
# # mnfnsendemail(
# # to3,
# # subject3,
# # "payment/templates/payments/MR18.html",
# # context3,
# # from_email,
# # # )
# request.session["affmessage"] = "Referred Successfully "
# return redirect("home")
# # return Response("successfull")
# else:
# if request.method == "POST":
# print("In Refer Your Friend As Anonymous User")
# print(request.POST)
# referList = request.POST.getlist("emailid")
# listofuser = []
# alreadyReferred = []
# alreadyUser = []
# print('email list',referList)
# for i in referList:
# print(i)
# if (
# i is not None
# and i != "undefined"
# and not refer.objects.filter(refer_email1=str(i)).exists()
# and not User.objects.filter(email=str(i)).exists()
# ):
# listofuser.append(str(i))
# subject3 = "One of your friend has referred you to join MyNextFilm"
# from_email = settings.EMAIL_HOST_USER
# to3 = i
# context3 = {
# "sender": "Your friend",
# "user1": i.split("@")[0],
# }
# # mnfnsendemail(
# # to3,
# # subject3,
# # "payment/templates/payments/MR19.html",
# # context3,
# # from_email,
# # )
# else:
# if User.objects.filter(email=str(i)).exists():
# alreadyUser.append(str(i))
# if refer.objects.filter(refer_email1=str(i)).exists():
# alreadyReferred.append(str(i))
# # get unique email ids
# temp = []
# for i in alreadyReferred:
# if i not in alreadyUser:
# temp.append(i)
# alreadyReferred = temp
# request.session["affmessage"] = "Referred Successfully"
# context = {"affmessage": request.session.get("affmessage", None)}
# # return render(request, "home.html", context)
# # return redirect("home")
# data={'data':"successs"}
# return JsonResponse(data,safe=False)
from Blockchain2.Narration import getUserprojectIds,NarrationData,getNarrationData
import requests
def blockchain_uploads(request):
print("request", request)
print("request.user", request.user)
print("Delhi India: 1")
if request.method == "POST":
print("request.FILES", request.FILES)
uploaded_file = request.FILES['scriptss']
script_id = request.POST.get('script_id')
#Blockchain
# if UserCredentialsForBlockchain.objects.filter(user=request.user).exists():
# blockchain_obj = UserCredentialsForBlockchain.objects.get(user=request.user)
# contex = z.choosescript
url = 'http://1.6.141.104/upload'
data = {
'files': uploaded_file,
}
# 'example.txt' should be replaced with the path to your file
response = requests.post(url, files=data)
print("hash;;;;;;;;>>",response)
response_data = response.json()
hash_value = response_data.get('hash')
hssh= {
"cid_hash":hash_value
}
txhash= NarrationData("2c8db4da45123baedc14d7a136bf094f59d0ff382c6647ef3ad079404a466b03","0xCe5D28611021a99418228d28479E81BE2D6e5af4",1,script_id,str(hssh) )
return render(
request, "mnfapp/uploadfiles.html",{"hash": str(hash_value),"tx_hash":txhash}
)
if request.method == "GET":
file_id = request.GET.get("file_id")
private_key1 = request.GET.get("private_key")
try:
status,getdata = getNarrationData(private_key1,1,str(file_id))
if status==True:
getdatas = eval(getdata[1])
cid_hash = getdatas.get('cid_hash')
return render(
request, "mnfapp/uploadfiles.html",{"cid_hash": cid_hash,}
)
return HttpResponse('External API returned a non-200 status code. file is not found on blockchain', status=500)
except:
return render(
request, "mnfapp/uploadfiles.html",
)
return render(
request, "mnfapp/uploadfiles.html",
) # many to many field or foreign key (characterwise_intro)
# def set_payment_token(request):
# if request.user.is_superuser:
# request.session["keyID"] = settings.T_RAZORPAY_KEY_ID
# request.session["keySecret"] = settings.T_RAZORPAY_KEY_SECRET
# else:
# request.session["keyID"] = settings.RAZORPAY_KEY_ID
# request.session["keySecret"] = settings.RAZORPAY_KEY_SECRET
# def price_pay(request,pk=None,amt=None):
# print("amount of jungarnath",amt)
# context = {
# "price":amt,
# "package":pk,
# }
# return render(request,"mnfapp/pricing_payment.html",context)
# @login_required(login_url="/")
# def juggernaut(request,pk=None,amt=None):
# set_payment_token(request)
# keyID = request.session["keyID"]
# keySecret = request.session["keySecret"]
# servicename = pk.capitalize()
# request.session['service_name'] = servicename
# service_id = "2"
# qtn=1
# promo_code =""
# total_amount = float(int(amt))
# request.session["total_amount"] = total_amount
# amount_charged = float(int(amt))
# discount = 0
# if servicename == "Globalise":
# # messages.success(request, 'Welcome to Globalise!')
# error = "Amount exceeded maximum limit "
# # return redirect("/members-home")
# return render(
# request,
# "payments/payment1.html",{"error": error}
# )
# else:
# pass
# indent_context = create_indent(request,servicename,service_id,qtn,promo_code,total_amount,amount_charged,discount)
# request.session["indent_context"] = indent_context
# with open(f"{basepath}/MNF/json_keys/conversionRates.json") as c:
# curr = json.load(c)
# print(curr["rates"]["INR"])
# try:
# rate = curr["rates"]["INR"]
# print(rate, " : Latest rates 30sep")
# except Exception as e:
# print("checkout error", e)
# rate = 80
# if request.session["indent_context"]:
# client = razorpay.Client(auth=(keyID, keySecret))
# if "orderId" in request.session["indent_context"]:
# request.session["payment_order_id"] = request.session["indent_context"]["orderId"]
# request.session["central_payment_id"] = request.session["indent_context"]["central_pay_id"]
# centralPayment_instance = CentralPayment.objects.get(id=request.session["indent_context"]["central_pay_id"])
# pid = centralPayment_instance.order_id
# amtINR = round(centralPayment_instance.amount_charged* rate, 2)
# context = {
# "pk": keyID,
# "amtINR": amtINR,
# "pid": pid,
# "amount": centralPayment_instance.amount_charged,
# }
# context["orderId"] = "orderId"
# # return render(
# # request,
# # "mnfapp/jagarnut_Razorpay.html",
# # context
# # )
# return render(
# request,
# "payments/payment1.html",
# context
# )
# elif "client_secret" in request.session["indent_context"]:
# request.session["payment_order_id"] = request.session["indent_context"]["client_secret"] # save central payment details in your database
# request.session["central_payment_id"] = request.session["indent_context"]["central_pay_id"]
# request.session["pub_key"] = request.session["indent_context"]["pub_key"] # save central payment details in your database
# centralPayment_instance = CentralPayment.objects.get(id=request.session["indent_context"]["central_pay_id"])
# pid = centralPayment_instance.order_id
# amtINR = total_amount* rate
# context = {
# "pk": request.session["indent_context"]["pub_key"],
# "total_amount": round(total_amount,2),
# "secret_key":request.session["indent_context"]["client_secret"],
# "amtINR": round(amtINR,2),
# "pid": pid,
# "STRIPE_PUBLISHABLE_KEY": request.session["indent_context"]["pub_key"],
# }
# context["client_secret"] = "client_secret"
# # return render(
# # request,
# # "mnfapp/jagarnut_stripe.html",
# # context
# # )
# return render(
# request,
# "payments/payment1.html",
# context
# )
# elif "monthly_user" in request.session["indent_context"]:
# request.session["payment_order_id"] = "monthly_user"
# request.session["central_payment_id"] = request.session["indent_context"]["central_pay_id"]
# centralPayment_instance = CentralPayment.objects.get(id=request.session["indent_context"]["central_pay_id"])
# pid = centralPayment_instance.order_id
# amtINR = centralPayment_instance.amount_charged
# s=PitchVector()
# s.payment_order_id = request.session["payment_order_id"] # save central payment details in your database
# s.central_payment_id = request.session["central_payment_id"]
# s.save()
# context = {
# "amtINR": round(amtINR,2),
# "pid": pid,
# "amount": round(total_amount,2),
# }
# # return render(request, "Pitchdeck/PitchnarratedVideos.html",context)
# return Response("ok")
# @login_required(login_url="/")
# def jugarnut_Razorpay(request):
# if request.method == 'POST':
# callback_payment = callback(request.POST, request)
# if callback_payment['payment_status'] == 'success':
# with open(f"{basepath}/MNF/json_keys/conversionRates.json") as c:
# curr = json.load(c)
# try:
# rate = curr["rates"]["INR"]
# except Exception as e:
# print("checkout error", e)
# rate = 80
# # total_amount = round(float((request.session["total_amount"]) * rate), 2)
# # amount_charged = round(float((request.session["net_payable"]) * rate), 2)
# # s=PitchVector()
# # s.payment_order_id = request.session["payment_order_id"] # save central payment details in your database
# # s.central_payment_id = request.session["central_payment_id"]
# # s.save()
# try:
# user_data = JuggernautPackage.objects.get(user_id = request.user.id,package_name = request.session['service_name'])
# except:
# print("not any package")
# if request.session["total_amount"] == 5:
# user_data.validity_days += 30
# user_data.save()
# elif request.session["total_amount"] == 99:
# user_data.language_alert = False
# user_data.conversion_languages += 1
# user_data.save()
# else:
# create_juggernaut_models(request.user, request.session['service_name'])
# print("create package")
# return redirect("/members-home")
# # except:
# else:
# print("manoj1450")
# amount_charged = request.session["net_payable"]
# return render(request, "payments/failed.html")
# else:
# return HttpResponse("You don't have an access to use this.")
# @login_required(login_url="/")
# def jugarnut_Stripe(request):
# if request.method == "GET":
# # total_amount= request.session["total_amount"]
# # amount_charged = request.session["net_payable"]
# # discount = request.session["discount"]
# for key, value in request.GET.items():
# print(rf'{key}: {value}')
# response = {
# "id": request.GET.get("payment_intent"),
# "client_secret": request.GET.get("payment_intent_client_secret"),
# "status": request.GET.get("redirect_status"),
# }
# callback_content = callback(response, request)
# if callback_content['payment_status'] == "success":
# s = MNFScriptDatabase()
# # p = PitchVector()
# s.user_id = request.user
# # s.script_id = script_id
# # s.script_title = script_title
# # p.payment_order_id = request.session["payment_order_id"] # save central payment details in your database
# # p.central_payment_id = request.session["central_payment_id"]
# # p.save()
# s.save()
# try:
# user_data = JuggernautPackage.objects.get(user_id = request.user.id,package_name = request.session['service_name'])
# except:
# print("not any package")
# if request.session["total_amount"] == 5:
# user_data.validity_days += 30
# user_data.save()
# elif request.session["total_amount"] == 99:
# user_data.language_alert = False
# user_data.conversion_languages += 1
# user_data.save()
# else:
# create_juggernaut_models(request.user, request.session['service_name'])
# return redirect("/members-home")
# else:
# amount_charged = "10"
# sendmail(to_email=[request.user.email] , email_code="TN4" ,key_value = {'amount':amount_charged})
# return render(request, "payments/failed.html")
# def update_juggernaut(request, **kwargs):
# user_id = request.user.id
# # check if object exists (else code will break)
# # there is a possibility that the user can have 2 packages active (fetch the object with the latest created datetime)
# # check service function parameters (as we are passing kwargs instead)
# # in models import service objects and uncomment associated projects
# response = {}
# if JuggernautPackage.objects.filter(user_id = user_id).exists():
# user_data = JuggernautPackage.objects.filter(user_id = user_id)
# if user_data.count()==1:
# user_data = JuggernautPackage.objects.get(user_id = user_id)
# else:
# user_data = JuggernautPackage.objects.get(id = request.session['user_data'])
# # user_data = request.session['user_data']
# if kwargs.get("service_name") == "narration":
# response = update_narration(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "conversion":
# response = update_conversion(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "scriptpad":
# response = update_scriptpad(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "projectcenter":
# response = update_projectcenter(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "subtitle":
# response = update_subtitle(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "pitchdeck":
# response = update_pitchdeck(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "audit":
# response = update_audit(user_data, response, **kwargs)
# return response
# def check_juggernaut(request, **kwargs):
# user_id = request.user.id
# # check if object exists (else code will break)
# # there is a possibility that the user can have 2 packages active (fetch the object with the latest created datetime)
# # check service function parameters (as we are passing kwargs instead)
# # in models import service objects and uncomment associated projects
# user_data_qs = JuggernautPackage.objects.filter(user_id=user_id)
# response = {}
# if JuggernautPackage.objects.filter(user_id = user_id).exists():
# user_data = JuggernautPackage.objects.filter(user_id = user_id)
# if user_data.count() == 1:
# user_data = JuggernautPackage.objects.get(user_id = user_id)
# if kwargs.get("service_name") == "narration":
# if user_data.count() > 1:
# for i in user_data:
# if i.package_name in ['Radiate',"Regionalise","Globalise"]:
# user_data = i
# request.session['user_data'] = str(user_data.id)
# break
# response = check_narration(user_data, response, **kwargs)
# elif kwargs.get("service_name") == "conversion":
# try:
# if user_data.count() > 1:
# max_beat = 0
# for i in user_data:
# if i.conversion_pages >= max_beat:
# user_data = i
# request.session['user_data'] = str(user_data.id)
# except:
# max_beat = 0
# request.session['user_data'] = str(user_data.id)
# response = check_conversion(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "scriptpad":
# # if user_data.count() > 1:
# # max_beat = 0
# # for i in user_data:
# # if i.beat_scene_generation >= max_beat:
# # user_data = i
# # request.session['user_data'] = str(user_data.id)
# # response = check_scriptpad(user_data, response, **kwargs)
# if user_data_qs.count() > 1:
# # Logic to select the appropriate user_data instance
# # For example, select the one with the maximum beat_scene_generation
# max_beat = 0
# selected_user_data = None
# for i in user_data_qs:
# if i.beat_scene_generation >= max_beat:
# max_beat = i.beat_scene_generation
# selected_user_data = i
# user_data = selected_user_data if selected_user_data else user_data_qs.first()
# else:
# user_data = user_data_qs.first()
# response = check_scriptpad(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "projectcenter":
# if user_data.count() > 1:
# for i in user_data:
# if i.scheduling_and_budget_projects >=1:
# user_data = i
# request.session['user_data'] = str(user_data.id)
# break
# if user_data.count() > 1:
# user_data = user_data[0]
# request.session['user_data'] = str(user_data.id)
# response = check_projectcenter(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "subtitle":
# if user_data_qs.count() > 1:
# # if user_data.count() > 1:
# max_beat = 0
# for i in user_data_qs:
# if i.subtitling_minutes >= max_beat:
# user_data = i
# request.session['user_data'] = str(user_data.id)
# else:
# user_data = user_data_qs.first()
# response = check_subtitle(user_data, response, **kwargs)
# elif kwargs.get("service_name")== "pitchdeck":
# if user_data.count() > 1:
# for i in user_data:
# if i.package_name in ['Longjump',"Tripplejump","Highjump"]:
# user_data = i
# request.session['user_data'] = str(user_data.id)
# break
# response = check_pitchdeck(user_data, response, **kwargs)
# # else:
# return response
def sampleScriptsC(request):
number = ReferUser.objects.filter(
reffered_by=request.user
).count() # refferedBy on aws {manoj}
sampleList = SampleScript.objects.filter(approved=True)
datas = SampleScript.objects.all()
lang_list = []
print("Running checks456")
for i in datas:
if i.approved == False:
pass
else:
langsss = str(i.languages).split(", ")
for ii in langsss:
if str(ii) in lang_list:
pass
else:
lang_list.append(str(ii))
# print(lang_list12)
return render(
request,
"mnfapp/sampleC.html",
{"list": sampleList, "number": number, "lang_list": sorted(lang_list)},
)
def samplescript_filter(request):
if request.method == "POST":
sampleList = SampleScript.objects.all()
language = request.POST.get("language")
scripts = []
for i in sampleList:
if i.approved == False: # True / False
pass
else:
if language == "":
scripts.append(
(
str(i.script_title),
str(i.script_file_path_pdf),
str(i.sample_id),
str(str(i.script_title)[0]),
str(i.author_name),
)
)
else:
if language in str(i.languages).split(", "):
scripts.append(
[
str(i.script_title),
str(i.script_file_path_pdf),
str(i.sample_id),
str(str(i.script_title)[0]),
str(i.author_name),
]
)
result = json.dumps(scripts)
return JsonResponse({"scripts": result})
def sampleConversion(request, id):
from conversion.translation.translation_variables import code_2_language
languages2 = code_2_language
for script in SampleScript.objects.all():
print(script.script_title)
x = SampleScript.objects.get(sample_id=id)
pdf = PdfReader(open(rf"{BasePath()}/media/{x.script_file_path_pdf}", "rb"))
number_of_pages = len(pdf.pages)
context = {
"id": 1234567890,
"numPages": number_of_pages,
"author_name": request.user.username,
"script_title": x.script_title,
"dial_src_script": x.dial_src_script,
"dial_src_lang_full": languages2.get(x.dial_src_language),
"non_dial_src_script": x.nondial_src_script,
"non_dial_src_lang_full": languages2.get(x.nondial_src_language),
"sample_id": id,
}
return render(request, "conversion2/conversion_processing.html", context)
class ProfileSerializer(serializers.ModelSerializer):
class Meta:
model = centralDatabase
fields = ('firstName','lastName','address', 'contact', 'profile_photo')
class UserSerializer(serializers.ModelSerializer):
centraldatabase = ProfileSerializer(source='centraldatabase_set.first', read_only=True)
class Meta:
model = User
fields = ('id', 'username', 'email','first_name','last_name', 'centraldatabase')
class GetUser(APIView):
authentication_classes = [JWTAuthentication]
permission_classes = [IsAuthenticated]
def get(self, request):
u_id = request.user.id if request.user.id else 1499
user = User.objects.get(id=u_id)
sr = UserSerializer(user)
context = {
'userid': sr.data
}
return Response(context)