Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from sqlalchemy import text
from core import app
import json
from .. import engine,engine_conf_db,engine_fk_db
# engine = create_engine(app.config['DATABASE_URI'])
# engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class DevelopersSettingModel():
def __init__(self):
try:
self.meta = MetaData()
self.users = Table("users", self.meta, autoload_with=engine)
self.states = Table("states", self.meta, autoload_with=engine)
self.conference = Table("conference", self.meta, autoload_with=engine)
self.user_payment = Table("user_payment", self.meta, autoload_with=engine)
self.user_types = Table("user_types", self.meta, autoload_with=engine)
self.m_payment_type = Table("m_payment_type", self.meta, autoload_with=engine)
self.logs = Table("logs", self.meta, autoload_with=engine)
self.delegates = Table("delegates", self.meta, autoload_with=engine)
self.delegates_addons = Table("delegates_addons", self.meta, autoload_with=engine)
self.admin_logs = Table("admin_logs", self.meta, autoload_with=engine)
self.trigger_daily_reports_mails = Table("trigger_daily_reports_mails", self.meta, autoload_with=engine)
self.export_filter_cols = Table("export_filter_cols", self.meta, autoload_with=engine)
self.badge_role = Table("badge_role", self.meta, autoload_with=engine)
self.society_applications = Table("society_applications", self.meta, autoload_with=engine)
self.delegate_user_logs = Table("delegate_user_logs", self.meta, autoload_with=engine)
self.delegate_attachments = Table("delegate_attachments", self.meta, autoload_with=engine)
self.reg_remark = Table("reg_remark", self.meta, autoload_with=engine)
self.mail_logs = Table("mail_logs", self.meta, autoload_with=engine)
self.del_m_payment_type = Table("del_m_payment_type", self.meta, autoload_with=engine)
self.mail_templates = Table("mail_templates", self.meta, autoload_with=engine)
self.app_style = Table("app_style", self.meta, autoload_with=engine)
self.del_trade_access = Table("del_trade_access", self.meta, autoload_with=engine)
self.admin_access = Table("admin_access", self.meta, autoload_with=engine)
self.map_menu_conf = Table("map_menu_conf", self.meta, autoload_with=engine)
self.m_app_menu = Table("m_app_menu", self.meta, autoload_with=engine)
self.del_conf_content = Table("del_conf_content", self.meta, autoload_with=engine)
except Exception as e:
print("table not found",e)
def get_role(self,conf_id):
with engine.connect() as conn:
stmt = text("select * FROM badge_role where conf_id = "+str(conf_id)+" ; ")
conn = engine.connect()
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_role_by_role_id(self,conf_id,b_role_id):
with engine.connect() as conn:
stmt = text("select * FROM badge_role where conf_id = "+str(conf_id)+" and b_role_id = "+str(b_role_id)+"; ")
conn = engine.connect()
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def delete_role_by_role_id(self,conf_id,b_role_id):
with engine.connect() as conn:
stmt = text("delete from badge_role where conf_id = "+str(conf_id)+" and b_role_id = "+str(b_role_id)+"; ")
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def update_role(self,conf_id,b_role_id,del_data):
with engine.connect() as conn:
conn = engine.connect()
stmt = self.badge_role.update().where(self.badge_role.c.b_role_id.in_([b_role_id])).values(del_data)
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def insert_role(self,conf_id,del_data):
with engine.connect() as conn:
result = conn.execute(self.badge_role.insert(), del_data)
conn.commit()
return "success"
def get_delegate_details_by_del_nos(self,delegate_nos,from_del_no,to_del_no,conf_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_delegate_no_search",[(delegate_nos or None),(from_del_no or None),(to_del_no or None),conf_id])
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()
return results
else :
cursor.close()
connection.commit()
return None
def update_delegate_role(self,conf_id,role,delegate_nos,updated_at,is_gen_number,b_role_id):
with engine.connect() as conn:
if is_gen_number == 'ref_number' :
where_con = " and ref_no in ('"+str(delegate_nos)+"') "
else :
where_con = " and delegate_no in ("+str(delegate_nos)+") "
conn = engine.connect()
stmt = text("update delegates set role = '"+str(role)+"',updated_at = '"+str(updated_at)+"',is_bo_role_update = 1,role_id = "+str(b_role_id)+" where conference_id = "+str(conf_id)+" and del_status_id = 2 "+where_con+" ; ")
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def get_export_columns_is_del(self):
with engine.connect() as conn:
stmt = text("select * from export_filter_cols where is_visible =1 and is_del =1 and orderby is not null order by orderby asc;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def update_export_columns_bulk(self,stmt_1):
with engine.connect() as conn:
stmt2 = text("set sql_safe_updates = 0 ;")
conn.execute(stmt2)
conn.commit()
stmt_1 = text(stmt_1)
result = conn.execute(stmt_1)
conn.commit()
return result
def get_export_col_by_col_id(self,conf_id,cols_id):
with engine.connect() as conn:
stmt = text("select * FROM export_filter_cols where FIND_IN_SET('"+str(conf_id)+"',conf_ids) and is_del = 1 and cols_id = "+str(cols_id)+"; ")
# print(stmt)
conn = engine.connect()
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def update_export_column(self,cols_id,del_data):
with engine.connect() as conn:
conn = engine.connect()
stmt = self.export_filter_cols.update().where(self.export_filter_cols.c.cols_id.in_([cols_id])).values(del_data)
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def insert_export_column(self,del_data):
with engine.connect() as conn:
result = conn.execute(self.export_filter_cols.insert(), del_data)
conn.commit()
return "success"
def delete_export_column_by_conf_id(self,conf_ids,cols_id):
with engine.connect() as conn:
conn = engine.connect()
if conf_ids:
stmt = text("update export_filter_cols set conf_ids = '"+str(conf_ids)+"' where cols_id = "+str(cols_id)+" and is_del = 1 ; ")
else:
stmt = text("delete from export_filter_cols where cols_id = "+str(cols_id)+" and is_del = 1 ; ")
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def get_not_existing_export_columns(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from export_filter_cols where not FIND_IN_SET ("+str(conf_id)+",conf_ids) and is_visible =1 and is_del =1 and orderby is not null order by orderby asc;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_export_columns_by_cols_id(self,cols_id):
with engine.connect() as conn:
stmt = text("select * from export_filter_cols where is_visible =1 and is_del =1 and orderby is not null and cols_id in ("+str(cols_id)+") order by orderby asc;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_conf_payment_types(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from m_payment_type where conf_id = "+str(conf_id)+" and is_visible =1 and is_delegate =1 order by order_by DESC;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_master_payment_types(self):
with engine.connect() as conn:
stmt = text("select * from del_m_payment_type;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_payment(self,conf_id):
with engine.connect() as conn:
stmt = text("select * FROM m_payment_type where conf_id = "+str(conf_id)+" ; ")
conn = engine.connect()
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def insert_payment_type(self,del_data):
with engine.connect() as conn:
result = conn.execute(self.m_payment_type.insert(), del_data)
conn.commit()
return "success"
def get_payment_by_payment_id(self,conf_id,m_payment_id):
with engine.connect() as conn:
stmt = text("select * FROM m_payment_type where conf_id = "+str(conf_id)+" and m_payment_id = "+str(m_payment_id)+"; ")
conn = engine.connect()
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def delete_payment_by_payment_id(self,conf_id,m_payment_id):
with engine.connect() as conn:
stmt = text("delete from m_payment_type where conf_id = "+str(conf_id)+" and m_payment_id = "+str(m_payment_id)+"; ")
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def update_payment_type(self,m_payment_id,del_data):
with engine.connect() as conn:
conn = engine.connect()
stmt = self.m_payment_type.update().where(self.m_payment_type.c.m_payment_id.in_([m_payment_id])).values(del_data)
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def insert_payment_types_bulk(self,stmt_1):
with engine.connect() as conn:
stmt2 = text("set sql_safe_updates = 0 ;")
conn.execute(stmt2)
conn.commit()
result = conn.execute(text(stmt_1))
conn.commit()
return result
# Mail Template Start
# Created At : 2023-10-16 10:46 By Ramya
def get_usp_mail_template_data(self,conf_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_bo_get_mail_templates",[conf_id])
while 1:
#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
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
finally:
# Return the connection to the pool (won't actually close).
connection.commit()
connection.close()
return sets
def get_existing_templates(self,conf_id):
with engine.connect() as conn:
try:
stmt = text("select mail_template_id,display_name from mail_templates where template_name not in ('receipt_mail','confirmation_mail',"
+" 'confirmation_and_receipt_mail','payment_link_generate','payement_acknowledgement_mail','rejected_payment_mail') "
+" and app_type_id = 2 and not find_in_set('"+str(conf_id)+"',conf_ids) ;")
# print(stmt)
result_2 = conn.execute(stmt).all()
return [dict(r._mapping) for r in result_2] if result_2 else None
except Exception as e:
return str(e)
def check_mail_template(self,d_mail_template_id,conf_id):
with engine.connect() as conn:
stmt = text("select dm.*,mt.* from delegate_mail_templates dm inner join mail_templates mt on mt.template_name COLLATE utf8mb4_general_ci = dm.template_name where d_mail_template_id = "+str(d_mail_template_id)+" and find_in_set('"+str(conf_id)+"',conf_ids COLLATE utf8mb4_general_ci);")
result = conn.execute(stmt).all()
if result :
return None
else :
stmt = text("select app_type_id, is_active, template_name, display_name, subject_type, subject, mail_type, mail_content, is_send_backup from delegate_mail_templates where d_mail_template_id = "+str(d_mail_template_id)+" ;")
result = conn.execute(stmt).fetchone()
return dict(result._mapping) if result else None
def insert_into_mail_template(self,data):
with engine.connect() as conn:
result = conn.execute(self.mail_templates.insert(),data)
conn.commit()
return result
def get_mail_template_by_id(self,mail_template_id):
with engine.connect() as conn:
try:
get_stmt = text("select * FROM mail_templates where mail_template_id ="+str(mail_template_id)+";")
# print(get_stmt)
result = conn.execute(get_stmt).one_or_none()
return dict(result._mapping) if result else None
except Exception as e:
return str(e)
def insert_and_get_data(self,conf_id,insert_data):
with engine.connect() as conn:
try:
insert_stmt = conn.execute(self.mail_templates.insert(),insert_data)
conn.commit()
get_stmt = text("select * FROM mail_templates where app_type_id = 2 and find_in_set("+str(conf_id)+",conf_ids COLLATE utf8mb4_general_ci);")
result_2 = conn.execute(get_stmt).all()
return [dict(r._mapping) for r in result_2] if result_2 else None
except Exception as e:
return str(e)
def update_and_get_data(self,conf_id,update_data,mail_template_id):
with engine.connect() as conn:
try:
stmt = self.mail_templates.update().where(self.mail_templates.c.mail_template_id.in_([mail_template_id])).values(update_data)
restult_1 = conn.execute(stmt)
conn.commit()
get_stmt = text("select * FROM mail_templates where app_type_id = 2 and find_in_set("+str(conf_id)+",conf_ids COLLATE utf8mb4_general_ci);")
result_2 = conn.execute(get_stmt).all()
return [dict(r._mapping) for r in result_2] if result_2 else None
except Exception as e:
return str(e)
def get_mail_templates_by_ids(self,mail_template_ids):
with engine.connect() as conn:
try:
stmt = text("select * from mail_templates where mail_template_id in ("+mail_template_ids+ ")"
+" and app_type_id = 2 group by template_name ;")
result_2 = conn.execute(stmt).all()
return [dict(r._mapping) for r in result_2] if result_2 else None
except Exception as e:
return str(e)
def update_mail_templates_bulk(self,stmt_1):
with engine.connect() as conn:
result = conn.execute(text(stmt_1))
conn.commit()
return result
# Mail Template End
#default role start
def get_dafault_role(self,is_default_role):
with engine.connect() as conn:
stmt = text("select b_role,is_default_role from badge_role where is_default_role ="+str(is_default_role)+";")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
#end
# insert default role
def insertDefaultRole(self,stmt_1) :
with engine.connect() as conn :
result = conn.execute(text(stmt_1))
conn.commit()
return "success"
def CheckDefaultRoleCount(self,conf_id):
with engine.connect() as conn:
stmt = text("select count(b_role) as total_selected_count from badge_role where conf_id = "+str(conf_id)+" and b_role in (select b_role from badge_role where is_default_role =1) ; ")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def CheckDefaultRole(self,conf_id):
with engine.connect() as conn:
stmt = text("select b_role from badge_role where conf_id = "+str(conf_id)+" and b_role in (select b_role from badge_role where is_default_role =1) group by b_role ;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def DefaultRoleCount(self):
with engine.connect() as conn:
stmt = text("select count(b_role) as total_default_count from badge_role where is_default_role =1;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def DefaultRole(self):
with engine.connect() as conn:
stmt = text("select * from badge_role where is_default_role =1;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_rolewise_delegates_count(self,conf_id):
with engine.connect() as conn:
stmt = text("select role,count(delegate_no) as role_count FROM delegates where delegate_no is not null and conference_id = "+str(conf_id)+" group by role ; ")
conn = engine.connect()
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
# Purpose : To Check Delegate Data
# Created on 2023-12-14 14:49
def check_bo_del_data(self,conf_id):
# print("call usp_del_bo_ds_check_del_data(",conf_id,")")
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_bo_ds_check_del_data",[(conf_id or None)])
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
if cursor.description is None:
break
finally:
connection.commit()
connection.close()
return sets
def update_delegate_data(self,delegate_id,update_data):
with engine.connect() as conn:
conn = engine.connect()
stmt = self.delegates.update().where(self.delegates.c.delegate_id.in_([delegate_id])).values(update_data)
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def search_user_id(self,society_id,email,mobile,conf_id):
with engine.connect() as conn:
try:
where_con = ""
if email and mobile :
where_con = " and (u.email ='"+email+"' or u.mobile = "+str(mobile)+" ) "
elif email and mobile is None:
where_con = " and (u.email ='"+email+"' ) "
elif email is None and mobile:
where_con = " and (u.mobile = "+str(mobile)+") "
else:
where_con = ""
stmt = text("select u.user_id, u.society_id, c.conf_id,u.membership_no, u.member_type_id, u.email, u.mobile,(case when u.prefix is null then u.full_name else concat(u.prefix, '' , u.full_name) end) as full_name,m.member_type "
+" from users u inner join conference c on c.society_id = u.society_id "
+" inner join m_member_type m on m.member_type_id = u.member_type_id"
+" where c.conf_id = "+str(conf_id)+" and c.society_id = "+str(society_id)+" "
+ where_con )
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
except Exception as e:
return str(e)
# Purpose : Adding default access to Trigger Daily reports mails
# Created At : 2024-02-24 01:14 By Ramya
def get_del_trigger_mail(self,conf_id):
with engine.connect() as conn:
emails = text("select group_concat(email separator ''',''') as email from trigger_daily_reports_mails where app_type_id = 2 and is_del = 1 and conf_id = "+str(conf_id))
result = conn.execute(emails).all()
dic_email = [dict(r._mapping) for r in result]
l_email = "'"+str(dic_email[0]['email'])+"'"
if l_email :
stmt = text("select * from del_trigger_drm where email not in ("+str(l_email)+") ")
else:
stmt = text("select * from del_trigger_drm ; ")
conn = engine.connect()
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_trigger_daily_reports_mails(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from trigger_daily_reports_mails where is_del = 1 and conf_id = "+str(conf_id)+" ; ")
conn = engine.connect()
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def check_trigger_mail_data(self,del_report_id,conf_id):
with engine.connect() as conn:
stmt = text("select dm.*,mt.* from del_trigger_drm dm inner join trigger_daily_reports_mails mt on mt.email = dm.email where mt.is_del = 1 and dm.del_report_id = "+str(del_report_id)+" and mt.conf_id in ("+str(conf_id)+");")
result = conn.execute(stmt).all()
if result :
return None
else :
stmt = text("select app_type_id, full_name, email, mobile, is_active, is_separate_mail, is_consolidate_mail, active_conf_list_mail, is_del from del_trigger_drm where del_report_id = "+str(del_report_id)+" ;")
result = conn.execute(stmt).fetchone()
return dict(result._mapping) if result else None
def insert_into_trigger_daily_reports_mails(self,data):
with engine.connect() as conn:
result = conn.execute(self.trigger_daily_reports_mails.insert(),data)
conn.commit()
return result
def update_remove_access_trigger_mail_data(self,stmt_1):
with engine.connect() as conn:
try:
stmt2 = text("set sql_safe_updates = 0 ;")
conn.execute(stmt2)
conn.commit()
result = conn.execute(text(stmt_1))
conn.commit()
return 'success' if result else 'fail'
except Exception as e:
return str(e)
def insert_trigger_data(self,data):
with engine.connect() as conn:
result = conn.execute(self.trigger_daily_reports_mails.insert(),data)
conn.commit()
return 'success' if result else 'fail'
def check_already_exist_trigger_data(self,email,conf_id):
with engine.connect() as conn:
stmt = text("select * from trigger_daily_reports_mails where is_del = 1 and email = '"+str(email)+"' and conf_id ="+str(conf_id)+";")
result = conn.execute(stmt).fetchone()
return dict(result._mapping) if result else None
def update_bulk_trigger_data(self,conf_id,report_id,data,updated_at):
with engine.connect() as conn:
stmt2 = text("set sql_safe_updates = 0 ;")
conn.execute(stmt2)
conn.commit()
stmt = 'update trigger_daily_reports_mails SET '
report_id = report_id
keyname = ["is_active","is_separate_mail","is_consolidate_mail","active_conf_list_mail","updated_at"]
for j in keyname:
stmt = stmt + j +" = case "
for i in data:
stmt = stmt + " When report_id in (" + i["report_id"] + ") then '" + str(i[j]) +"' "
stmt = stmt + ' END, '
stmt = stmt[:-2]
stmt = stmt + ' Where conf_id = ' +str(conf_id)+' and report_id in (\''+ "','".join(report_id) +'\');'
stmt = text(stmt)
result = conn.execute(stmt)
conn.commit()
stmt_1 = text("select count(report_id) as updated_count from trigger_daily_reports_mails where conf_id = "+str(conf_id)+" and updated_at = '"+updated_at+"' ;")
result_1 = conn.execute(stmt_1).one_or_none()
return dict(result_1._mapping) if result_1 else None
# Purpose : Page Info
# Created At : 2024-02-24 01:14 By Ramya
def get_page_info_data(self,pathname):
with engine.connect() as conn:
stmt = text("select info_id, del_page_name, del_info_content, pathname, is_active from del_page_info where pathname = '"+str(pathname)+"' and is_active =1 ;")
result = conn.execute(stmt).fetchone()
return dict(result._mapping) if result else None
# Purpose : App Style
# Created At : 2024-02-24 01:14 By Ramya
def get_app_style(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from app_style where conf_id = "+str(conf_id)+" limit 1 ;")
result = conn.execute(stmt).fetchone()
return dict(result._mapping) if result else None
def insert_or_update_app_style(self,update_or_insert,style_id,data):
with engine.connect() as conn:
try:
if update_or_insert == 'insert' :
result = conn.execute(self.app_style.insert(),data)
conn.commit()
return 'insert_success' if result else 'insert_fail'
elif update_or_insert == 'update':
stmt = self.app_style.update().where(self.app_style.c.style_id.in_([style_id])).values(data)
result = conn.execute(stmt)
conn.commit()
return 'update_success' if result else 'update_fail'
else :
conn.commit()
return 'failed'
except Exception as e:
return str(e)
# Purpose : Add Trade admin access
# Created on 2024-05-01 09:42:00 By Ramya.S
def get_trade_users(self,society_id):
with engine.connect() as conn:
stmt = text("select user_id,member_type_id,full_name,email,mobile,is_trade,password,trade_access_limit FROM users where society_id = "+str(society_id)+" and is_trade = 1;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def check_trade_admin_access(self,society_id,email,conf_id):
with engine.connect() as conn:
stmt = text("select admin_access_id from admin_access where society_id = "+str(society_id)+" and ( admin_email = '"+email+"' ) and app_type_id = 2 and conf_id = "+str(conf_id)+" and admin_role_id = 1 limit 1 ;")
result = conn.execute(stmt).fetchone()
return dict(result._mapping) if result else None
def check_trade_email_or_mobile(self,society_id,email,mobile):
with engine.connect() as conn:
stmt = text("select user_id from users where society_id = "+str(society_id)+" and ( email = '"+email+"' or mobile = '"+mobile+"' ) limit 1 ;")
result = conn.execute(stmt).fetchone()
return dict(result._mapping) if result else None
def update_trade_user(self,user_id,data):
with engine.connect() as conn:
stmt = self.users.update().where(self.users.c.user_id.in_([user_id])).values(data)
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def insert_admin_access(self,data):
with engine.connect() as conn:
result = conn.execute(self.admin_access.insert(), data)
conn.commit()
return 'success' if result else 'fail'
def get_edit_trade_users(self,user_id):
with engine.connect() as conn:
stmt = text("select user_id,member_type_id,full_name,email,mobile,is_trade,password,trade_access_limit from users where user_id = "+str(user_id)+" limit 1 ;")
result = conn.execute(stmt).fetchone()
return dict(result._mapping) if result else None
def get_reg_type_for_trade_user(self,user_id,conf_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_set_reg_type_limit_for_trade_user",[(user_id or None),(conf_id or None)])
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
if cursor.description is None:
break
finally:
connection.commit()
connection.close()
return sets
def insert_del_trade_access(self,insert_data):
with engine.connect() as conn:
result = conn.execute(self.del_trade_access.insert(),insert_data)
conn.commit()
return 'success' if result else 'fail'
def update_del_trade_access(self,id,update_data):
with engine.connect() as conn:
stmt = self.del_trade_access.update().where(self.del_trade_access.c.id.in_([id])).values(update_data)
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
# Purpose : Add Bo app menu
# Created At : 2024-03-24 01:14 By Ramya
def get_bo_app_menu(self,society_id,conf_id,app_type_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_bo_app_menu",[(conf_id or None),(society_id or None),(app_type_id or None)])
while 1:
#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
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
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def update_map_menu_conf(self,post_type,mmc_id,update_data,insert_data,conf_id):
with engine.connect() as conn:
if post_type == "update":
conn = engine.connect()
stmt = self.map_menu_conf.update().where(self.map_menu_conf.c.mmc_id.in_([mmc_id])).values(update_data)
result = conn.execute(stmt)
conn.commit()
return 'update_success' if result else 'update_fail'
elif post_type =="insert":
result = conn.execute(text(insert_data))
conn.commit()
return 'insert_success' if result else 'insert_fail'
elif post_type =="remove_menu":
stmt = text("delete FROM map_menu_conf WHERE menu_id in ("+str(mmc_id)+") and conf_id = "+str(conf_id)+" ;")
result = conn.execute(stmt)
conn.commit()
return 'delete_success' if result else 'delete_fail'
def check_del_bo_app_menu(self,conf_id,menu_id,app_type_id,query_type):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_bo_check_app_menu",[(conf_id or None),(menu_id or None),(app_type_id or None),(query_type or 'app_menu')])
while 1:
#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
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
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def check_admin_menu(self,conf_id,admin_access_id,modal_type):
with engine.connect() as conn:
where_con = ''
added_menu = text("select group_concat(menu_ids) as menu_id from map_admin_menu where conf_id = "+str(conf_id)+ " and admin_access_id = "+str(admin_access_id)+" ;")
result = conn.execute(added_menu).fetchone()
result = dict(result._mapping)
menu_ids = result['menu_id']
if menu_ids :
if modal_type == 'add' :
stmt = text("select m.menu_id,m.menu_name from map_menu_conf mc inner join m_app_menu m on m.menu_id = mc.menu_id and m.app_type_id= 2 where m.is_visible = 1 and mc.is_visible = 1 and mc.conf_id = "+str(conf_id)+" and mc.menu_id not in ("+menu_ids+") ;")
else :
stmt = text("select mm.map_menu_id,m.menu_id,m.menu_name from map_menu_conf mc inner join m_app_menu m on m.menu_id = mc.menu_id and m.app_type_id= 2 inner join map_admin_menu mm on mm.conf_id = mc.conf_id and mc.menu_id = mm.menu_ids where m.is_visible = 1 and mc.is_visible = 1 and mc.conf_id = "+str(conf_id)+" and mc.menu_id in ("+menu_ids+") and mm.admin_access_id = "+str(admin_access_id)+" group by mm.menu_ids ;")
else :
if modal_type == 'add' :
stmt = text("select m.menu_id,m.menu_name from map_menu_conf mc "
+" inner join m_app_menu m on m.menu_id = mc.menu_id and m.app_type_id= 2 "
+" where m.is_visible = 1 and mc.is_visible = 1 and mc.conf_id = "+str(conf_id)+" ;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def remove_admin_menu(self,conf_id,map_menu_ids,admin_access_id):
with engine.connect() as conn:
stmt = text("delete from map_admin_menu where conf_id = "+str(conf_id)+" and map_menu_id in ("+str(map_menu_ids)+" ) and admin_access_id = "+str(admin_access_id)+"; ")
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def get_m_app_menu(self):
with engine.connect() as conn:
stmt = text("select * from m_app_menu where app_type_id = 2 and is_visible = 1 and parent_menu_id=13 ; ")
conn = engine.connect()
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
# Slight Changes from admin module
# Purpose : To add admin access from Backoffice
# Created on : 2024-05-21 17:00 by Ramya
def get_admin_data(self,society_id):
with engine.connect() as conn:
stmt = text("select aa.admin_access_id,aa.admin_role_id,mar.role,aa.society_id,aa.conf_id,group_concat(aa.app_type_id) as app_type_id,u.user_id,aa.admin_email,concat(ifnull(u.prefix,''), u.full_name) as full_name, group_concat(mat.app_name) as app_name from admin_access aa "+
"inner join users u on aa.admin_email=u.email and aa.society_id=u.society_id "+
"left join m_app_type mat on mat.app_type_id = aa.app_type_id "+
"left join m_admin_role mar on mar.admin_role_id = aa.admin_role_id "+
f"where aa.society_id={society_id} "+
"group by aa.admin_email order by admin_access_id")
results = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results] if results else None
return results
def get_admin_roles(self):
with engine.connect() as conn:
stmt = text("select * from m_admin_role;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_app_by_admin_email(self,society_id,admin_email):
with engine.connect() as conn:
stmt = text("select u.user_id,concat(ifnull (u.prefix,''),u.full_name)as full_name,u.mobile,u.password,ua.admin_access_id,ua.admin_role_id,a.app_type_id,s.society_id, ifnull(s.conf_id,0) as conf_id, app_name,c.conf_name,concat(a.app_type_id,'-',s.society_id,'-',ifnull(s.conf_id,0)) as access_key ,ua.admin_email from m_app_type a "+
"inner join society_applications s on s.app_type_id = a.app_type_id "+
"left join conference c on c.conf_id = s.conf_id "+
f"left join admin_access ua on ua.society_id=s.society_id and ifnull(ua.conf_id,0) = ifnull(s.conf_id,0) and ua.app_type_id=s.app_type_id and ua.admin_email='{admin_email}' "+
f"left join users u on u.email = '{admin_email}' and u.society_id=s.society_id "
f"where s.society_id = {society_id} and a.app_type_id not in (9) "+
"order by field(a.app_type_id,1,4,7,2,3,5) ,year(c.conf_start_time);")
results = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results] if results else None
return results
def get_admin_data_by_admin_email(self,society_id,admin_email):
with engine.connect() as conn:
if admin_email :
admin_email = " and u.email = '"+admin_email+"'"
else :
admin_email = " and u.email = null "
stmt = text("select concat(ifnull (u.prefix,''),u.full_name)as full_name,u.email as u_email,u.mobile,u.password,aa.admin_role_id,aa.admin_email,u.user_id from users u "+
" left join admin_access aa on aa.admin_email=u.email and aa.society_id =u.society_id "
+" where u.society_id="+str(society_id)+" "+admin_email+" group by u.email;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_old_app_datas(self,admin_email,society_id):
with engine.connect() as conn:
stmt = text("select admin_role_id,concat(app_type_id,'-',society_id,'-',ifnull(conf_id,0))as app_type_ids from admin_access "+
f"where society_id={society_id} and admin_email='{admin_email}';")
results = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results] if results else None
return results
def insert_admin_access(self,apps):
with engine.connect() as conn:
stmt_1 = insert(self.admin_access).values(apps)
result = conn.execute(stmt_1)
conn.commit()
return result
def delete_admin_access(self,delete_apps):
with engine.connect() as conn:
for i in delete_apps:
where_con = ""
if i["conf_id"]:
where_con = " and conf_id = "+str(i["conf_id"])
stmt_1 = text(f"delete from admin_access where society_id = {i['society_id']} and app_type_id = {i['app_type_id']} and admin_email = '{i['admin_email']}' and admin_role_id = {i['admin_role_id']} {where_con}")
# stmt_1 = insert(self.admin_access).values(delete_apps)
result = conn.execute(stmt_1)
conn.commit()
return result
def insert_super_admin(self,data):
with engine.connect() as conn:
stmt_1 = insert(self.admin_access).values(data)
result = conn.execute(stmt_1)
conn.commit()
return result
def delete_super_admin(self,data1):
with engine.connect() as conn:
stmt_1 = text(f"delete from admin_access where society_id = {data1['society_id']} and admin_email = '{data1['admin_email']}' and admin_role_id = {data1['admin_role_id']}")
# stmt_1 = insert(self.admin_access).values(delete_apps)
result = conn.execute(stmt_1)
conn.commit()
return result
def insert_new_access_admin(self,data):
with engine.connect() as conn:
result = conn.execute(self.admin_access.insert(), data)
conn.commit()
pk_id = result.inserted_primary_key[0] if result.inserted_primary_key[0] else None
return pk_id
def insert_admin_user(self,data):
with engine.connect() as conn:
result = conn.execute(self.users.insert(), data)
conn.commit()
return result
def delete_admin_access_by_email(self,data):
with engine.connect() as conn:
stmt_1 = text(f"delete from admin_access where society_id = {data['society_id']} and conf_id = {data['conf_id']} and admin_email = '{data['admin_email']}' ")
# stmt_1 = insert(self.admin_access).values(delete_apps)
result = conn.execute(stmt_1)
conn.commit()
return result
def insert_m_app_menu(self,data):
with engine.connect() as conn:
result = conn.execute(self.m_app_menu.insert(), data)
conn.commit()
return 'success' if result else 'fail'
# Registration Mapped Function Starts here
def BoGetRegistrationPageContent(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from del_conf_content where conf_id = "+str(conf_id)+" order by order_by asc;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def remove_del_content_by_id(self,conf_id,del_conf_id,updated_at):
with engine.connect() as conn:
conn = engine.connect()
stmt = text("update del_conf_content set is_visible = 0 ,updated_at = '"+str(updated_at)+"' where conf_id = "+str(conf_id)+" and id = '"+str(del_conf_id)+"'; ")
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def add_del_content_by_id(self,conf_id,del_conf_id,updated_at):
with engine.connect() as conn:
conn = engine.connect()
stmt = text("update del_conf_content set is_visible = 1 ,updated_at = '"+str(updated_at)+"' where conf_id = "+str(conf_id)+" and id = '"+str(del_conf_id)+"'; ")
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def get_del_content_by_id(self,conf_id,del_conf_id):
with engine.connect() as conn:
conn = engine.connect()
stmt = text("select * from del_conf_content where conf_id = "+str(conf_id)+" and id = '"+str(del_conf_id)+"'; ")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def update_del_content_data(self,conf_id,del_conf_id,dict_data):
with engine.connect() as conn:
conn = engine.connect()
stmt = self.del_conf_content.update().where(self.del_conf_content.c.conf_id.in_([conf_id]),self.del_conf_content.c.id.in_([del_conf_id])).values(dict_data)
result = conn.execute(stmt)
conn.commit()
return 'success' if result else 'fail'
def insert_del_content_data(self,del_data):
with engine.connect() as conn:
conn = engine.connect()
result = conn.execute(self.del_conf_content.insert(), del_data)
conn.commit()
return 'success' if result else 'fail'
def delete_del_content_by_id(self,del_conf_id):
with engine.connect() as conn:
stmt = text("delete from del_conf_content WHERE id = "+str(del_conf_id)+";")
results = conn.execute(stmt)
conn.commit()
if results:
return 'success'
else :
return 'fail'
# Registration Mapped Function Ends here
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists