Sindbad~EG File Manager
from flask import session
from flask import request, Blueprint, jsonify
from sqlalchemy import create_engine, select, MetaData, Table,text
from sqlalchemy.sql import and_, or_
from core import app
engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class RegdeskModel():
def __init__(self):
try:
self.meta = MetaData()
except Exception as e:
print(e)
def getConfDataForRegdesk(self,regdesk_pin):
with engine.connect() as conn:
stmt = text("SELECT conf_id,conf_name,conf_title,conf_key,username,regdesk_pin,conf_start_time,conf_end_time,del_table_name,is_regdesk_open,signup_table,signup_for_alldays FROM conference where regdesk_pin = "+str(regdesk_pin)+" and is_regdesk_open > 0 order by conf_id desc limit 1;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def delegateData(self,conf_id,del_table_name,signup_for_alldays,signup_table,curr_date):
with engine.connect() as conn:
if signup_for_alldays > 0 :
stmt = text("select d.delegate_id, d.delegate_no,d.role,concat(ifnull(d.prefix , '') , ' ' ,ifnull(d.full_name , '') ) as full_name,d.email,d.mobile,d.city,d.state,d.membership_no,d.mc_number, d.counter,d.batch,s.signed_by,s.comments,min(s.signed_on) as signed_on, min(s.updated_at) as updated_at,d.conf_id,reg_remarks from "+del_table_name+" d "
+" left join "+ signup_table +" s on s.delegate_no = d.delegate_no and d.conf_id = s.conf_id and s.signin_date= '"+curr_date+"' "
+ " where d.conf_id = "+str(conf_id)+" and d.delegate_no > 0 and d.delegate_no is not null and d.role not in ('TRADE','EXHIBITOR','CREW','SUPPORT - IT','SUPPORT - AV', 'GUEST OF HONOR','AV - TEAM','VOLUNTEER', 'Trade Delegate' , 'Crew') group by d.delegate_no order by d.delegate_no asc;")
else :
stmt = text("select d.delegate_id, d.delegate_no,d.role,concat(ifnull(d.prefix , ''), ' ' , ifnull(d.full_name , '') ) as full_name,d.email,d.mobile,d.city,d.state,d.membership_no,d.mc_number, d.counter,d.batch,d.signed_by,d.comments,min(d.signed_on) as signed_on, min(d.updated_at) as updated_at,d.conf_id,reg_remarks from "+del_table_name+" d "
+ " where d.conf_id = "+str(conf_id)+" and d.delegate_no > 0 and d.delegate_no is not null and d.role not in ('TRADE','EXHIBITOR','CREW','SUPPORT - IT','SUPPORT - AV', 'GUEST OF HONOR','AV - TEAM','VOLUNTEER', 'Trade Delegate' , 'Crew') group by d.delegate_no order by d.delegate_no asc;")
# old working fine .
# stmt = text("select d.delegate_id, d.delegate_no,d.role,d.full_name,d.email,d.mobile,d.city,d.state,d.membership_no,d.mc_number, d.counter,d.batch,s.signed_by,s.comments,min(s.signed_on) as signed_on, min(s.updated_at) as updated_at,d.conf_id from "+del_table_name+" d "
# +" left join "+ signup_table +" s on s.delegate_no = d.delegate_no and d.conf_id = s.conf_id "
# + " where d.conf_id = "+str(conf_id)+" and d.delegate_no > 0 and d.delegate_no is not null and d.role not in ('TRADE','EXHIBITOR','CREW','SUPPORT - IT','SUPPORT - AV') group by d.delegate_no order by d.delegate_no asc;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
# get other device signed in records
def getRegdeskSignedData(self,del_table_name,delegate_no_str):
with engine.connect() as conn:
try:
if delegate_no_str :
stmt = text("select * from " +del_table_name+ " where delegate_no not in ("+delegate_no_str+") and device_id !='"+device_id+"' and sync_at is not null ; ")
else :
stmt = text("select * from " +del_table_name+ " where sync_at is not null ; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
except Exception as e:
return str(e)
# Feb 25 2023 ----------------
# call update_android_sync_data(8,1,'delegates_demo', '2023-02-25 23:56:00' ,'DELEGATE', 'TEST','2023-03-07',1,'numerotech_primary_db_conf.signup_demo'); -- use this for checking -- use this for checking
def updateAndGetSignedCountForAndroidSignup(self,conf_id,delegate_no,del_table_name,curr_dt,signed_by,comments,curr_date,signup_for_alldays,signup_table):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
cursor.callproc("android_signin_with_cmescan_mobileapp",[conf_id,delegate_no,del_table_name,curr_dt,signed_by,comments,curr_date,signup_for_alldays,signup_table])
# android_signin_new
# cursor.callproc("update_android_sync_data",[conf_id,delegate_no,del_table_name,curr_dt,signed_by,comments,curr_date,signup_for_alldays,signup_table])
while 1:
names = [c[0] for c in cursor.description]
set_ = []
while 1:
row_raw = cursor.fetchone()
if row_raw is None:
break
row = dict(zip(names, row_raw))
set_.append(row)
sets.append(list(set_))
if cursor.nextset() is None:
break
# nextset() doesn't seem to be sufficiant to tell the end.
if cursor.description is None:
break
cursor.close()
connection.commit()
finally:
connection.commit()
connection.close()
return sets
# Multiple result set
def syncAllDataWithSignedCountForAndroidSignup(self,conf_id,del_table_name,date_1,signup_for_alldays,signup_table):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
#call usp_android_sync_with_signed_count(1, 'delegates_demo','2023-03-07',1,'numerotech_primary_db_conf.signup_demo');
# signup_for_alldays,signup_table,curr_date usp_android_sync_with_signed_count,usp_android_sync_with_signed_count_new
cursor.callproc("usp_android_sync_with_signed_count",[conf_id,del_table_name,date_1,signup_for_alldays,signup_table])
# cursor.callproc("usp_android_sync_with_signed_count",[conf_id,del_table_name,date_1,signup_for_alldays,signup_table])
while 1:
names = [c[0] for c in cursor.description]
set_ = []
while 1:
row_raw = cursor.fetchone()
if row_raw is None:
break
row = dict(zip(names, row_raw))
set_.append(row)
sets.append(list(set_))
if cursor.nextset() is None:
break
# nextset() doesn't seem to be sufficiant to tell the end.
if cursor.description is None:
break
cursor.close()
connection.commit()
finally:
connection.commit() # Updated On jUNE 14, 2023
connection.close()
return sets
# Scanned list only for android Aug 02, 2023
def syncAllDataScannedListOnly(self,conf_id,del_table_name,date_1,signup_for_alldays,signup_table):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_scanned_list_for_android",[conf_id,del_table_name,date_1,signup_for_alldays,signup_table])
while 1:
names = [c[0] for c in cursor.description]
set_ = []
while 1:
row_raw = cursor.fetchone()
if row_raw is None:
break
row = dict(zip(names, row_raw))
set_.append(row)
sets.append(list(set_))
if cursor.nextset() is None:
break
# nextset() doesn't seem to be sufficiant to tell the end.
if cursor.description is None:
break
cursor.close()
connection.commit()
finally:
connection.commit() # Updated On jUNE 14, 2023
connection.close()
return sets
# End
# get confdate
def getConfDates(self,conf_id):
with engine.connect() as conn:
stmt = text("select conf_id,conf_name,date(conf_start_time) as conf_start_time , date(conf_end_time) as conf_end_time from conference where conf_id ="+str(conf_id)+" ; ")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def delegateDatByDatewise(self,conf_id,del_table_name,date_1):
with engine.connect() as conn:
where_con = " "
if date_1 == "All Day" :
where_con = " "
elif date_1 == "Not Collected" :
where_con = where_con + " and signed_on is null "
else :
where_con = where_con + " and signed_on is not null and date(signed_on) = '"+date_1+"' "
stmt = "select delegate_id,delegate_no,role,full_name,email,mobile,city,state,membership_no,mc_number,counter,batch,signed_by,comments,signed_on,updated_at,conf_id from "+del_table_name+" where conf_id = "+str(conf_id)+ " and delegate_no > 0 and delegate_no is not null and role not in ('TRADE','EXHIBITOR','CREW','SUPPORT - IT','SUPPORT - AV','VOLUNTEER','GUEST OF HONOR') "
stmt_2 = stmt + where_con
stmt_3 = text(stmt_2)
result = conn.execute(stmt_3).all()
results = [dict(r._mapping) for r in result] if result else None
return results
# March 08 2023 get overall count
def getOverAllcountRolewise(self,conf_id,del_table_name,date_1,signup_for_alldays,signup_table):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
# usp_android_get_overall_signed_count_new
cursor.callproc("usp_android_get_overall_signed_count",[conf_id,del_table_name,date_1,signup_for_alldays,signup_table])
# cursor.callproc("usp_android_get_overall_signed_count",[conf_id,del_table_name,date_1,signup_for_alldays,signup_table])
while 1:
names = [c[0] for c in cursor.description]
set_ = []
while 1:
row_raw = cursor.fetchone()
if row_raw is None:
break
row = dict(zip(names, row_raw))
set_.append(row)
sets.append(list(set_))
if cursor.nextset() is None:
break
# nextset() doesn't seem to be sufficiant to tell the end.
if cursor.description is None:
break
cursor.close()
connection.commit()
finally:
# Return the connection to the pool (won't actually close).
connection.commit() # Updated On August 30, 2023
connection.close()
return sets
# Ganesan J on June 14 2023
def GetUserForConfAppLogin(self,email,password):
with engine.connect() as conn:
stmt = text("SELECT * FROM users where email = '"+email+"' and password = '"+str(password)+"' and email like '%numerotec.com%';")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def insertUserDevice(self,insert_query):
with engine_conf.connect() as conn:
try:
stmt = text(insert_query)
results = conn.execute(stmt)
conn.commit()
return "success"
except Exception as e:
return str(e)
def unsignupFromMobileApp(self,conf_id,delegate_no,del_table_name,reason,device_type):
connection = engine_conf.raw_connection()
cursor = connection.cursor()
cursor.callproc("unsignup_from_mobileapp",[conf_id,delegate_no,del_table_name,reason,device_type])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
def getSignedCount(self,conf_id,del_table_name):
with engine.connect() as conn:
stmt = text( " SELECT count(*) as signed_count FROM "+ del_table_name + " where conf_id = "+str(conf_id)+" and signed_on is not null ")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
# Remove cme scan record from mobile app
def removeCMEScanRecordFromMobileApp(self,conf_id,delegate_no,del_table_name,reason,device_type,signup_table):
connection = engine_conf.raw_connection()
cursor = connection.cursor()
cursor.callproc("remove_cmescan_from_mobileapp",[conf_id,delegate_no,del_table_name,reason,device_type,signup_table])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
def getCEMSignedCount(self,conf_id,signup_table,date_1):
with engine.connect() as conn:
stmt = text( " SELECT count(*) as signed_count FROM "+ signup_table + " where conf_id = "+str(conf_id)+" and signed_on is not null and signin_date = '"+date_1+"' ")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists