Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from core import app
from .. import Cryptography
from core.library.helper import Helper
import json
import datetime
from datetime import timedelta,date,datetime
from .. import engine
import sqlite3
import pandas as pd
# engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
# engine = create_engine(app.config['DATABASE_URI'],pool_size=20, max_overflow=0)
engine_sqlite = create_engine('sqlite:///sqlite_database.db')
class UserModel():
def __init__(self):
try:
self.meta = MetaData()
self.users = Table("users", self.meta, autoload_with=engine)
self.categories = Table("abs_categories",self.meta, autoload_with=engine)
self.abstracts = Table("abstracts", self.meta, autoload_with=engine)
self.user_attachments = Table("user_attachments", self.meta, autoload_with=engine)
except Exception as e:
print(e)
def GetAppStyle(self,conf_id):
with engine_sqlite.connect() as conn:
stmt = text("select * from app_style where conf_id ="+str(conf_id)+"")
result = conn.execute(stmt).first()
return dict(result._mapping) if result else None
def get_society(self,society_id):
with engine.connect() as conn:
stmt = text("select * from societies where society_id = {}".format(society_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_conference_by_host(self,host):
with engine.connect() as conn:
stmt = text("select * from society_applications sa inner join conference c on sa.conf_id = c.conf_id where app_host = '{}' and app_type_id = 3".format(host))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def insert_new_user(self,email,society_id):
with engine.connect() as conn:
stmt = text("insert into users (email,society_id,created_at) values('{}',{},'{}')".format(email,society_id,datetime.now()))
result = conn.execute(stmt)
conn.commit()
stmt = text("select * from users where email = '{}' and society_id = {} limit 1".format(email,society_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def check_password(self,user_id):
with engine.connect() as conn:
stmt = self.users.select().where(self.users.c.user_id.in_([user_id]))
result = conn.execute(stmt).first()
return dict(result._mapping) if result else None
def insert_new_request_user(self,data,society_id):
with engine.connect() as conn:
stmt = text("select * from users where email = '{}' and society_id = {} limit 1".format(data['email'],society_id))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
if results:
return results
else:
stmt_1 = text("insert into users (prefix,full_name,email,society_id,created_at) values('Dr.','{}','{}',{},'{}')".format(data["name"],data['email'],society_id,datetime.now()))
results = conn.execute(stmt_1)
conn.commit()
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results
def insert_new_request_user_v1(self,data,society_id):
with engine.connect() as conn:
stmt = text("select * from users where email = '{}' and society_id = {} limit 1".format(data['email'],society_id))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
if results:
return results
else:
results = conn.execute(self.users.insert(),data)
# stmt_1 = text(f"""insert into users (prefix,full_name,email,mobile,city,country_id,affiliation,society_id,created_at,mobile_isd_code) values('Dr.','{data["name"]}','{data["email"]}',{data["mobile"]},'{data["city"]}','{data["country"]}','{data["affiliation"]}','{society_id}','{datetime.now()}','{data["mobile_isd_code"]}')""")
# results = conn.execute(stmt_1)
conn.commit()
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results
def get_state_and_country(self):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_state_and_country")
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.close()
return sets
def get_state(self):
with engine.connect() as conn:
stmt = text("select * from states where country_id = 101 order by state_name asc")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_coountry(self):
with engine.connect() as conn:
stmt = text("select * from countries")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_country_data(self,country_id):
with engine.connect() as conn:
stmt = text("select * from states where country_id = {} order by state_name asc".format(country_id))
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def count_whatsapp_num(self,whatsapp_number,user_id,society_id):
with engine.connect() as conn:
stmt = text("select count(*) from users where user_id <> :user_id and (mobile= :whatsapp_number or whatsapp_number=:whatsapp_number) and society_id = :society_id ")
result = conn.execute(stmt.bindparams(user_id=user_id,whatsapp_number=whatsapp_number,society_id=society_id))
results = result.one_or_none()
if results :
return results
else:
return None
def get_mobile_count(self,mobile,user_id,society_id):
with engine.connect() as conn:
stmt = text("select count(*) as mobile_count from users where mobile = '{}' and user_id != {} and society_id = {} ".format(mobile,user_id,society_id))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results["mobile_count"]
def get_user_data_by_uuid(self,uuid):
with engine.connect() as conn:
stmt = text("select * from users where user_uuid = '{}'".format(uuid))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_confe(self,conf_id,conf_key):
with engine_sqlite.connect() as conn:
stmt = text("select c.*,sa.app_title,sa.app_url,app_host,sa.mail_setting_id,app_style,s.society_title,s.society_name,s.society_key,s.society_intial,sa.index_content as society_index_content,sa.app_type_id,sa.header_right,ms.* from conference c inner join societies s on s.society_id = c.society_id inner join society_applications sa on c.conf_id = sa.conf_id and sa.app_type_id = 3 inner join mail_setting ms on ms.mail_setting_id=sa.mail_setting_id where c.conf_id = {} and c.conf_key = '{}'".format(conf_id,conf_key))
result = conn.execute(stmt).one_or_none()
# results = [dict(r) for r in result] if result else None
return dict(result._mapping) if result else None
def get_users_email_data(self,email,society_id):
with engine.connect() as conn:
stmt = text("select * from users where email = '{}' and society_id = {} limit 1".format(email,society_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_members_email_data(self,email,society_id):
with engine.connect() as conn:
stmt = text("select * from users where email = '{}' and society_id = {} and member_type_id in (1,6)".format(email,society_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_otp_random(self,user_id):
with engine.connect() as conn:
stmt = text("select otp from users where user_id = {} ".format(user_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def update_member(self,user_id,data):
with engine.connect() as conn:
stmt = self.users.update().values(data).where(self.users.c.user_id.in_([user_id]))
result = conn.execute(stmt)
conn.commit()
select_stmt = text("select * from users where user_id = "+str(user_id)+" ")
select_result = conn.execute(select_stmt).one_or_none()
return dict(select_result._mapping) if select_result else None
def get_member(self,user_id):
with engine.connect() as conn:
stmt = text("select * from users where user_id = {} ".format(user_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_users_member_no(self,ids):
with engine.connect() as conn:
stmt = text("select user_id,membership_no,member_type_id,concat(ifnull(prefix,' '),ifnull(full_name,' ')) as full_name,email,mobile,user_uuid from users where user_id = {} ".format(ids))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_categories(self,abs_type,conf_id):
with engine.connect() as conn:
if abs_type == "VT":
stmt_2 = text("select * from abs_categories where is_{} = 1 and forum_is_visible = 0 and conf_id = {} order by category_id".format(abs_type,conf_id))
else:
stmt_2 = text("select * from abs_categories where is_{} = 1 and segment is not null and conf_id = {} order by category_id".format(abs_type,conf_id))
result = conn.execute(stmt_2).all()
return [dict(r._mapping) for r in result] if result else None
def get_categories_v1(self,abs_type,conf_id):
with engine.connect() as conn:
stmt = text("select * from abs_categories ac inner join map_abs_category mas on mas.category_id=ac.category_id inner join abs_types ats on ats.abs_type_id=mas.abs_type_id where is_active=1 and mas.conf_id={} and ats.abs_type='{}' order by order_no asc".format(conf_id,abs_type))
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_categories_by_userid(self,abs_type,conf_id,user_id,conf_schema):
with engine.connect() as conn:
stmt = text("select * from abs_categories ac inner join map_abs_category mas on mas.category_id=ac.category_id inner join abs_types ats on ats.abs_type_id=mas.abs_type_id where is_active=1 and mas.conf_id={} and ats.abs_type='{}' and ac.category_id not in (select category_id from {}.abstracts where conf_id={} and abs_type='{}' and user_id={} and abs_status_id>0) order by order_no asc".format(conf_schema,conf_id,abs_type,conf_id,abs_type,user_id))
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_categories_bo(self,abs_type,conf_id):
with engine.connect() as conn:
stmt = text("select * from abs_categories where conf_id = {}".format(conf_id))
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def new_abs(self,user_id,abs_type,role_id,created_at,conf_id,conf_schema):
abstracts = Table("abstracts", self.meta, schema=conf_schema, autoload_with=engine)
with engine.connect() as conn:
stmt = abstracts.insert().values(user_id=user_id,abs_type=abs_type,created_at=created_at,conf_id=conf_id)
result = conn.execute(stmt)
abs_id = result.inserted_primary_key if result.inserted_primary_key[0] else None
stmt = text("insert into {}.abs_topics (user_id,abs_id,role_id,created_at) VALUES('{}','{}',{},'{}')".format(conf_schema,str(user_id),str(abs_id[0]),str(role_id),str(created_at)))
result = conn.execute(stmt)
conn.commit()
return abs_id
def steps_data(self,ids,conf_schema):
abstracts = Table("abstracts", self.meta, schema=conf_schema, autoload_with=engine)
with engine.connect() as conn:
stmt = abstracts.select().where(abstracts.c.abs_id.in_([ids]))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
# ****
def steps_2_data(self,ids,conf_schema):
with engine.connect() as conn:
stmt = text('select ab.abs_id,abs_type,abs_no,title,synopsis,abs_status_id,resume,methods,results,file_name,path from {}.abstracts ab left join {}.abs_uploads abu on ab.abs_id = abu.abs_id where ab.abs_id = {} '.format(conf_schema,conf_schema,ids))
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def check_abs_id(self,abs_id):
with engine.connect() as conn:
stmt = text("select count(*) as check_abs_id from abstracts where abs_id ={}".format(abs_id))
result=conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def update_step(self,data,abs_id,conf_schema):
abstracts = Table("abstracts", self.meta, schema=conf_schema, autoload_with=engine)
with engine.connect() as conn:
stmt = abstracts.update().values(data).where(abstracts.c.abs_id.in_([abs_id]))
result = conn.execute(stmt)
conn.commit()
return None
def get_search_data_presenting(self,user_type,role_id,search,abs_type,society_id,conf_id=None):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_search_coi_v1",[user_type,role_id,search,abs_type,society_id,conf_id])
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
def get_search_data(self,search,role_id,abs_type,society_id,conf_id=None):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_search_coi_v1",[None,role_id,search,abs_type,society_id,conf_id])
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
def get_ratified_member_count(self,abs_id,conf_schema):
with engine.connect() as conn:
stmt = text("select count(*) as ratified_count from {}.abs_topics ab inner join users u on ab.user_id = u.user_id where abs_id = {} and member_type_id in (1,6,17,20)".format(conf_schema,abs_id))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results["ratified_count"]
def get_ratified_member_count_kos(self,abs_id,conf_schema):
with engine.connect() as conn:
stmt = text("select count(*) as ratified_count from {}.abs_topics ab inner join users u on ab.user_id = u.user_id where abs_id = {} and member_type_id in (1,6,17,20) and u.is_ratified=1;".format(conf_schema,abs_id))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results["ratified_count"]
def get_category_by_id(self,ids):
with engine.connect() as conn:
stmt = text("select display_name from abs_categories where category_id={}".format(ids))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results["display_name"]
def get_presentation_type(self,ids):
with engine.connect() as conn:
stmt = text("select type from abs_presentation_type where presentation_type_id = {}".format(ids))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results["type"]
def get_user_data(self,user_id):
with engine.connect() as conn:
stmt = text("select * from users where user_id = {}".format(user_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_consent_count_email(self,topic_id,conf_id,conf_schema):
with engine.connect() as conn:
stmt1 = text("select user_id from {}.abs_topics where topic_id = {}".format(conf_schema,topic_id))
result = conn.execute(stmt1).one_or_none()
results = dict(result._mapping) if result else None
user_id = results["user_id"]
if int(conf_id) == 57:
stmt = text("select count(distinct(t.abs_id))as consent_count from {}.abs_topics t inner join {}.abstracts a on t.abs_id = a.abs_id and a.conf_id = {} where t.user_id={} and a.abs_status_id > 0 and a.abs_status_id != 4 and consent_status_id = 2 and role_id = 33 ".format(conf_schema,conf_schema,conf_id,user_id))
else:
stmt = text("select count(distinct(t.abs_id))as consent_count from {}.abs_topics t inner join {}.abstracts a on t.abs_id = a.abs_id and a.conf_id = {} where t.user_id={} and t.abs_id not in (select distinct(abs_id) from {}.abstracts where user_id = {} and conf_id= {} ) and consent_status_id = 2 and role_id = 33 ".format(conf_schema,conf_schema,conf_id,user_id,conf_schema,user_id,conf_id))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results["consent_count"]
def get_user_consent_count(self,user_id,conf_id,conf_schema):
with engine.connect() as conn:
stmt = text("select count(distinct(t.abs_id))as consent_count from {}.abs_topics t inner join {}.abstracts a on t.abs_id = a.abs_id and a.conf_id = {} where t.user_id={} and a.abs_status_id > 0 and a.abs_status_id != 4 and consent_status_id = 2 and role_id = 33 ".format(conf_schema,conf_schema,conf_id,user_id))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results["consent_count"]
def check_coi_count(self,abs_id,conf_schema):
with engine.connect() as conn:
stmt = text(" select count(distinct user_id) as coi_count from {}.abs_topics where abs_id = {}".format(conf_schema,abs_id))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results["coi_count"]
def check_fp_PA_count(self,user_id,conf_schema):
with engine.connect() as conn:
stmt = text("select count(*) as PA_count from {}.abs_topics where user_id = {} and role_id = 35".format(conf_schema,user_id))
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results["PA_count"]
def get_date_config(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from abs_types where conf_id = {} and is_visible = 1 and is_abs = 1".format(conf_id))
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_abstract_home(self,user_id,abs_type,confe_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_abstract_home",[user_id,abs_type,confe_id])
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.close()
return sets
def get_abstract_home_v1(self,user_id,abs_type,confe_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_abstract_home_v1",[user_id,abs_type,confe_id])
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.close()
return sets
def get_next_previous_data_eva(self,abs_id,user_id,eva_abs_type):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_next_previous_eva",[abs_id,user_id,eva_abs_type])
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.close()
return sets
def get_guidelines(self,abs_type,conf_id):
with engine.connect() as conn:
stmt = text('select * from abs_settings where setting_key = "{}_guideline_html" and conf_id = {}'.format(abs_type,conf_id))
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
# def dashboard_content(self,user_id,conf_id):
# with engine.connect() as conn:
# stmt = text('select abt.abs_type,abt.abs_icons,count(ab.abs_type)as abs_count,setting_value as total_count,abt.title,start_date,end_date,abs_type_url,abs_description from abs_types abt'+
# ' left join abstracts ab on abt.abs_type = ab.abs_type and ab.user_id = '+ str(user_id) +' and abs_status_id >= 1 '+
# ' left join abs_settings abset on concat(abt.abs_type,"_count") = abset.setting_key and abset.conf_id ='+ str(conf_id)+
# ' where is_visible = 1 and is_abs = 1 and abt.conf_id = '+ str(conf_id) +' or abt.user_id = '+ str(user_id) +' group by abt.abs_type order by abt.order_by ')
# result = conn.execute(stmt).all()
# return [dict(r._mapping) for r in result] if result else None
def dashboard_content(self,user_id,conf_id,conf_schema):
with engine.connect() as conn:
stmt = text('select abt.abs_type,abt.abs_icons,count(ab.abs_type)as abs_count,setting_value as total_count,abt.title,abt.start_date,abt.end_date,abs_type_url,abs_description,ct.start_date as custom_start_date,ct.end_date as custom_end_date,abt.is_visible,abt.is_abs from abs_types abt'+
' left join ' +str(conf_schema) +'.abstracts ab on abt.abs_type = ab.abs_type and ab.user_id = '+ str(user_id) +' and abs_status_id >= 1 and abs_status_id != 4 and ab.conf_id = abt.conf_id'+
' left join abs_settings abset on concat(abt.abs_type,"_count") = abset.setting_key and abset.conf_id ='+ str(conf_id) +
' left join custom_user_abs_types ct on FIND_IN_SET(abt.abs_type_id,ct.abs_type_ids) and ct.user_id = '+ str(user_id) +
' where is_abs = 1 and abt.conf_id = '+ str(conf_id) +' or abt.user_id = '+ str(user_id) +' group by abt.abs_type order by abt.order_by ')
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_daily_report(self,date,conf_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_abs_trigger_day_reports",[date,conf_id])
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.close()
return sets
def check_abs_types(self,now_date,conf_id):
with engine.connect() as conn:
stmt = text('select * from abs_types where conf_id = '+str(conf_id)+' and abs_type not like "%VAL%" and "'+now_date.strftime('%Y-%m-%d')+'" between start_date and end_date ')
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def check_eva_abs_types(self,now_date,conf_id):
with engine.connect() as conn:
stmt = text(f"""select * from abs_types where conf_id = {conf_id} and abs_type like "%VAL%" and "{now_date.strftime('%Y-%m-%d')}" between start_date and end_date ;""")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_abstract_data(self,conf_id,abs_no,abs_type):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_abstract_view",[conf_id,abs_no,abs_type])
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.close()
return sets
def get_commitment_data_search(self,conf_id,search_word):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_commiment_users_search",[conf_id,search_word])
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
def get_commitment_data_search_public(self,conf_id,search_word):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_commiment_users_search_public",[conf_id,search_word])
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
def get_mail_templates(self,template_name,conf_id):
with engine.connect() as conn:
stmt = text("SELECT * FROM mail_templates where template_name=:template_name and find_in_set(:conf_id,conf_ids) and app_type_id=3 and is_active=1")
result = conn.execute(stmt.bindparams(template_name=template_name,conf_id=conf_id))
results = result.one_or_none()
return results if results else None
def get_template(self,template_name,conf_id):
with engine.connect() as conn:
stmt = text(f"SELECT * FROM abs_templates where template_name='{template_name}' and conf_id = {conf_id}")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
# Harini for KSOS23
def get_search_data_presenting_v1(self,user_type,role_id,search,abs_type,abs_id,society_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_search_coi_v2",[user_type,role_id,search,abs_type,abs_id,society_id])
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
def get_abs_awards(self,abs_type,conf_id):
with engine.connect() as conn:
stmt = text("select * from abs_awards where is_active=1 and conf_id={} and abs_type='{}' order by order_no".format(conf_id,abs_type))
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
# Priyavarthana daily report mail
def getAllConfForTriggerReport(self):
with engine.connect() as conn:
stmt = text("select * from m_app_type mat "+
" inner join society_applications sa on sa.app_type_id=mat.app_type_id"+
" inner join conference c on c.conf_id=sa.conf_id where mat.app_type_id=3 and sa.is_daily_report_mail=1")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_trigger_report_emails_data(self):
with engine.connect() as conn:
stmt = text("select group_concat(c.conf_id) as conf_id,group_concat(c.conf_key) as conf_key,t.full_name,t.email,t.is_separate_mail from trigger_daily_reports_mails t inner join society_applications s on t.conf_id = s.conf_id and s.app_type_id=3 inner join conference c on s.conf_id = c.conf_id where t.is_abs = 1 and t.is_active = 1 and s.is_daily_report_mail = 1 group by t.email,t.is_separate_mail")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_trigger_report_data(self,pre_date):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_abs_trigger_day_reports_v1",[pre_date])
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.close()
return sets
def get_programsheet_data(self,conf_date,conf_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_programsheet_data",[conf_id,conf_date])
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.close()
return sets
def get_programsheet_data_v1(self,conf_date,conf_id,user_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_programsheet_data_v1",[conf_id,conf_date,user_id])
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.close()
return sets
def get_session_view_data(self,session_id,conf_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_session_view_data",[session_id,conf_id])
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.close()
return sets
#check email is already exist or not
def check_email(self,email,society_id):
with engine.connect() as conn:
stmt = self.users.select().where(self.users.c.email.in_([email])).where(self.users.c.society_id.in_([society_id]))
return conn.execute(stmt).first()
#check mobile is already exist or not
def check_mobile(self,mobile,society_id):
with engine.connect() as conn:
stmt = text("select * from users where (mobile= :mobile or whatsapp_number=:mobile) and society_id=:society_id;")
result = conn.execute(stmt.bindparams(mobile=mobile,society_id=society_id))
return result.first()
def get_daily_mail_templates(self,template_name):
with engine.connect() as conn:
stmt = text(f"SELECT * FROM mail_templates where template_name = '{template_name}' and app_type_id=3 and is_active=1;")
result = conn.execute(stmt).first()
# result = dict(result._mapping) if result else None
return result
#count email is already exist or not
def count_email(self,user_id,email,society_id):
with engine.connect() as conn:
stmt = text("select count(*) from users where user_id <> :user_id and email= :email and society_id=:society_id;")
result = conn.execute(stmt.bindparams(user_id=user_id,email=email,society_id=society_id))
results = result.first()
if results :
return results
else:
return None
def check_bo_access(self,email,app_type_id,society_id,conf_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_check_admin_access",[email,app_type_id,society_id,conf_id])
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[0]
else :
return None
def get_country_isd_code(self):
with engine.connect() as conn:
stmt = text("select * from countries where isd_code is not null order by country_name")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_next_previous_data_eva_v1(self,abs_id,user_id,eva_abs_type,conf_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_next_previous_eva_v1",[abs_id,user_id,eva_abs_type,conf_id])
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.close()
return sets
def session_data_InsertToSqlite_1(self):
sqlite_conn = sqlite3.connect('sqlite_database.db')
tables = ['societies', 'conference', 'society_applications', 'mail_setting','app_style','admin_access','map_menu_conf','m_app_menu','map_admin_menu']
for table in tables:
mysql_query = f"SELECT * FROM {table}"
df = pd.read_sql(mysql_query, engine)
df.to_sql(table, sqlite_conn, if_exists='replace', index=False)
sqlite_conn.commit()
engine.dispose()
sqlite_conn.close()
return "success"
def session_data_InsertToSqlite_MergeTag(self):
sqlite_conn = sqlite3.connect('sqlite_database.db')
tables = ['merge_tags']
for table in tables:
mysql_query = f"SELECT * FROM {table}"
df = pd.read_sql(mysql_query, engine)
df.to_sql(table, sqlite_conn, if_exists='replace', index=False)
sqlite_conn.commit()
engine.dispose()
sqlite_conn.close()
return "success"
def get_bo_layout_data(self,conf_id,admin_email,app_type_id):
with engine_sqlite.connect() as conn:
other_admin = text("select admin_role_id from admin_access where admin_email = '{}' and conf_id ={} and admin_role_id not in (2) and app_type_id ={} ".format(admin_email,conf_id,app_type_id));
adminresult = conn.execute(other_admin).one_or_none()
if adminresult:
stmt = text("Select ma.menu_id,mmc.conf_id,(case when is_cus_menu_name = 1 then mmc.custom_menu_name else ma.menu_name end ) as display_name ,ma.parent_menu_id,ma.url,ma.is_custom_url,ma.full_url,ma.parameter,mmc.is_visible,custom_sub_menu,menu_icon from map_menu_conf mmc "+
" inner join m_app_menu ma on ma.menu_id = mmc.menu_id "+
" inner join admin_access a on a.conf_id = mmc.conf_id "+
" inner join map_admin_menu maa on maa.admin_access_id = a.admin_access_id and maa.menu_ids = mmc.menu_id "+
" where a.admin_email = '{}' and mmc.conf_id = {} and mmc.is_visible = 1 and ma.app_type_id = {} order by mmc.order_by ASC".format(admin_email,conf_id,app_type_id))
else :
stmt=text("Select ma.menu_id,mmc.conf_id,(case when is_cus_menu_name = 1 then mmc.custom_menu_name else ma.menu_name end ) as display_name ,ma.parent_menu_id,ma.url,ma.is_custom_url,ma.full_url,ma.parameter,mmc.is_visible,custom_sub_menu,menu_icon from map_menu_conf mmc "+
" inner join m_app_menu ma on ma.menu_id = mmc.menu_id and ma.app_type_id = 3 "+
" Where mmc.conf_id = {} and mmc.is_visible = 1 order by mmc.order_by ASC".format(conf_id))
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def GetMergeTags(self,conf_id):
with engine_sqlite.connect() as conn:
stmt = text("select * from merge_tags where conf_id ="+str(conf_id)+"")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_delegate_app(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from society_applications where conf_id = {} and app_type_id = 2".format(conf_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_profileupdate_app(self,society_id):
with engine.connect() as conn:
stmt = text("select * from society_applications where society_id = {} and app_type_id = 4".format(society_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_delegates(self,user_id,conf_id):
with engine.connect() as conn:
stmt = text("select * from delegates where conference_id = {} and user_id = {} and del_status_id=2 limit 1".format(conf_id,user_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def GetSocietyAttachment(self,society_id):
with engine.connect() as conn:
stmt = text("select * from m_attachment_type where society_id ="+str(society_id)+"")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_user_attach(self,attach_id,attach_type_id):
with engine.connect() as conn:
stmt = text("select * from user_attachments where attach_id = "+str(attach_id)+" and attach_type_id = " +str(attach_type_id)+";")
result = conn.execute(stmt).first()
if result:
return dict(result._mapping)
else:
return None
def update_image(self,attach_type_id,data):
with engine.connect() as conn:
stmt = self.user_attachments.update().where(self.user_attachments.c.attach_id.in_([attach_type_id])).values(data)
result = conn.execute(stmt)
conn.commit()
if result:
return 'success'
else :
return 'fail'
def insert_image(self,data):
with engine.connect() as conn:
result = conn.execute(self.user_attachments.insert(), data)
conn.commit()
pk_id = result.inserted_primary_key[0] if result.inserted_primary_key[0] else None
return pk_id
def delete_image(self,attach_id,attach_type_id):
with engine.connect() as conn:
stmt = text("delete from user_attachments WHERE attach_id = "+str(attach_id)+" and attach_type_id ="+str(attach_type_id)+";")
results = conn.execute(stmt)
conn.commit()
if results:
return 'success'
else :
return 'fail'
def get_image(self,user_id,society_id):
with engine.connect() as conn:
stmt = text("select ma.*,ua.attach_file_name,ua.attach_path,ua.attach_id from m_attachment_type as ma left join user_attachments as ua on ma.attach_type_id=ua.attach_type_id and user_id={} where society_id={} ".format(user_id,society_id))
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def get_user_image(self,user_id,):
with engine.connect() as conn:
stmt = text("select * from user_attachments where user_id={} ".format(user_id))
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def save_evaluation_consent_responce(self,eva_type,eva_id,conf_id,consent_status_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_save_evaluator_consent",[eva_type,eva_id,conf_id,consent_status_id])
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
def get_aadhar_image(self,user_id,society_id,attach_type_id):
with engine.connect() as conn:
stmt = text("select ma.*,ua.attach_file_name,ua.attach_path,ua.attach_id from m_attachment_type as ma left join user_attachments as ua on ma.attach_type_id=ua.attach_type_id and user_id={} where society_id={} and ma.attach_type_id={} ".format(user_id,society_id,attach_type_id))
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def get_user_image(self,user_id):
with engine.connect() as conn:
stmt = text("select * from user_attachments where user_id={} ".format(user_id))
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def get_user_aadhaarimage(self,user_id):
with engine.connect() as conn:
stmt = text("select * from user_attachments where user_id={} and attach_type_id=69 ".format(user_id))
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def update_step_pre(self,data,abs_id,conf_schema):
abs_topics = Table("abs_topics", self.meta, schema=conf_schema, autoload_with=engine)
with engine.connect() as conn:
stmt = abs_topics.update().values(data).where(abs_topics.c.abs_id.in_([abs_id])).where(abs_topics.c.role_id.in_(['35']))
result = conn.execute(stmt)
conn.commit()
return None
app.jinja_env.globals.update(UserModel=UserModel)
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists