Sindbad~EG File Manager

Current Path : /home/numerotech/workshops.numerotech.com/common_workshop_reg/core/controller/
Upload File :
Current File : //home/numerotech/workshops.numerotech.com/common_workshop_reg/core/controller/OfflineController.py

from flask import Flask, request, Blueprint, jsonify, redirect, url_for,flash, render_template,session,Response,jsonify,json
from core.model.BOModel import BOModel
from core.model.UserModel import UserModel

from core.model.OfflineModel import OfflineModel
from random import randint
from .. import Cryptography,Auth,RouteGroup,Helper,Custom,AWSUpload
import datetime
from core.library.email import EMAIL
import math
from datetime import timedelta,date,datetime
from flask import session, app
from os import listdir
import io

import ast
import requests,mandrill,json,math
import flask

from werkzeug.utils import secure_filename
import boto3, botocore
from botocore.exceptions import ClientError

import webbrowser
import os #use for new instance of chrome
import urllib.parse


app = Blueprint('offline', __name__)


'''------------------------ Offine Registartion in Back Office Start ----------------------------------------'''
@app.route('/<int:conf_id>/<conf_key>/bo/offline_registration', methods = [ "GET","POST"])
@RouteGroup.conf_required
@RouteGroup.bologin_required
def BoDelegate(conf_id,conf_key):
	now              = datetime.now()
	curr_dt       = now.strftime("%Y-%m-%d %H:%M:%S")
	conf 			 = Auth.getConf(conf_id,conf_key)
	
	society_id       = conf['society_id']
	parent_user_id   = Auth.user(society_id)['user_id']
	user_id          = request.values.get('user_id',0)
	# parent_user_id  = request.values.get('parent_user_id',0)
	delegate_id      = request.values.get('delegate_id',0)
	is_custom_addons = 1
	state_id         = UserModel().get_states()  
	country_id       = UserModel().get_country()
	reg_types        = BOModel().get_addon_reg_type(conf_id)
	addons           = BOModel().get_addonsBOModel(delegate_id,curr_dt,conf_id,None,is_custom_addons)
	parent_user      = UserModel().get_user(parent_user_id,society_id,conf_id)
	badge_role       = BOModel().get_badge_model(conf_id)
	
	user = None
	if int(str(user_id),0) > 0:
		user            = UserModel().get_user(user_id,society_id,conf_id)
	delegate = None
	if int(str(delegate_id),0) >0:  
		delegate   = UserModel().get_delegate(delegate_id)

	if delegate is None:
		if user:
			delegate = user

	incompleted_template    = Offlineget_parent_incompleted_delegates(parent_user_id,conf_id,conf_key)
	return render_template('offlines/non_member_register_page.html',user_id=user_id,states=state_id,countries=country_id,delegate=delegate,parent_user_id=parent_user_id,reg_types=reg_types,addons=addons,str=str,type=type,conf=conf,incompleted_template=incompleted_template,badge_role=badge_role)
		

@app.route('/bo/check_self_reg', methods = [ "GET","POST"])
def check_self_reg():
	user_id         = request.values.get('user_id',0)
	society_id      = request.values.get('society_id')
	check_user_del  = BOModel().check_user_delegate(user_id,society_id)
	return str(check_user_del)


@app.route('/<int:conf_id>/<conf_key>/bo/selected_member', methods = [ "POST"])
def BoSelectedMember(conf_id,conf_key):
	now              = datetime.now()
	curr_dt       = now.strftime("%Y-%m-%d %H:%M:%S")
	conf             = Auth.getConf(conf_id,conf_key)
	
	# conf            = BOModel().get_conf(conf_id,conf_key)
	society_id       = conf['society_id']
	user_id          = request.values.get('user_id',0)
	parent_user_id   = request.values.get('parent_user_id',0)
	delegate_id      = request.values.get('delegate_id',0)
	data             = UserModel().get_state_country_users_type(user_id,society_id,delegate_id,conf_id,parent_user_id,now)
	is_custom_addons = 1
	addons           = BOModel().get_addonsBOModel(delegate_id,curr_dt,conf_id,None,is_custom_addons)
	badge_role       = BOModel().get_badge_model(conf_id)
	for index,value in enumerate(data):
		if index == 0:
			state_id = value
		if index == 1:
			country_id = value
		if index == 2:
			user = value
		if index == 4:
			reg_types = value
		if index == 6:
			parent_user = value
	if int(str(user_id),0) > 0: #Check user_id greater then 0 
		user        = UserModel().get_user(user_id,society_id,conf_id) # get user details
		if user and user["member_type_id"] == Custom.MemberTypeId or user["member_type_id"] == Custom.AssociateMemberTypeId or user["member_type_id"] in Custom.ASIMemberTypeId or user["member_type_id"] == Custom.NationalMemberTypeId: # check user is member Custom -
			user    = OfflineModel().get_member_details(user_id,curr_dt)
			html_data =  render_template('offlines/non_member_register_page_content.html',delegate=user,states=state_id,countries=country_id,parent_user_id=parent_user_id,reg_types=reg_types,addons=addons,str=str,type=type,conf=conf,badge_role=badge_role)
			data = { "html_data": html_data,"status":1}
			return json.dumps(data,default =str)		
		else:
			html_data = None
			data = { "html_data": html_data,"status":0}
			return json.dumps(data,default =str)
	else:
		return redirect(url_for('back_office.BoRegister',conf_id=conf_id,conf_key=conf_key))
		

@app.route('/<int:conf_id>/<conf_key>/bo/add_delegate', methods = [ "GET","POST"])
@RouteGroup.conf_required
def BoAddDelegate(conf_id,conf_key):
	now         = datetime.now()
	curr_dt     = now.strftime("%Y-%m-%d %H:%M:%S")

	conf = Auth.getConf(conf_id,conf_key)
	if request.method == 'POST':
		conf             = BOModel().get_conf(conf_id,conf_key)
		society_id       = conf['society_id']
		user_id          = request.values.get('user_id',0)
		parent_user_id   = request.values.get('parent_user_id',0)
		delegate_id      = request.values.get('delegate_id',0)
		update           = request.values.get('update',0)
		data             = UserModel().get_state_country_users_type(user_id,society_id,delegate_id,conf_id,parent_user_id,now)
		is_custom_addons = 1
		addons           = BOModel().get_addonsBOModel(delegate_id,curr_dt,conf_id,None,is_custom_addons)
		badge_role       = BOModel().get_badge_model(conf_id)
		for index,value in enumerate(data):
			if index == 0:
				state_id = value
			if index == 1:
				country_id = value
			if index == 2:
				user = value
			if index == 4:
				reg_types = value
			if index == 6:
				parent_user = value

		if int(str(user_id),0) > 0: #Check user_id greater then 0 
			user            = UserModel().get_user(user_id,society_id,conf_id) # get user details
			if user and user["member_type_id"] == Custom.MemberTypeId or user["member_type_id"] == Custom.AssociateMemberTypeId or user["member_type_id"] in Custom.ASIMemberTypeId or user["member_type_id"] == Custom.NationalMemberTypeId: # check user is member Custom -
				user   = OfflineModel().get_member_details(user_id,curr_dt)
				if int(str(delegate_id),0) >0:  
					delegate = UserModel().get_delegate(delegate_id)
					user     = delegate if delegate else user 
				if  user_id == parent_user_id: # if both same then call myself add or edit else add or edit for other 
					return render_template('offlines/non_member_register_page_content.html',user_id=user_id,states=state_id,countries=country_id,delegate=delegate,parent_user_id=parent_user_id,reg_types=reg_types,addons=addons,str=str,type=type,conf=conf,update=update,badge_role=badge_role)
				else:
					return render_template('offlines/non_member_register_page_content.html',user_id=user_id,states=state_id,countries=country_id,delegate=delegate,parent_user_id=parent_user_id,reg_types=reg_types,addons=addons,str=str,type=type,conf=conf,update=update,badge_role=badge_role)          
				
		user = None
		if int(str(user_id),0) > 0:
			user            = UserModel().get_user(user_id,society_id,conf_id)
		delegate = None
		if int(str(delegate_id),0) >0:  
			delegate   = UserModel().get_delegate(delegate_id)

		if delegate is None:
			if user:
				delegate = user         
		return render_template('offlines/non_member_register_page_content.html',user_id=user_id,states=state_id,countries=country_id,delegate=delegate,parent_user_id=parent_user_id,reg_types=reg_types,addons=addons,str=str,type=type,conf=conf,update=update,badge_role=badge_role)
	else :
		return redirect(url_for('back_office.BoRegister',conf_id=conf_id,conf_key=conf_key))
		
