739 lines
33 KiB
Python
739 lines
33 KiB
Python
from django.shortcuts import render,redirect
|
|
from django.contrib.auth import get_user_model
|
|
User = get_user_model()
|
|
from rest_framework.response import Response
|
|
from auto_email.views import sendmail
|
|
from .utils import create_juggernaut_models
|
|
from centralizePayment.views import callback, create_indent
|
|
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
|
|
import json
|
|
from .models import *
|
|
from .serializers import *
|
|
from centralizePayment.models import CentralPayment
|
|
from rest_framework.decorators import (api_view, authentication_classes,
|
|
permission_classes)
|
|
|
|
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 check_narration(user_data,service_data, **kwargs):
|
|
if user_data.narrarion_character_intro >= kwargs['narration_character_intro']:
|
|
service_data['Character Introduction'] = True # nikalne do character intro
|
|
else:
|
|
service_data['Character Introduction'] = False # character intro ka paisa lo
|
|
if user_data.narrarion_line_by_line >= kwargs['narrarion_line_by_line']:
|
|
service_data['Line by Line Narration'] = True
|
|
else:
|
|
service_data['Line by Line Narration'] = False
|
|
if user_data.narrarion_characterwise >= kwargs['narrarion_characterwise']:
|
|
service_data['Characterwise Narration'] = True
|
|
else:
|
|
service_data['Characterwise Narration'] = False
|
|
return service_data
|
|
|
|
def check_conversion(user_data, service_data, **kwargs):
|
|
if user_data.conversion_pages >= kwargs['conversion_pages']:
|
|
service_data['conversion_pages'] = 0
|
|
else:
|
|
service_data['conversion_pages'] = kwargs['conversion_pages'] - user_data.conversion_pages
|
|
if JuggernautConversion.objects.filter(associated_project=kwargs['associated_project']).exists():
|
|
conversion_juggernaut = JuggernautConversion.objects.get(associated_project=kwargs['associated_project'])
|
|
juggernaut_language_sets = JuggernautConversionSet.objects.filter(associated_project=kwargs['associated_project'])
|
|
list_of_language_sets = []
|
|
for set in juggernaut_language_sets:
|
|
list_of_language_sets.append([set.actionline_lang, set.actionline_script, set.dial_lang, set.dial_script])
|
|
if kwargs['translation_language'] in list_of_language_sets:
|
|
if conversion_juggernaut.iterations >= user_data.conversion_iteration:
|
|
service_data['conversion_pages'] = kwargs['conversion_pages']
|
|
else:
|
|
if conversion_juggernaut.languages >= user_data.conversion_languages:
|
|
service_data['conversion_pages'] = kwargs['conversion_pages']
|
|
user_data.language_alert = True
|
|
user_data.save()
|
|
service_data['language_alert'] = True
|
|
return service_data
|
|
|
|
|
|
def check_scriptpad(user_data, service_data, **kwargs):
|
|
if user_data.beat_scene_generation >= kwargs['beat_scene_generation']:
|
|
service_data['beat_scene_generation'] = True
|
|
else:
|
|
payable_beat = kwargs['beat_scene_generation'] - user_data.beat_scene_generation
|
|
service_data['beat_scene_generation'] = payable_beat
|
|
return service_data
|
|
|
|
def check_projectcenter(user_data, service_data,**kwargs):
|
|
if user_data.scheduling_and_budget_projects >= kwargs['scheduling_and_budget_projects']:
|
|
service_data['scheduling_and_budget_projects'] = True
|
|
else:
|
|
service_data['scheduling_and_budget_projects'] = False
|
|
|
|
# elif user_data.scheduling_and_budget_projects < scheduling_and_budget_projects:
|
|
# payable_project = scheduling_and_budget_projects - user_data.scheduling_and_budget_projects
|
|
# return {"payable_project":payable_project}
|
|
return service_data
|
|
|
|
def check_subtitle(user_data, service_data, **kwargs):
|
|
if user_data.subtitling_minutes >= kwargs['subtitling_minutes']:
|
|
service_data['subtitling_minutes'] = 0
|
|
|
|
else:
|
|
service_data['subtitling_minutes'] = kwargs['subtitling_minutes']-user_data.subtitling_minutes
|
|
|
|
if user_data.subtitling_languages >= kwargs['subtitling_languages']:
|
|
service_data['subtitling_languages'] = 0
|
|
else:
|
|
service_data['subtitling_languages'] = kwargs['subtitling_languages']-user_data.subtitling_languages
|
|
if JuggernautSubtitling.objects.filter(associated_project=kwargs['associated_project']).exists():
|
|
subtitling_juggernaut = JuggernautSubtitling.objects.get(associated_project=kwargs['associated_project'])
|
|
try:
|
|
unique_element_set1 =set(kwargs['subtitling_languages_list']) - set(subtitling_juggernaut.associated_project.target_languages.split(','))
|
|
same_element = set(kwargs['subtitling_languages_list']) - unique_element_set1
|
|
if subtitling_juggernaut.iterations < same_element.count():#free use of iterations
|
|
service_data['subtitling_languages'] += same_element.count()
|
|
if subtitling_juggernaut.languages < unique_element_set1.count():
|
|
service_data['subtitling_languages'] += unique_element_set1.count()
|
|
|
|
except:
|
|
pass
|
|
# if subtitling_juggernaut.iterations >= user_data.subtitling_iteration:
|
|
# service_data['subtitling_minutes'] = kwargs['subtitling_minutes']
|
|
# if subtitling_juggernaut.languages >= user_data.subtitling_languages:
|
|
# service_data['subtitling_minutes'] = kwargs['subtitling_minutes']
|
|
# else:
|
|
# factor = user_data.subtitling_languages - subtitling_juggernaut.languages
|
|
# service_data['subtitling_minutes'] *= factor
|
|
return service_data
|
|
|
|
def check_pitchdeck(user_data, service_data,**kwargs):
|
|
if user_data.pitchdeck_one_pager >= kwargs['pitchdeck_one_pager']:
|
|
service_data['pitchdeck_one_pager'] = True
|
|
else:
|
|
service_data['pitchdeck_one_pager'] = False
|
|
|
|
if user_data.pitchdeck_elevator >= kwargs['pitchdeck_elevator']:
|
|
service_data['pitchdeck_elevator'] = True
|
|
else:
|
|
service_data['pitchdeck_elevator'] = False
|
|
|
|
if user_data.pitchdeck_screenplay >= kwargs['pitchdeck_screenplay']:
|
|
service_data['pitchdeck_screenplay'] = True
|
|
else:
|
|
service_data['pitchdeck_screenplay'] = False
|
|
|
|
return service_data
|
|
|
|
|
|
|
|
def update_narration(user_data,service_data, **kwargs):
|
|
if user_data.narrarion_character_intro > 0:
|
|
remain_intro = user_data.narrarion_character_intro - int(kwargs['narration_character_intro'])
|
|
user_data.narrarion_character_intro = remain_intro
|
|
user_data.save()
|
|
if user_data.narrarion_line_by_line > 0:
|
|
remain_line = user_data.narrarion_line_by_line - int(kwargs['narrarion_line_by_line'])
|
|
user_data.narrarion_line_by_line = remain_line
|
|
user_data.save()
|
|
if user_data.narrarion_characterwise > 0:
|
|
remain_char = user_data.narrarion_characterwise - int(kwargs['narrarion_characterwise'])
|
|
user_data.narrarion_characterwise = remain_char
|
|
user_data.save()
|
|
return("updated_narration",user_data)
|
|
|
|
def update_conversion(user_data, service_data, **kwargs):
|
|
|
|
if JuggernautConversion.objects.filter(associated_project=kwargs['associated_project']).exists():
|
|
conversion_juggernaut = JuggernautConversion.objects.get(associated_project=kwargs['associated_project'])
|
|
juggernaut_language_sets = JuggernautConversionSet.objects.filter(associated_project=kwargs['associated_project'])
|
|
list_of_language_sets = []
|
|
for set in juggernaut_language_sets:
|
|
list_of_language_sets.append([set.actionline_lang, set.actionline_script, set.dial_lang, set.dial_script])
|
|
if kwargs['translation_language'] in list_of_language_sets:
|
|
conversion_juggernaut.iterations += 1
|
|
else:
|
|
conversion_juggernaut.languages += 1
|
|
conversion_juggernaut.save()
|
|
else:
|
|
user_data.conversion_pages -= kwargs['conversion_pages']
|
|
if user_data.conversion_pages < 0:
|
|
user_data.conversion_pages = 0
|
|
user_data.save()
|
|
jcs = JuggernautConversionSet()
|
|
jcs.associated_project = kwargs['associated_project']
|
|
jcs.actionline_lang = kwargs['translation_language'][0]
|
|
jcs.actionline_script = kwargs['translation_language'][1]
|
|
jcs.dial_lang = kwargs['translation_language'][2]
|
|
jcs.dial_script = kwargs['translation_language'][3]
|
|
jcs.save()
|
|
|
|
jc = JuggernautConversion.objects.create(associated_project=kwargs['associated_project'], package=user_data)
|
|
jc.project_name = kwargs['associated_project'].script_title
|
|
jc.languages = 1
|
|
jc.project_details = kwargs['conversion_pages']
|
|
jc.save()
|
|
|
|
return ("updated_conversion successfully",user_data)
|
|
|
|
def update_scriptpad(user_data, service_data, **kwargs):
|
|
if user_data.beat_scene_generation >= kwargs['beat_scene_generation']:
|
|
remain = user_data.beat_scene_generation - int(kwargs['beat_scene_generation'])
|
|
user_data.beat_scene_generation = remain
|
|
user_data.save()
|
|
return("updated_scriptpad",user_data)
|
|
|
|
def update_projectcenter(user_data, service_data,**kwargs):
|
|
if user_data.scheduling_and_budget_projects >0:
|
|
remain = user_data.scheduling_and_budget_projects - int(kwargs['scheduling_and_budget_projects'])
|
|
user_data.scheduling_and_budget_projects = remain
|
|
user_data.save()
|
|
# if JuggernautProjectCenter.objects.filter(associated_project=kwargs['associated_project']).exists():
|
|
# # project_juggernaut = JuggernautProjectCenter.objects.get(associated_project=kwargs['associated_project'])
|
|
# print("project_jugggernaut")
|
|
# else:
|
|
jpc = JuggernautProjectCenter.objects.create(associated_project=kwargs['associated_project'],package = user_data,project_name = kwargs['associated_project'].project_name)
|
|
jpc.save()
|
|
# return service_data
|
|
return("updated_projectcenter",user_data)
|
|
|
|
def update_subtitle(user_data, service_data, **kwargs):
|
|
user_data.subtitling_minute = user_data.subtitling_minute - kwargs['subtitling_minutes']
|
|
if user_data.subtitling_minute < 0:
|
|
user_data.subtitling_minute = 0
|
|
user_data.save()
|
|
if not JuggernautSubtitling.objects.filter(associated_project=kwargs['associated_project'],package = user_data).exists():
|
|
js = JuggernautSubtitling.objects.create(associated_project=kwargs['associated_project'],package = user_data)
|
|
else:
|
|
js = JuggernautSubtitling.objects.get(associated_project=kwargs['associated_project'])
|
|
try:
|
|
unique_element_set1 =set(kwargs['subtitling_languages_list']) - set(js.associated_project.target_languages.split(','))
|
|
same_element = set(kwargs['subtitling_languages_list']) - unique_element_set1
|
|
if js.iterations < same_element.count():#free use of iterations
|
|
js.iterations += same_element.count()
|
|
if js.languages < unique_element_set1.count():
|
|
js.languages += unique_element_set1.count()
|
|
|
|
except:
|
|
pass
|
|
# js.languages = kwargs["associated_project"].target_languages.split(',').count()
|
|
js.project_name = kwargs["associated_project"].project_name
|
|
js.project_details =kwargs['subtitling_minutes']
|
|
js.save()
|
|
# user_data.subtitling_languages = user_data.subtitling_languages - kwargs["associated_project"].target_languages.split(',').count()
|
|
|
|
|
|
# if JuggernautSubtitling.objects.filter(associated_project=kwargs['associated_project']).exists():
|
|
# subtitling_juggernaut = JuggernautSubtitling.objects.get(associated_project=kwargs['associated_project'])
|
|
# if subtitling_juggernaut.iterations >= user_data.subtitling_iteration:
|
|
# service_data['subtitling_minutes'] = kwargs['subtitling_minutes']
|
|
# if subtitling_juggernaut.languages >= user_data.subtitling_languages:
|
|
# service_data['subtitling_minutes'] = kwargs['subtitling_minutes']
|
|
# return service_data
|
|
|
|
def update_pitchdeck(user_data,service_data, **kwargs):
|
|
if user_data.pitchdeck_one_pager > 0:
|
|
remain_intro = user_data.pitchdeck_one_pager - int(kwargs['pitchdeck_one_pager'])
|
|
user_data.pitchdeck_one_pager = remain_intro
|
|
user_data.save()
|
|
if user_data.pitchdeck_elevator > 0:
|
|
remain_line = user_data.pitchdeck_elevator - int(kwargs['pitchdeck_elevator'])
|
|
user_data.pitchdeck_elevator = remain_line
|
|
user_data.save()
|
|
if user_data.pitchdeck_screenplay > 0:
|
|
remain_char = user_data.pitchdeck_screenplay - int(kwargs['pitchdeck_screenplay'])
|
|
user_data.pitchdeck_screenplay = remain_char
|
|
user_data.save()
|
|
return("updated_pitchdeck",user_data)
|
|
|
|
def update_audit(user_data,service_data, **kwargs):
|
|
user_data.audit_pages += kwargs['audit_pages']
|
|
user_data.save()
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
@api_view(["GET", "DELETE", "POST", "PUT", "PATCH"])
|
|
# @authentication_classes([JWTAuthentication])
|
|
# @permission_classes([IsAuthenticated])
|
|
def juggernautapi(request,pk=None):
|
|
if request.method == "GET":
|
|
if pk is not None:
|
|
main = JuggernautPackage.objects.all().filter(user_id=pk)
|
|
serializer = JuggernautPackageSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
main = JuggernautPackage.objects.all()
|
|
serializer = JuggernautPackageSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
if request.method == "POST":
|
|
serializer = JuggernautPackageSerializer(data=request.data)
|
|
if serializer.is_valid():
|
|
serializer.save()
|
|
return Response("data created")
|
|
return Response(serializer.errors)
|
|
if request.method == "PUT":
|
|
main = JuggernautPackage.objects.get(id=pk)
|
|
serializer = JuggernautPackageSerializer(main, data=request.data)
|
|
if serializer.is_valid():
|
|
serializer.save()
|
|
return Response("complete data updated")
|
|
return Response(serializer.errors)
|
|
if request.method == "PATCH":
|
|
main = JuggernautPackage.objects.get(id=pk)
|
|
serializer = JuggernautPackageSerializer(main, data=request.data, partial=True)
|
|
if serializer.is_valid():
|
|
serializer.save()
|
|
return Response("partial data updated")
|
|
return Response(serializer.errors)
|
|
if request.method == "DELETE":
|
|
if id is not None:
|
|
main = JuggernautPackage.objects.filter(id=pk)
|
|
# else:
|
|
# main = MemberProfile.objects.filter(projectid=pk)
|
|
main.delete()
|
|
return Response("data deleted")
|
|
|
|
@api_view(["GET"])
|
|
def juggernaut_project_center_api(request,pk=None):
|
|
if request.method == "GET":
|
|
if pk is not None:
|
|
main = JuggernautProjectCenter.objects.all().filter(package=pk)
|
|
serializer = JuggernautProjectCenterSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
main = JuggernautProjectCenter.objects.all()
|
|
serializer = JuggernautProjectCenterSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
|
|
@api_view(["GET"])
|
|
def juggernaut_narration_api(request,pk=None):
|
|
if request.method == "GET":
|
|
if pk is not None:
|
|
main = JuggernautNarration.objects.all().filter(project_name=pk)
|
|
serializer = JuggernautNarrationSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
main = JuggernautNarration.objects.all()
|
|
serializer = JuggernautNarrationSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
|
|
|
|
@api_view(["GET"])
|
|
def juggernaut_pitchdeck_api(request,pk=None):
|
|
if request.method == "GET":
|
|
if pk is not None:
|
|
main = JuggernautPitchdeck.objects.all().filter(project_name=pk)
|
|
serializer = JuggernautPitchdeckSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
main = JuggernautPitchdeck.objects.all()
|
|
serializer = JuggernautPitchdeckSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
|
|
@api_view(["GET"])
|
|
def juggernaut_conversion_api(request,pk=None):
|
|
if request.method == "GET":
|
|
if pk is not None:
|
|
main = JuggernautConversion.objects.all().filter(package=pk)
|
|
serializer = JuggernautConversionSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
main = JuggernautConversion.objects.all()
|
|
serializer = JuggernautConversionSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
|
|
@api_view(["GET"])
|
|
def juggernaut_subtitle_api(request,pk=None):
|
|
if request.method == "GET":
|
|
if pk is not None:
|
|
main = JuggernautSubtitling.objects.all().filter(package=pk)
|
|
serializer = JuggernautSubtitleSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
main = JuggernautSubtitling.objects.all()
|
|
serializer = JuggernautSubtitleSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
|
|
@api_view(["GET"])
|
|
def juggernaut_beatsheet_api(request,pk=None):
|
|
if request.method == "GET":
|
|
if pk is not None:
|
|
main = JuggernautBeatSheet.objects.all().filter(project_name=pk)
|
|
serializer = JuggernautBeatSheetSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
main = JuggernautBeatSheet.objects.all()
|
|
serializer = JuggernautBeatSheetSerializer(main, many=True)
|
|
return Response(serializer.data)
|
|
|
|
|