@app.route('/<int:conf_id>/<conf_key>/bo/edit_delegate', methods = [ "GET","POST"])
@RouteGroup.conf_required
def BoEditDelegate(conf_id,conf_key):
	conf             = Auth.getConf(conf_id,conf_key)
	now              = datetime.now()
	curr_dt     = now.strftime("%Y-%m-%d %H:%M:%S")
	# conf            = BOModel().get_conf(conf_id,conf_key)
	society_id       = conf['society_id']
	user_id          = request.values.get('user_id',0)
	parent_user_id   = request.values.get('parent_user_id',0)
	delegate_id      = request.values.get('delegate_id',0)
	del_status_id    = request.values.get('del_status_id')
	data             = UserModel().get_state_country_users_type(user_id,society_id,delegate_id,conf_id,parent_user_id,now)
	is_custom_addons = 1
	addons           = BOModel().get_addonsBOModel(delegate_id,curr_dt,conf_id,None,is_custom_addons)
	badge_role       = BOModel().get_badge_model(conf_id)
	for index,value in enumerate(data):
		if index == 0:
			state_id = value
		if index == 1:
			country_id = value
		if index == 2:
			user = value
		if index == 4:
			reg_types = value
		if index == 6:
			parent_user = value

	if int(str(user_id),0) > 0: #Check user_id greater then 0 
		user            = UserModel().get_user(user_id,society_id,conf_id) # get user details
		if user and user["member_type_id"] == Custom.MemberTypeId or user["member_type_id"] == Custom.AssociateMemberTypeId or user["member_type_id"] in Custom.ASIMemberTypeId or user["member_type_id"] == Custom.NationalMemberTypeId: # check user is member Custom -
			user   = OfflineModel().get_member_details(user_id,curr_dt)
			if int(str(delegate_id),0) >0:  
				delegate = UserModel().get_delegate(delegate_id)
				user     = delegate if delegate else user 
			if  user_id == parent_user_id: # if both same then call myself add or edit else add or edit for other 
				return render_template('backoffice_user/delegate_registration/edit_index_page_member.html',user_id=user_id,states=state_id,countries=country_id,delegate=delegate,parent_user_id=parent_user_id,reg_types=reg_types,addons=addons,str=str,type=type,conf=conf,del_status_id=del_status_id,badge_role=badge_role)
			else:
				return render_template('backoffice_user/delegate_registration/edit_index_page_member.html',user_id=user_id,states=state_id,countries=country_id,delegate=delegate,parent_user_id=parent_user_id,reg_types=reg_types,addons=addons,str=str,type=type,conf=conf,del_status_id=del_status_id,badge_role=badge_role)            

	user = None
	if int(str(user_id),0) > 0:
		user            = UserModel().get_user(user_id,society_id,conf_id)
	delegate = None
	if int(str(delegate_id),0) >0:  
		delegate   = UserModel().get_delegate(delegate_id)

	if delegate is None:
		if user:
			delegate = user
	return render_template('backoffice_user/delegate_registration/edit_index_page_member.html',user_id=user_id,states=state_id,countries=country_id,delegate=delegate,parent_user_id=parent_user_id,reg_types=reg_types,addons=addons,str=str,type=type,conf=conf,del_status_id=del_status_id,badge_role=badge_role)


@app.route('/<int:conf_id>/<conf_key>/bo/delete_delegate', methods = [ "GET","POST"])
@RouteGroup.conf_required
def BoDeleteDelegate(conf_id,conf_key):
	conf            = Auth.getConf(conf_id,conf_key)
	delegate_id     = request.values.get('delegate_id',0)
	parent_user_id  = request.values.get('parent_user_id',0)
	if int(str(delegate_id)) > 0:
		BOModel().delete_delegate(delegate_id)
		incompleted_template =  Offlineget_parent_incompleted_delegates(parent_user_id,conf_id,conf_key)

		json={ 'msg':'Deleted Successfully','status':1,'incompleted_template':incompleted_template}
	
	else:
		json={ 'msg':'Error try after some time','status':1,'data': ''}
	return jsonify(json)



@app.route('/<int:conf_id>/<conf_key>/bo/search_user', methods = ["GET", "POST"])
@RouteGroup.conf_required
def BoGetSearchUser(conf_id,conf_key):
	conf = Auth.getConf(conf_id,conf_key)
	if request.method == 'POST':
		conf       = BOModel().get_conf(conf_id,conf_key)
		society_id = conf['society_id']
		search     = request.values.get('search')
		user_id    = request.form['user_id']
		user       = UserModel().get_search_user(search,society_id,conf_id)
		if user == None:
			html = None
		else:   
			html = render_template('backoffice_user/delegate_registration/search_table.html' , user_data= user,conf_id=conf_id,conf_key=conf_key)
		return json.dumps(html ,default=str)
	else:
		return redirect(url_for('back_office.BoRegister',conf_id=conf_id,conf_key=conf_key))    


@app.route('/<int:conf_id>/<conf_key>/bo/bo_post_add_register', methods = ["POST"])
@RouteGroup.conf_required
def BoPostAddRegister(conf_id,conf_key):
	now             = datetime.now()
	curr_dt         = now.strftime("%Y-%m-%d %H:%M:%S")
	conf            = Auth.getConf(conf_id,conf_key)
	pg_cert_path    = None
	pg_cert_name    = None	
	file            = None
	file_upload     = None # For upload certificates in delegates table # Added by Ganesan J
	is_file_upload  = 0
	msg             = ""
	status          = 1
	data            = ""
	delegate_id     = request.form['delegate_id'] or None  
	parent_user_id  = request.form['parent_user_id'] 
	user_id         = request.form['user_id']
	conf_id         = request.form['conf_id']
	conf_key        = request.form['conf_key']
	# conf          = BOModel().get_conf(conf_id,conf_key)
	society_id      = conf['society_id']
	dt_string       = now.strftime("%Y-%m-%d %H:%M:%S")
	prefix          = request.form['prefix'] or None
	full_name       = request.form['full_name'] or None
	email           = request.form['email'] 
	mobile          = request.form['mobile']
	date_of_birth   = request.form['dob'] or None
	if date_of_birth:
		try:
			dob     = datetime.strptime(date_of_birth, '%d-%m-%Y')
		except Exception as e:
			dob     = None
	else:
		dob         = None
	gender          = request.form['gender'] or None
	address1        = request.form['address1'] or None
	address2        = request.form['address2'] or None
	address3        = request.form['address3'] or None
	city            = request.form['city'] or None
	pincode         = request.form['pincode'] or None
	state_id        = request.form['state_id'] or None
	country_id      = request.form['country_id'] or None
	mc_number       = request.form['mc_number'] or None
	mc_state_id     = request.form['mc_state_id'] or None
	membership_no   = request.form['membership_no'] or None
	role   	        = request.form['role'] or None
	
	if role :
		if "_" in  role :
			role_1	= role.split("_")
			role    = role_1[0]
			range_1 = role_1[1]
		else :
			role = "DELEGATE"
			range_1 = 1

	check_in_date   = request.values.get('check_in_date') or None
	check_out_date  = request.values.get('check_out_date') or None
	check_in_time   = request.values.get('check_in_time') or None
	check_out_time  = request.values.get('check_out_time') or None
	designation     = request.values.get('designation') or None
	institution     = request.values.get('institution') or None
	nationality     = request.values.get('nationality') or None
	accom_persons   = request.values.get("accom_persons" or None)
	delegate_remarks= request.form['delegate_remarks'] or None
	is_take_part_bpw= request.values.get('is_take_part_bpw') or None
	mem_applied_at  = request.values.get('mem_applied_at') or None
	mem_is_applied  = request.values.get('mem_is_applied') or None
	mem_year        = request.values.get('mem_year') or None
	food            = request.values.get('food') or None
	age             = request.values.get('age') or None
	user_type_id    = None
	district        = request.values.get('district') or None
	
	place_of_work    = request.values.get('place_of_work') or None	
	institution      = request.values.get('institution') or None
	
	# Delegate Image
	image_data           = request.values.get('delegate_image_base64',None) or None
	image_data_ext       = request.values.get('delegate_image_ext') or None
	is_remove_del_img    = request.values.get('is_remove_del_img') or 0
	
	
	if int(user_id) > 0:
		member_type_id = request.form['member_type_id'] or None
	else:
		member_type_id = 2
	conference_id     = conf_id
	time_set          = request.form['time_set'] or None
	conf_id           = conf_id
	reg_types         = BOModel().get_addon_reg_type(conf_id)
	addons            = BOModel().get_addonsBOModel(delegate_id,curr_dt,conf_id)
	reg_addons        = {} 
	insert_del_addons = []
	delete_del_addons = [] 

	created_at_date   = {'created_at': dt_string}
	updated_at_date   = {'updated_at': dt_string}

	for addon in addons:
		reg_addons[addon["addon_id"]] = addon
		#collect all delegate_addon_id for delegate 
		if addon["delegate_addon_id"]  and addon["delegate_addon_id"] > 0:
			delete_del_addons.append(addon["delegate_addon_id"])

	is_mandatory = {}
	for rt in reg_types:
		is_mandatory[rt['addon_type_id']]   =  rt['is_mandatory']
		values = request.values.getlist(rt.get('input_name'))
		if values:
			is_mandatory[rt['addon_type_id']] = 0
			for val in values:
				addon_id     = val
				addon        = reg_addons[int(val)]
				if rt['addon_type_id'] == 1 :
					user_type_id = addon.get("user_type_id")
					
				if  addon.get("delegate_addon_id") and addon.get("delegate_addon_id") > 0 and request.form['addon_amount_'+val] == addon.get("amount"):
					#if already have addon and deleate not change the addon then we removed delegate_addon_id in delete_addons variable
					delete_del_addons.remove(addon.get("delegate_addon_id")) 
				else:   
					add_data = {
								 "addon_id"         : val,
								 "amount"           : request.form['addon_amount_'+val] or addon.get("amount",0),
								 "original_amount"  : request.form['addon_amount_'+val] or addon.get("amount",0),
								 "reg_status"       : 0      
					}
					insert_del_addons.append(add_data)

	# TNASICON 2023	
	if conf_id and int(conf_id) in [19] :
		if addon_id:
			if int(addon_id) in [223,377,378,379]:
				file  = request.files.get('files_asi',None)	
				if file:
					image_name  = "tnasicon2023_asipayment_proof_"
					foldername  = ""
					is_file_upload = 1
	
	# IAP KARNATAKA 2023,SZTNAOI 2023
	if conf_id and int(conf_id) in [32,36,8] :
		file  = request.files.get('files',None)	
		if file:
			image_name     = "certificate_proof_"
			foldername     = ""
			is_file_upload = 1	

	 # MEDITER RETINA CLUB 2023 
	if conf_id and int(conf_id) == 37 :
		if addon_id:
			if int(addon_id) in [553,554,557,559,561,562,565,567,571,573,575,576]:
				file  = request.files.get('files',None)
				if file:
					image_name     = "certificate_proof_"
					foldername     = ""
					is_file_upload = 1	

	# IPGS 2023	
	if conf_id and int(conf_id) == 29 :
		if addon_id:
			if int(addon_id) in [365,373,369]:
				file  = request.files.get('files_', None)
				if file:
					image_name     = "certificate_proof_"
					foldername     = ""
					is_file_upload = 1


	if int(is_file_upload) == 1:
		file_upload = AWSUpload().AwsFileUpload(user_id,file,image_name,foldername)
	else:
		file_upload = ''

	# If  file upload function call then this block will execute					
	if  file_upload :
		file_upload = ast.literal_eval(file_upload)
		file_upload_msg    = file_upload["msg"]
		file_upload_status = file_upload["status"]
		if file_upload_status  == 1 :
			pg_cert_path    = file_upload["pg_cert_path"] or None
			pg_cert_name    = file_upload["pg_cert_name"] or None
		else :
			return file_upload_msg					
	
	# if conf_id and int(conf_id) == 19 :
	# 	if addon_id:
	# 		if int(addon_id) in [223,377,378,379]:
	# 			file  = request.files.get('files_asi',None)				
	# 			pg_cert_path = None
	# 			pg_cert_name = None
	# 			if file.filename:
	# 				filename        = secure_filename(file.filename)
	# 				split_tup       = os.path.splitext(filename)
	# 				file_name       = split_tup[0]
	# 				file_extension  = split_tup[1]
	# 				file_str        = "tnasicon2023_asipayment_proof_"+ datetime.now().strftime("%Y%m%d-%H%M%S") +file_extension
	# 				if " " in file_str :
	# 					file_str = file_str.replace(" ","")
	# 				try:
	# 					bucket     = "delegateapp"
	# 					user_id    = str(user_id)
	# 					foldername = ""
	# 					acl            ="public-read"
	# 					s3             = boto3.client("s3",aws_access_key_id='AKIAILLDAQ7NFUMVOYLQ',aws_secret_access_key='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')
	# 					response   = s3.upload_fileobj(file, bucket,foldername + file_str, ExtraArgs={"ACL": acl,"ContentType": file.content_type})
	# 					data_1     = {'bucketname' : bucket,'foldername':foldername,'file_name':file_str+"?"+str(Helper.getcurrenttimestamp()),'msg':'Image successfully uploded','file_extension':file_extension,'status':1} 
	# 					file_path  = "https://delegateapp.s3.ap-southeast-1.amazonaws.com/"+foldername
		
	# 					pg_cert_path = file_path
	# 					pg_cert_name = file_str
		
						
	# 				except ClientError as e:
	# 					print(str(e))
	# 					# logging.error(e)
	# 					# data_1      = {'msg':'Image upload failed .Please try again.','status':0}        
	# 					# json_data   = json.dumps(data_1)
	# 					# return json_data
	# 					return str(e)
	# 					# flash('Something Error .Please Try Again')				

	# if conf_id and int(conf_id) in [32,36] :
	# 	file  = request.files.get('files',None)				
	
	# 	pg_cert_path = None
	# 	pg_cert_name = None
	# 	if file.filename:
	# 		filename        = secure_filename(file.filename)
	# 		split_tup       = os.path.splitext(filename)
	# 		file_name       = split_tup[0]
	# 		file_extension  = split_tup[1]
	# 		file_str        = "certificate_proof_"+ datetime.now().strftime("%Y%m%d-%H%M%S") +file_extension
	# 		if " " in file_str :
	# 			file_str = file_str.replace(" ","")
	# 		try:
	# 			bucket     = "delegateapp"
	# 			user_id    = str(user_id)
	# 			foldername = ""
	# 			acl            ="public-read"
	# 			s3             = boto3.client("s3",aws_access_key_id='AKIAILLDAQ7NFUMVOYLQ',aws_secret_access_key='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')
	# 			response   = s3.upload_fileobj(file, bucket,foldername + file_str, ExtraArgs={"ACL": acl,"ContentType": file.content_type})
	# 			data_1     = {'bucketname' : bucket,'foldername':foldername,'file_name':file_str+"?"+str(Helper.getcurrenttimestamp()),'msg':'Image successfully uploded','file_extension':file_extension,'status':1} 
	# 			file_path  = "https://delegateapp.s3.ap-southeast-1.amazonaws.com/"+foldername

	# 			pg_cert_path = file_path
	# 			pg_cert_name = file_str

				
	# 		except ClientError as e:
	# 			print(str(e))
	# 			# logging.error(e)
	# 			# data_1      = {'msg':'Image upload failed .Please try again.','status':0}        
	# 			# json_data   = json.dumps(data_1)
	# 			# return json_data
	# 			return str(e)
	# 			# flash('Something Error .Please Try Again')
				
	# # MEDITERRETINA 2023
	
	# if conf_id and int(conf_id) == 37 :
	# 	if addon_id:
	# 		if int(addon_id) in [553,554,557,559,561,562,565,567,571,573,575,576]:
	# 			file  = request.files.get('files',None)				
			
	# 			pg_cert_path = None
	# 			pg_cert_name = None

	# 			if file.filename:
	# 				filename        = secure_filename(file.filename)
	# 				split_tup       = os.path.splitext(filename)
	# 				file_name       = split_tup[0]
	# 				file_extension  = split_tup[1]
	# 				file_str        = "certificate_proof_"+ datetime.now().strftime("%Y%m%d-%H%M%S") +file_extension
	# 				if " " in file_str :
	# 					file_str = file_str.replace(" ","")
	# 				try:
	# 					bucket     = "delegateapp"
	# 					user_id    = str(user_id)
	# 					foldername = ""
	# 					acl        = "public-read"
	# 					s3         = boto3.client("s3",aws_access_key_id='AKIAILLDAQ7NFUMVOYLQ',aws_secret_access_key='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')
	# 					response   = s3.upload_fileobj(file, bucket,foldername + file_str, ExtraArgs={"ACL": acl,"ContentType": file.content_type})
	# 					data_1     = {'bucketname' : bucket,'foldername':foldername,'file_name':file_str+"?"+str(Helper.getcurrenttimestamp()),'msg':'Image successfully uploded','file_extension':file_extension,'status':1} 
	# 					file_path  = "https://delegateapp.s3.ap-southeast-1.amazonaws.com/"+foldername

	# 					pg_cert_path = file_path
	# 					pg_cert_name = file_str

						
	# 				except ClientError as e:
	# 					print(str(e))
	# 					# logging.error(e)
	# 					# data_1      = {'msg':'Image upload failed .Please try again.','status':0}        
	# 					# json_data   = json.dumps(data_1)
	# 					# return json_data
	# 					return str(e)
	# 					# flash('Something Error .Please Try Again')			
				

	# if conf_id and int(conf_id) == 29 :
	# 	if addon_id:
	# 		if int(addon_id) in [365,373,369]:
				
	# 			file  = request.files.get('files_', None)
	# 			pg_cert_path = None
	# 			pg_cert_name = None	

				
	# 			if file.filename:
	# 				filename        = secure_filename(file.filename)
	# 				split_tup       = os.path.splitext(filename)
	# 				file_name       = split_tup[0]
	# 				file_extension  = split_tup[1]
	# 				file_str        = "certificate_proof_"+ datetime.now().strftime("%Y%m%d-%H%M%S") +file_extension
	# 				if " " in file_str :
	# 					file_str = file_str.replace(" ","")
	# 				try:
	# 					bucket     = "delegateapp"
	# 					user_id    = str(user_id)
	# 					foldername = ""
	# 					acl            ="public-read"
	# 					s3             = boto3.client("s3",aws_access_key_id='AKIAILLDAQ7NFUMVOYLQ',aws_secret_access_key='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')
	# 					response   = s3.upload_fileobj(file, bucket,foldername + file_str, ExtraArgs={"ACL": acl,"ContentType": file.content_type})
	# 					data_1     = {'bucketname' : bucket,'foldername':foldername,'file_name':file_str+"?"+str(Helper.getcurrenttimestamp()),'msg':'Image successfully uploded','file_extension':file_extension,'status':1} 
	# 					file_path  = "https://delegateapp.s3.ap-southeast-1.amazonaws.com/"+foldername
	
	# 					pg_cert_path = file_path
	# 					pg_cert_name = file_str
	
						
	# 				except ClientError as e:
	# 					print(str(e))
	# 					# logging.error(e)
	# 					# data_1      = {'msg':'Image upload failed .Please try again.','status':0}        
	# 					# json_data   = json.dumps(data_1)
	# 					# return json_data
	# 					return str(e)
	# 					# flash('Something Error .Please Try Again')	

	# extra input fields

	reg_Validation = []         
	for key in is_mandatory:
		if is_mandatory[key] == 1:
			reg_Validation.append({'key': key ,'msg': "following field is mandatory."})  
			status = 0;

	del_data = {
				'parent_user_id': parent_user_id,
				'prefix'        : prefix,
				'user_id'       : user_id if int(user_id) >0 else None,
				'full_name'     : full_name,
				'email'         : email,
				'mobile'        : mobile,
				'dob'           : dob,
				'gender'        : gender,
				'address1'      : address1,
				'address2'      : address2,
				'address3'      : address3,
				'city'          : city,
				'pincode'       : pincode,
				'state_id'      : state_id,
				'country_id'    : country_id,
				'mc_number'     : mc_number,
				'mc_state_id'   : mc_state_id,
				'conference_id' : conference_id,
				'membership_no' : membership_no,
				'member_type_id': member_type_id,
				'admin_user_id' : parent_user_id,
				'society_id'    : society_id,
				'is_offline'    : 1,
				'd_is_kit'      : 1,
				'role'		    : role,
				'check_in_date' : check_in_date,
				'check_out_date': check_out_date,
				'check_in_time' : check_in_time,
				'check_out_time': check_out_time,
				'designation'	: designation,
				'institution'	: institution,
				'nationality'	: nationality,
				'accom_persons' : accom_persons,
				'delegate_remarks': delegate_remarks,
				'is_take_part_bpw':is_take_part_bpw,
				'district'        : district,
				# extra input fields
				'mem_is_applied'  : mem_is_applied,
				'mem_applied_at'  : mem_applied_at,
				'mem_year' 		  : mem_year,
				'age'      		  : age,
				'food'     		  : food,
				'reg_type_id'     : user_type_id,
				'del_status_id'	  : 0,
				'institution'     : institution,
				'place_of_work'   : place_of_work
			}
	
	cert_proof_deleted = request.values.get('cert_proof_deleted') or 0
	asi_proof_deleted = request.values.get('asi_proof_deleted') or 0
	res_proof_deleted = request.values.get('res_proof_deleted_') or 0

	if conf_id and int(conf_id) in [32,36,8] :
		if pg_cert_path  or int(cert_proof_deleted) == 1:
			del_data['pg_cert_path'] = pg_cert_path
		if pg_cert_name  or int(cert_proof_deleted) == 1:	
			del_data['pg_cert_name'] = pg_cert_name
	
	if conf_id and int(conf_id) == 19 :
		if addon_id:
			if int(addon_id) in [223,377,378,379]:
				if pg_cert_path  or int(asi_proof_deleted) == 1:
					del_data['pg_cert_path'] = pg_cert_path
				if pg_cert_name  or int(asi_proof_deleted) == 1:	
					del_data['pg_cert_name'] = pg_cert_name		
					
			
	if conf_id and int(conf_id)== 29 :
		if addon_id:
			if int(addon_id) in [365,373,369]:
				if pg_cert_path  or int(res_proof_deleted) == 1:
					del_data['pg_cert_path'] = pg_cert_path
				if pg_cert_name  or int(res_proof_deleted) == 1:	
					del_data['pg_cert_name'] = pg_cert_name
			else:
				del_data['pg_cert_path'] = None
				del_data['pg_cert_name'] = None	
				
	if conf_id and int(conf_id) == 37 :
		if addon_id:
			if int(addon_id) in [553,554,557,559,561,562,565,567,571,573,575,576]:
				if pg_cert_path  or int(cert_proof_deleted) == 1:
					del_data['pg_cert_path'] = pg_cert_path
				if pg_cert_name  or int(cert_proof_deleted) == 1:	
					del_data['pg_cert_name'] = pg_cert_name
			else:
				del_data['pg_cert_path'] = None
				del_data['pg_cert_name'] = None				
	
	if int(time_set) == 0:
		del_data.update(created_at_date)
	else:
		del_data.update(updated_at_date) 

	if int(delegate_id) > 0:
		delegate     = UserModel().get_delegate(delegate_id)
		if delegate:
			if delegate['delegate_no'] and delegate['delegate_no'] >0:
				delegate_id     = BOModel().insert_delegate(del_data)
				if image_data:
					AWSUpload().DelegateImageUpload(delegate_id,full_name,image_data,conf_key,image_data_ext)
				else :
					if int(is_remove_del_img) == 1: 
						AWSUpload().DeleteDelegateImage(delegate_id,conf_key)
				BOModel().save_delegates_addons(delegate_id,insert_del_addons,delete_del_addons,now)

				incompleted_template = Offlineget_parent_incompleted_delegates(parent_user_id,conf_id,conf_key)
				data={ 'msg':'Add Successfully','status':1,'incompleted_template':incompleted_template}
				return jsonify(data)
		else:
			status = 0
			msg    = "your request cannot be processed. click here to try after some time"


		if status == 1:
			update        = BOModel().update_delegate(delegate_id,del_data,None,conf_id)
			if image_data:
				AWSUpload().DelegateImageUpload(delegate_id,full_name,image_data,conf_key,image_data_ext)
			else :
				if int(is_remove_del_img) == 1: 
					AWSUpload().DeleteDelegateImage(delegate_id,conf_key)
			BOModel().save_delegates_addons(delegate_id,insert_del_addons,delete_del_addons,now)
		json = { 
				'msg':'Update completed ...',
				'status':status,
				'incompleted_template' : Offlineget_parent_incompleted_delegates(parent_user_id,conf_id,conf_key),
				 'reg_validation' :  reg_Validation
			}
		return jsonify(json)    
	else:
		existing_data = None
		if int(user_id) > 0 :
			existing_data       = UserModel().get_check_exsits_delegate(user_id,parent_user_id,conf_id)
			
		if existing_data:
			delegate_no  = existing_data["delegate_no"]

			if delegate_no and delegate_no > 0 :
				delegate_id     = BOModel().insert_delegate(del_data)
				if image_data:
					AWSUpload().DelegateImageUpload(delegate_id,full_name,image_data,conf_key,image_data_ext)
				else :
					if int(is_remove_del_img) == 1: 
						AWSUpload().DeleteDelegateImage(delegate_id,conf_key)
				BOModel().save_delegates_addons(delegate_id,insert_del_addons,delete_del_addons,now)

				incompleted_template = Offlineget_parent_incompleted_delegates(parent_user_id,conf_id,conf_key)
				data={ 'msg':'Add Successfully','status':1,'incompleted_template':incompleted_template}
				return jsonify(data)
				
			else:
				# Already registered block .So is_mandatory is removed.
				delegate_id     = BOModel().insert_delegate(del_data)
				if image_data:
					AWSUpload().DelegateImageUpload(delegate_id,full_name,image_data,conf_key,image_data_ext)
				else :
					if int(is_remove_del_img) == 1: 
						AWSUpload().DeleteDelegateImage(delegate_id,conf_key)
				BOModel().save_delegates_addons(delegate_id,insert_del_addons,delete_del_addons,now)

				incompleted_template = Offlineget_parent_incompleted_delegates(parent_user_id,conf_id,conf_key)
				data={ 'msg':'Add Successfully','status':1,'incompleted_template':incompleted_template}
				return jsonify(data)
		else:   
			if status == 1:
				delegate_id     = BOModel().insert_delegate(del_data)
				if image_data:
					AWSUpload().DelegateImageUpload(delegate_id,full_name,image_data,conf_key,image_data_ext)
				else :
					if int(is_remove_del_img) == 1: 
						AWSUpload().DeleteDelegateImage(delegate_id,conf_key)
				BOModel().save_delegates_addons(delegate_id,insert_del_addons,delete_del_addons,now)

				incompleted_template = Offlineget_parent_incompleted_delegates(parent_user_id,conf_id,conf_key)
				data={ 'msg':'Add Successfully','status':1,'incompleted_template':incompleted_template}
				return jsonify(data)
			else:
				data= { 'msg':'','status':0,'data':'','reg_validation' :  reg_Validation}
				return jsonify(data)
					

'''-----------landing page  end-----------'''
@app.route('/<int:conf_id>/<conf_key>/<parent_user_id>/offline_get_parent_incompleted_delegates', methods = ["GET", "POST"])
def Offlineget_parent_incompleted_delegates(parent_user_id,conf_id,conf_key):
	conf          = Auth.getConf(conf_id,conf_key)
	unique_id     = None
	society_id    = conf['society_id']
	payment_types = BOModel().get_payment_types(conf_id)
	delegateData  = BOModel().get_course_incompleted_delegates_by_parent_user_id(parent_user_id,unique_id,conf_id,reg_mode=1)
	if delegateData:
		total_amount = 0
		for index , value in enumerate(delegateData):
			total_amount = total_amount + (value['total_amt'] if value['total_amt'] is not None else 0)
		del_html_data = render_template('offlines/incompleted_information.html' ,user_data = delegateData,user_id = parent_user_id,conf_id =conf_id,conf_key=conf_key,total_amount=total_amount,conf=conf,payment_types=payment_types)
	else:
		del_html_data = ""
	return del_html_data
	

@app.route('/<int:conf_id>/<conf_key>/<parent_user_id>/get_parent_incompleted_delegates_table', methods = ["GET", "POST"])
def get_parent_incompleted_delegates_table(parent_user_id,conf_id,conf_key):
	conf          = Auth.getConf(conf_id,conf_key)
	unique_id     = None
	society_id    = conf['society_id']
	payment_types = BOModel().get_payment_types(conf_id)
	delegateData  = BOModel().get_course_incompleted_delegates_by_parent_user_id(parent_user_id,unique_id,conf_id,reg_mode=1)
	if delegateData:
		total_amount = 0
		for index , value in enumerate(delegateData):
			total_amount = total_amount + (value['total_amt'] if value['total_amt'] is not None else 0)
		del_html_data = render_template('offlines/incompleted_information_table.html' ,user_data = delegateData,user_id = parent_user_id,conf=conf,conf_id =conf_id,conf_key=conf_key,total_amount=total_amount,payment_types=payment_types)
	else:
		del_html_data = ""
	return del_html_data            


@app.route('/<int:conf_id>/<conf_key>/get_total', methods = ["GET","POST"])
def GetTotal(conf_id,conf_key):
	conf                 = Auth.getConf(conf_id,conf_key)
	delegate_ids         = request.form.getlist('delegate[]')
	parent_user_id       = request.values.get('parent_user_id')
	incompleted_template =  Offlineget_parent_incompleted_delegates(parent_user_id,conf_id,conf_key)
	if len(delegate_ids)> 0 :
		if delegate_ids:
			delegate_ids    = str(delegate_ids)
			delegate_ids     = delegate_ids.replace("[" ,"").replace("]","").replace("'","")
			total_amount = BOModel().get_dele(delegate_ids)
			json={ 'status':1,'incompleted_template':incompleted_template,'total_amount':total_amount}
	else:   
		json={ 'status':1,'incompleted_template':incompleted_template,'total_amount':''}
	return jsonify(json)
	


@app.route('/<int:conf_id>/<conf_key>/get_addons_total', methods = ["GET","POST"])
def GetAddonsTotal(conf_id,conf_key):
	conf         = Auth.getConf(conf_id,conf_key)
	addon_ids    = request.form.getlist('addon_id[]')
	delegate_id  = request.form['delegate_id']
	if len(addon_ids)> 0 :
		addon_ids    = str(addon_ids)
		addon_ids     = addon_ids.replace("[" ,"").replace("]","").replace("'","")
		total_amount = BOModel().get_addons_total_amount(addon_ids,delegate_id)
		json={ 'status':1,'total_amount':total_amount}
	else:   
		json={ 'status':1,'total_amount':''}
	return jsonify(json)

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists