Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from .. import Cryptography,Auth
from core import app
import json
import datetime
from datetime import timedelta,date,datetime
from .. import engine
class AbstractModel():
def __init__(self):
try:
self.meta = MetaData()
self.sa_abstracts = Table("sa_abstracts", self.meta, autoload_with=engine)
self.author = Table("sa_topics", self.meta, autoload_with=engine)
self.marks = Table("abs_marks", self.meta, autoload_with=engine)
self.abs_uploads = Table("abs_uploads", self.meta, autoload_with=engine)
except Exception as e:
print(e)
def get_abstracts_by_user(self,user_id,abs_type):
with engine.connect() as conn:
stmt = text(f"select * from sa_abstracts where user_id ={user_id} and abs_type = '{abs_type}'")
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_abs_type_data(self,abs_type,conf_id):
with engine.connect() as conn:
stmt = text("select * from abs_types where conf_id = {} and abs_type = '{}' ".format(conf_id,abs_type))
result = conn.execute(stmt).first()
conn.close()
result = dict(result._mapping) if result else None
return result
def get_abstracts_by_user_abs_id(self,user_id,abs_id):
with engine.connect() as conn:
stmt = text("select * ,ab.abs_status_id as status_check from sa_abstracts ab left join abs_categories c on ab.category_id=c.category_id left join abs_uploads abu on ab.abs_id = abu.abs_id where user_id ={} and ab.abs_id = {}".format(user_id,abs_id))
result = conn.execute(stmt).first()
conn.close()
result = dict(result._mapping) if result else None
return result
def mainauthor(self,user_id,abs_id):
with engine.connect() as conn:
stmt = text("insert into sa_topics (user_id,abs_id,role_id) VALUES('{}','{}',32)".format(user_id,abs_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def add_to_authors(self,data,abs_id):
with engine.connect() as conn:
stmt = text("select user_id from sa_abstracts where abs_id = {}".format(abs_id));
result = conn.execute(stmt).first()
results = dict(result._mapping) if result else None
db_user_id= results["user_id"]
if(int(db_user_id) == int(data["user_id"])):
data['consent_status_id'] = '2'
result = conn.execute(self.author.insert(),data)
conn.commit()
conn.close()
return None
def get_authors_1(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT u.user_id, concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name, u.membership_no,a.abs_id,u.email,u.mobile,a.topic_id, a.topic ,a.duration,a.order_no,ab.panel_discussion,a.consent_status_id FROM users u JOIN sa_topics a ON u.user_id = a.user_id JOIN sa_abstracts ab on a.abs_id = ab.abs_id WHERE a.abs_id = {} and (a.role_id = 33 or a.role_id = 36) and a.consent_status_id = 0 order by order_no ;".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_authors(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT u.user_id, concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name, u.membership_no,a.abs_id,u.email,u.mobile,a.topic_id, a.topic ,a.duration,a.order_no,ab.panel_discussion,a.consent_status_id,a.misc1,u.institution FROM users u JOIN sa_topics a ON u.user_id = a.user_id JOIN sa_abstracts ab on a.abs_id = ab.abs_id WHERE a.abs_id = {} and (a.role_id = 33 or a.role_id = 36) order by order_no ;".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_mem_authors(self,abs_id,mem_type):
with engine.connect() as conn:
stmt = text("SELECT u.user_id, concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name, u.membership_no,a.abs_id,u.email,u.mobile,a.topic_id, a.topic ,a.duration,a.order_no,ab.panel_discussion,a.consent_status_id,a.misc1 FROM users u JOIN sa_topics a ON u.user_id = a.user_id JOIN sa_abstracts ab on a.abs_id = ab.abs_id WHERE a.abs_id = {} and (a.role_id = 33 or a.role_id = 36) and u.member_type_id in ({}) order by order_no ;".format(abs_id,mem_type))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_GP_authors(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT u.user_id, concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name, u.membership_no,a.abs_id,u.email,u.mobile,a.topic_id, a.topic ,a.duration,a.order_no,ab.panel_discussion,a.consent_status_id,absr.role,absr.role_id FROM users u JOIN sa_topics a ON u.user_id = a.user_id left JOIN sa_abstracts ab on a.abs_id = ab.abs_id left join abs_roles absr on a.role_id = absr.role_id WHERE a.abs_id = {} order by order_no ;".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_panel_disscussion(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT panel_discussion from sa_abstracts where abs_id = {};".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def delete_author_userid(self,topic_id):
with engine.connect() as conn:
stmt = text("delete from sa_topics where topic_id ={}".format(topic_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def get_author_for_edit(self,topic_id):
with engine.connect() as conn:
stmt = text("select u.membership_no,u.user_id,concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name,u.email,u.mobile,a.topic,a.duration,a.order_no,a.topic_id,a.misc1 from users u inner join sa_topics a on u.user_id = a.user_id where a.topic_id = {} ;".format(topic_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
# def edit_to_authors(self,data,topic_id):
# stmt = text("update sa_topics set topic ='{}',duration='{}',order_no='{}' where topic_id={}".format(data["topic"],data["duration"],data["order_no"],topic_id))
# conn = engine.connect()
# result = conn.execute(stmt)
# conn.close()
# return None
def edit_to_authors(self,data,topic_id):
with engine.connect() as conn:
stmt = self.author.update().values(data).where(self.author.c.topic_id.in_([topic_id]))
# stmt = text("update sa_topics set topic ='{}',duration='{}',order_no='{}',misc1='{}' where topic_id={}".format(data["topic"],data["duration"],data["order_no"],data['misc1'],topic_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return None
def total_duration(self,abs_id,panel_discussion,confe_name,conf_id):
with engine.connect() as conn:
duration_db = AbstractModel().settings(confe_name+"_Duration",conf_id)
if panel_discussion or panel_discussion == 0:
stmt = text("select sum(a.duration) as duration from sa_topics as a join sa_abstracts as ab on a.abs_id = ab.abs_id where a.abs_id = {} group by a.abs_id;".format(abs_id))
result = conn.execute(stmt).first()
results = dict(result._mapping) if result else None
duration = results["duration"]
if duration == None:
duration=0
checkduration = duration+panel_discussion
if checkduration <= int(duration_db[0][0]["setting_value"]):
stmt = text("update sa_abstracts set panel_discussion = '{}' where abs_id ='{}'".format(panel_discussion,abs_id))
result = conn.execute(stmt)
conn.commit()
stmt = text("select sum(a.duration)+ab.panel_discussion as duration from sa_topics as a join sa_abstracts as ab on a.abs_id = ab.abs_id where a.abs_id = {} group by a.abs_id;".format(abs_id))
result = conn.execute(stmt).first()
results = dict(result._mapping) if result else None
conn.close()
duration = results["duration"]
if duration == None:
duration=0
return duration
else :
stmt = text("select sum(a.duration) as duration from sa_topics as a join sa_abstracts as ab on a.abs_id = ab.abs_id where a.abs_id = {} group by a.abs_id;".format(abs_id))
result = conn.execute(stmt).first()
results = dict(result._mapping) if result else None
duration = results["duration"]
if duration == None:
duration=0
data =duration+panel_discussion
conn.close()
return data
else :
stmt = text("select sum(a.duration)+ab.panel_discussion as duration from sa_topics as a join sa_abstracts as ab on a.abs_id = ab.abs_id where a.abs_id = {} group by a.abs_id;".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["duration"]
def authors_total_duration_for_edit(self,abs_id,topic_id):
with engine.connect() as conn:
stmt = text("select a.abs_id,sum(a.duration)+ab.panel_discussion as total_duration from sa_topics as a join sa_abstracts as ab on ab.abs_id = a.abs_id where a.abs_id = {} and a.topic_id not in ({}) group by a.abs_id ;".format(abs_id,topic_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["total_duration"]
def check_authors_id_by_abs_id(self,abs_id):
with engine.connect() as conn:
stmt = text("select count(*) as check_topic_id from sa_topics where abs_id = {} ;".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["check_topic_id"]
def get_sept4_data(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT ab.*,abss.setting_value,u.user_id, concat(u.prefix,u.full_name)as full_name,u.membership_no,u.email,u.mobile,c.display_name,p.type,ab.abs_status_id as status_check,SUM(a.duration) + ab.panel_discussion AS total_duration,abu.path,abu.file_name,aw.award_name,aw.award_id,ast.start_date,ast.end_date,ah.name as hall_name,ase.type as selection_type FROM sa_abstracts AS ab "
+" inner JOIN users u ON ab.user_id = u.user_id "
+" left JOIN sa_topics AS a ON a.abs_id = ab.abs_id"
+" left join abs_presentation_type p on ab.presentation_type_id=p.presentation_type_id "
+" left join sa_settings abss on abss.setting_key = concat(ab.abs_type,'_guideline') and abss.conf_id = ab.conf_id "
+" left join abs_uploads abu on abu.abs_id = ab.abs_id "
+" left JOIN abs_categories c ON c.category_id = ab.category_id"
+" left join abs_session_types ast on ast.abs_session_id=ab.abs_session_id "
+" left join abs_halls ah on ah.hall_id=ast.hall_id and ah.conf_id=ab.conf_id"
+" left join abs_selection_type ase on ase.selection_type_id=ab.selection_type_id"
+" left JOIN abs_awards aw ON aw.award_id = ab.award_id WHERE ab.abs_id = {}".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
results[0]['abs_id'] = abs_id
return results[0]
def get_eval_data(self,mark_id):
with engine.connect() as conn:
stmt = text("select m.*,eva_id as eva_id,ab.*,c.display_name,p.type from sa_abstracts ab join abs_marks m on ab.abs_id = m.abs_id left join abs_presentation_type p on ab.presentation_type_id=p.presentation_type_id left JOIN abs_categories c ON ab.category_id = c.category_id where mark_id = {};".format(mark_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def total_duration_step4(self,abs_id):
with engine.connect() as conn:
stmt = text("select sum(a.duration)+ab.panel_discussion as duration from sa_topics as a join sa_abstracts as ab on a.abs_id = ab.abs_id where a.abs_id = {} group by a.abs_id;".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["duration"]
def abstract_submited(self,user_id,abs_id,abs_type,data):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_sa_set_abs_no",[user_id,abs_id,data['submitted_at'],abs_type])
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
connection.close()
if results :
return "success"
else :
return "fail"
def abstract_submited_v1(self,user_id,abs_id,abs_type,data,conf_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_set_ic_no_v2",[user_id,abs_id,data['submitted_at'],abs_type,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()
connection.close()
if results :
return "success"
else :
return "fail"
def get_usp_type_of_presentation(self,user_id,conf_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_presentation_type",[user_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()
connection.close()
return results
def get_paticipate_co_instructor(self,user_id,abs_type):
with engine.connect() as conn:
stmt=text("select abs_id as abs_id_group from sa_abstracts where user_id = {} and abs_type = '{}';".format(user_id,abs_type))
result = conn.execute(stmt).all()
abs_ids = []
results = [dict(r._mapping) for r in result] if result else None
if results == []:
abs_ids.append(0)
for i in results:
abs_ids.append(i["abs_id_group"])
string_ints = [str(int) for int in abs_ids]
abs_ids = ",".join(string_ints)
stmt1 = text("select ab.title,ab.user_id,ab.abs_id,a.topic,concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name,ab.abs_type,a.topic_id,a.consent_status_id,ab.abs_status_id from sa_topics as a join sa_abstracts as ab on ab.abs_id = a.abs_id join users as u on u.user_id=ab.user_id where ab.abs_type ='{}' and a.user_id = {} and a.abs_id not in ({}) group by a.topic_id ;".format(abs_type,user_id,abs_ids))
result = conn.execute(stmt1).all()
results = [dict(r._mapping) for r in result] if result else None
conn.close()
if results == []:
data={}
return data
else:
return results
""" Setting function called in templates """
def settings(self,abs_type):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_sa_get_settings",[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 status_to_db(self,topic_id,status):
with engine.connect() as conn:
stmt = text("update sa_topics set consent_status_id = {} where topic_id = {}".format(status,topic_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return "succes"
def check_consent_status(self,topic_id):
with engine.connect() as conn:
stmt = text("select consent_status_id,abs_id from sa_topics where topic_id = {}".format(topic_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def get_coi_by_topic_id(self,topic_id):
with engine.connect() as conn:
stmt = text("select * from sa_topics as a join users as u on u.user_id=a.user_id where topic_id = {}".format(topic_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def check_authors_count(self,abs_id,role_id):
with engine.connect() as conn:
stmt = text("select count(*)as authors_count,ifnull(abs_status_id,0) as abs_status_id,ab.panel_discussion from sa_topics a inner join sa_abstracts ab on a.abs_id=ab.abs_id where a.abs_id = {} and role_id = {}".format(abs_id,role_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def get_type_of_presentation(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from abs_presentation_type where conf_id = {}".format(conf_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def add_to_GP_author(self,abs_id,user_id):
with engine.connect() as conn:
stmt = text("update sa_abstracts set user_id={} , updated_at = '{}' where abs_id={} ".format(user_id,datetime.now(),abs_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def add_to_GP_presenting_author(self,abs_id,user_id,role_id,topic,order_by,duration):
with engine.connect() as conn:
stmt = text("insert into sa_topics(user_id,abs_id,role_id,topic,order_no,duration,consent_status_id,created_at) VALUES({},{},{},'{}',{},{},2,'{}');".format(user_id,abs_id,role_id,topic,order_by,duration,datetime.now()))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def add_to_teammate(self,abs_id,user_id,role_id):
with engine.connect() as conn:
stmt1 = text("select count(*) as author_count from sa_topics where abs_id={} and role_id = {}".format(abs_id,role_id))
result = conn.execute(stmt1).first()
results = dict(result._mapping) if result else None
if(results["author_count"] == 0 ):
stmt = text("insert into sa_topics(user_id,abs_id,role_id,consent_status_id,created_at) VALUES({},{},36,2,'{}');".format(user_id,abs_id,datetime.now()))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
else:
stmt = text("update sa_topics set user_id={} , updated_at = '{}' where abs_id={} and role_id = 36".format(user_id,datetime.now(),abs_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def add_to_presenting_author(self,abs_id,user_id,role_id):
with engine.connect() as conn:
stmt1 = text("select count(*) as author_count from sa_topics where abs_id={} and role_id = {}".format(abs_id,role_id))
result = conn.execute(stmt1).first()
results = dict(result._mapping) if result else None
if(results["author_count"] == 0 and role_id == "35"):# Inserting presenting author
stmt = text("insert into sa_topics(user_id,abs_id,role_id,consent_status_id,created_at) VALUES({},{},35,2,'{}');".format(user_id,abs_id,datetime.now()))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
elif(int(results["author_count"]) <= 4 and role_id == "36"):# Inserting co author
stmt_1 = text("select count(*) from sa_topics where user_id = {} and abs_id = {} and role_id = 36 ".format(user_id,abs_id))
result = conn.execute(stmt_1).first()
if result[0] < 1:
stmt = text("insert into sa_topics(user_id,abs_id,role_id,consent_status_id,created_at) VALUES({},{},36,2,'{}');".format(user_id,abs_id,datetime.now()))
result = conn.execute(stmt)
conn.commit()
conn.close()
return results
else:# updating Inserting presenting author
stmt = text("update sa_topics set user_id={} , updated_at = '{}' where abs_id={} and role_id = 35".format(user_id,datetime.now(),abs_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def GP_step1_get_author(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT u.membership_no,u.user_id,concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name,u.email,u.mobile from users u join sa_abstracts a ON a.user_id=u.user_id where a.abs_id ={} ;".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def q_step1_get_author(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT u.membership_no,u.user_id,concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name,u.email,u.mobile from users u join sa_topics a ON a.user_id=u.user_id where a.abs_id ={} and a.role_id = 36;".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def FP_step1_get_author(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT u.membership_no,u.user_id,concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name,u.email,u.mobile from users u join sa_topics a ON a.user_id=u.user_id where a.abs_id ={} and a.role_id = 35;".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def get_presentation_type(self,presentation_id):
with engine.connect() as conn:
stmt = text("select type from abs_presentation_type where presentation_type_id = {}".format(presentation_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["type"]
def fp_authors_for_email(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT u.membership_no,u.user_id,concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name,u.email,u.mobile from users u inner join sa_topics a ON a.user_id=u.user_id where a.abs_id ={} and a.role_id not in (69,70) group by a.user_id ;".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def fp_authors_for_email_v1(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT u.membership_no,u.user_id,concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name,u.email,u.mobile from users u inner join sa_topics a ON a.user_id=u.user_id where a.abs_id ={} and role_id not in (36) group by a.user_id ;".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def limit_of_authors(self,abs_id):
with engine.connect() as conn:
stmt= text("select count(DISTINCT(user_id)) as count from sa_topics where abs_id = {} and role_id in (36,33) group by abs_id;".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["count"] if results else 0
def check_submit_status(self,abs_id):
with engine.connect() as conn:
stmt = text("select abs_status_id from sa_abstracts where abs_id = {} ".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["abs_status_id"]
def get_email_consent(self,topic_id):
with engine.connect() as conn:
stmt = text("select concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name,a.topic from sa_topics a join users u on u.user_id=a.user_id where a.topic_id = {}".format(topic_id))
stmt1 = text("select u.email from sa_topics a join sa_abstracts ab on a.abs_id=ab.abs_id join users u on u.user_id=ab.user_id where a.topic_id ={} ".format(topic_id))
co_instructor = conn.execute(stmt).first()
chief_instructor = conn.execute(stmt1).first()
co_instructor_name = dict(co_instructor._mapping)
chief_instructor_email = dict(chief_instructor._mapping)
conn.close()
result = [chief_instructor_email["email"],co_instructor_name["full_name"],co_instructor_name['topic']]
return result
def get_count_of_coi(self,abs_id):
with engine.connect() as conn:
stmt = text("select count(DISTINCT a.user_id) as coi_count,group_concat(DISTINCT a.user_id separator ',') as coi_user_ids from sa_abstracts ab left join sa_topics a on ab.abs_id = a.abs_id where ab.abs_id = {} and role_id = 33 group by a.abs_id".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def get_FP_PA_count_final(self,abs_id,abs_type):
with engine.connect() as conn:
stmt = text("select count(a.user_id) as PA_count from sa_topics a join sa_abstracts ab on a.abs_id=ab.abs_id and abs_type = '{}' where a.user_id = (select user_id from sa_topics where abs_id = {} and role_id = 35) and role_id = 35 and a.abs_id = {}".format(abs_type,abs_id,abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["PA_count"]
def get_FP_PA_count(self,pa_user_id,abs_id,abs_type):
with engine.connect() as conn:
stmt = text("select count(a.user_id) as PA_count from sa_topics a "
+ " join sa_abstracts ab on a.abs_id=ab.abs_id and abs_type = '{}' "
+ " where a.user_id = 1 and role_id = 35 and ab.abs_status_id >0".format(abs_type,pa_user_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["PA_count"]
def get_confe(self,conf_id):
with engine.connect() as conn:
stmt = text("select * 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 where conf_id = {}".format(conf_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_evaluation(self,conf_id,user_id,t_date):
with engine.connect() as conn:
# stmt = text('select abt.* from abs_marks m inner join sa_abstracts ab on m.abs_id = ab.abs_id inner join abs_types abt on abt.abs_type = concat(ab.abs_type,"val") where eva_id = '+str(user_id)+' and is_abs = 0 and "'+t_date.strftime('%Y-%m-%d')+'" between start_date and end_date and abt.conf_id = {} and ab.conf_id= {} group by ab.abs_type '.format(conf_id,conf_id))
stmt = text('select abt.* from abs_marks m inner join abs_types abt on abt.abs_type = m.eva_abs_type left join custom_user_abs_types c on c.user_id = m.eva_id and c.abs_type_ids = abt.abs_type_id where eva_id = '+str(user_id)+' and is_abs = 0 and ("'+str(t_date)+'" between abt.start_date and abt.end_date or "'+str(t_date)+'" between c.start_date and c.end_date ) and abt.conf_id = {} group by abt.abs_type '.format(conf_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def Check_can_upload(self,conf_id,user_id,t_date):
with engine.connect() as conn:
stmt = text('select abt.* from sa_abstracts ab inner join abs_types abt on abt.upload_selection_type = ab.selection_type_id and abt.conf_id=ab.conf_id where abt.conf_id={} and ab.user_id = {} and abs_status_id = 2 and is_abs = 0 and "{}" between start_date and end_date group by abt.abs_type ;'.format(conf_id,user_id,t_date))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_evaluation_list(self,user_id,abs_type,conf_id):
with engine.connect() as conn:
if abs_type == "ICVAL":
stmt = text(f"select abs_type,abs_no,m.mark_id,m.abs_id,title,parent_category_id as category_id,marks_total,ab.user_id from abs_marks m join sa_abstracts ab on m.abs_id = ab.abs_id join abs_categories c on ab.category_id = c.category_id where eva_id = {user_id} and eva_abs_type = '{abs_type}' and ab.conf_id = {conf_id} order by ab.abs_no;")
else:
stmt = text(f"select abs_type,abs_no,m.mark_id,m.abs_id,title,ab.category_id,marks_total,ab.user_id from abs_marks m join sa_abstracts ab on m.abs_id = ab.abs_id join abs_categories c on ab.category_id = c.category_id where eva_id = {user_id} and eva_abs_type = '{abs_type}' and ab.conf_id = {conf_id} order by ab.abs_no;")
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_categories_eva(self,user_id,abs_type,conf_id):
with engine.connect() as conn:
if abs_type == "ICVAL":
stmt = text(f"select abs_type,m.abs_id,parent_category_id as category_id,parent_category as display_name from abs_marks m join sa_abstracts ab on m.abs_id = ab.abs_id join abs_categories c on ab.category_id = c.category_id where ab.conf_id ={conf_id} and eva_id = {user_id} and eva_abs_type = '{abs_type}' group by c.parent_category_id;")
else:
stmt = text(f"select abs_type,m.abs_id,ab.category_id,display_name from abs_marks m join sa_abstracts ab on m.abs_id = ab.abs_id join abs_categories c on ab.category_id = c.category_id where ab.conf_id ={conf_id} and eva_id = {user_id} and eva_abs_type = '{abs_type}' group by c.category_id;")
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def sent_mark(self,abs_id,user_id,eva_abs_type,data):
with engine.connect() as conn:
stmt = self.marks.update().values(data).where(self.marks.c.abs_id.in_([abs_id])).where(self.marks.c.eva_id.in_([user_id])).where(self.marks.c.eva_abs_type.in_([eva_abs_type]))
results = conn.execute(stmt)
conn.commit()
conn.close()
return None
def abstract_home_validation(self,abs_type,user_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_sa_abstract_validation",[user_id,abs_type,datetime.now()])
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
connection.close()
if results :
return results[0]
else :
return "fail"
def settings_mail(self,setting_mail_id,conf_id):
with engine.connect() as conn:
stmt = text("select * from abs_settings where setting_key = '{}' and conf_id = {};".format(setting_mail_id,conf_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def update_imge_db(self,abs_id,data1):
with engine.connect() as conn:
stmt = text("insert into abs_uploads (abs_id,file_name,path,created_at,img_type) value({},'{}','{}','{}','{}');".format(abs_id,data1["file_name"],data1["path"],datetime.now(),data1['img_type']))
stmt_1 = text("select max(upload_id) as max from abs_uploads where abs_id = {} ".format(abs_id))
result = conn.execute(stmt)
conn.commit()
result = conn.execute(stmt_1).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def update_imge_db_v1(self,abs_id,data1):
with engine.connect() as conn:
stmt = text("insert into abs_uploads (abs_id,file_name,path,img_type,created_at) value({},'{}','{}','{}','{}');".format(abs_id,data1["file_name"],data1["path"],data1["img_type"],datetime.now()))
stmt_1 = text("select max(upload_id) as max from abs_uploads where abs_id = {} ".format(abs_id))
result = conn.execute(stmt)
conn.commit()
result = conn.execute(stmt_1).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def get_img_upload(self,abs_id):
with engine.connect() as conn:
stmt = text("select * from abs_uploads where abs_id = {} and img_type is not null;".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def get_img_upload_by_upload_id(self,upload_id):
with engine.connect() as conn:
stmt = text("select * from abs_uploads where upload_id = {} ;".format(upload_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def get_img_upload_count(self,abs_id):
with engine.connect() as conn:
stmt = text("select * from abs_uploads where abs_id = {};".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def delete_image(self,abs_id):
with engine.connect() as conn:
conn = engine.connect()
stmt = text("delete from abs_uploads where abs_id = {};".format(abs_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def delete_image_v2(self,abs_id,filename):
with engine.connect() as conn:
stmt = text("delete from abs_uploads where abs_id = {} and file_name = '{}';".format(abs_id,filename))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def delete_abs_upload(self,upload_id):
with engine.connect() as conn:
stmt = text("delete from abs_uploads where upload_id = {} ;".format(upload_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def delete_image_v1(self,abs_id,file_type):
with engine.connect() as conn:
stmt = text("delete from abs_uploads where abs_id = {} and img_type = '{}';".format(abs_id,file_type))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def get_upload_photo_count(self,abs_id):
with engine.connect() as conn:
stmt = text("select count(*) as img_count , count(a.abs_id) as team_count from abs_uploads au left join sa_topics a on au.abs_id = a.abs_id and role_id = 36 where au.abs_id = {}".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def get_member_type_count(self,abs_id):
with engine.connect() as conn:
stmt = text("select count(*) as mem_type from sa_topics a inner join users u on a.user_id = u.user_id where abs_id = {} and member_type_id in (1,6) ".format(abs_id))
conn = engine.connect()
result = conn.execute(stmt).fetchone()
conn.close()
return result[0]
def get_change_author(self,abs_id):
with engine.connect() as conn:
stmt = text("select topic_id,abt.user_id,topic,abt.duration,concat(ifnull(prefix,''),ifnull(full_name,'')) as full_name,mobile,email,membership_no from sa_abstracts ab "+
" inner join sa_topics abt on ab.abs_id = abt.abs_id "+
" inner join users u on u.user_id = abt.user_id "+
" where ab.abs_id = {} and abt.role_id = 33 and consent_status_id in (0,3); ".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def update_coi_user(self,topic_id,user_id):
with engine.connect() as conn:
stmt = text("update sa_topics set user_id = {}, consent_status_id = 0 where topic_id = {} ".format(user_id,topic_id))
result = conn.execute(stmt)
conn.commit()
stmt_1 = text("SELECT u.user_id, concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name, u.membership_no,a.abs_id,u.email,u.mobile,a.topic_id, a.topic ,a.duration,a.order_no,ab.panel_discussion,a.consent_status_id FROM users u JOIN sa_topics a ON u.user_id = a.user_id inner JOIN sa_abstracts ab on a.abs_id = ab.abs_id WHERE a.topic_id = {} and a.consent_status_id = 0 order by order_no ;".format(topic_id))
result = conn.execute(stmt_1).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def limit_of_instructors(self,abs_id):
with engine.connect() as conn:
stmt= text("select count(DISTINCT(user_id)) as count from sa_topics where abs_id = {} and role_id in (36,33) and user_id != (select user_id from sa_topics where abs_id = {} and role_id =32) group by abs_id;".format(abs_id,abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["count"] if results else 0
# Harini for KSOS pannel discussion
def get_panel_disscussion_v1(self,abs_id):
with engine.connect() as conn:
stmt = text("select ab.abs_id, ab.abs_type, ab.panel_discussion,ab.duration,(ab.duration - sum(ifnull(a.duration,0))) as total_duration_ab from sa_topics a left join sa_abstracts ab on ab.abs_id= a.abs_id where a.abs_id = {};".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def update_panel(self,data2,abs_id):
with engine.connect() as conn:
stmt = self.sa_abstracts.update().values(data2).where(self.sa_abstracts.c.abs_id.in_([abs_id]))
# stmt = text("update sa_topics set topic ='{}',duration='{}',order_no='{}',misc1='{}' where topic_id={}".format(data["topic"],data["duration"],data["order_no"],data['misc1'],topic_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return None
def total_duration_step4_v1(self,abs_id):
with engine.connect() as conn:
stmt = text("select sum(a.duration) as duration from sa_topics as a join sa_abstracts as ab on a.abs_id = ab.abs_id where a.abs_id = {} group by a.abs_id;".format(abs_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["duration"]
def authors_total_duration_for_edit_v1(self,abs_id,topic_id):
with engine.connect() as conn:
stmt = text("select a.abs_id,sum(a.duration) as total_duration from sa_topics as a join sa_abstracts as ab on ab.abs_id = a.abs_id where a.abs_id = {} and a.topic_id not in ({}) group by a.abs_id ;".format(abs_id,topic_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["total_duration"]
# mukesh added for TNASI conference
def Check_if_delegate(self,conf_id,email):
with engine.connect() as conn:
stmt = text("select count(*) as count from delegates where conference_id = {} and email = '{}' and delegate_no is not null; ;".format(conf_id,email))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["count"]
def get_img_upload_by_abs_id(self,abs_id):
with engine.connect() as conn:
stmt = text("select * from abs_uploads where abs_id = {};".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_img_upload_v1(self,abs_id,file_type):
with engine.connect() as conn:
stmt = text("select * from abs_uploads where abs_id = '{}' and img_type = '{}';".format(abs_id,file_type))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results
def get_authors_v1(self,abs_id,role_id):
with engine.connect() as conn:
stmt = text("SELECT u.user_id, concat(ifnull(u.prefix,''),ifnull(u.full_name,'')) as full_name, u.membership_no,a.abs_id,u.email,u.mobile,a.topic_id, a.topic ,a.duration,a.order_no,ab.panel_discussion,a.consent_status_id,a.misc1,u.institution FROM users u JOIN sa_topics a ON u.user_id = a.user_id JOIN sa_abstracts ab on a.abs_id = ab.abs_id WHERE a.abs_id = {} and a.role_id = {} order by order_no ;".format(abs_id,role_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def limit_of_authors_v1(self,abs_id,role_id):
with engine.connect() as conn:
stmt= text("select count(DISTINCT(user_id)) as count from sa_topics where abs_id = {} and role_id = {} group by abs_id;".format(abs_id,role_id))
result = conn.execute(stmt).first()
conn.close()
results = dict(result._mapping) if result else None
return results["count"]
def add_to_author(self,abs_id,user_id,role_id):
with engine.connect() as conn:
stmt1 = text("select count(*) as author_count from sa_topics where abs_id={} and role_id = {}".format(abs_id,role_id))
result = conn.execute(stmt1).first()
results = dict(result._mapping) if result else None
if(int(results["author_count"]) <= 4 ):# Inserting co author
stmt_1 = text("select count(*) from sa_topics where user_id = {} and abs_id = {} and role_id = {} ".format(user_id,abs_id,role_id))
result = conn.execute(stmt_1).fetchone()
if result[0] < 1:
stmt = text("insert into sa_topics(user_id,abs_id,role_id,consent_status_id,created_at) VALUES({},{},{},2,'{}');".format(user_id,abs_id,role_id,datetime.now()))
result = conn.execute(stmt)
conn.commit()
conn.close()
return results
else:# updating Inserting presenting author
stmt = text("update sa_topics set user_id={} , updated_at = '{}' where abs_id={} and role_id = {}".format(user_id,datetime.now(),abs_id,role_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
def get_abs_award(self,conf_id,abs_type):
with engine.connect() as conn:
stmt = text("select * from abs_awards where conf_id = {} and abs_type = '{}';".format(conf_id,abs_type))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_abs_uploads(self,abs_id):
with engine.connect() as conn:
stmt = text("select * from abs_uploads where abs_id ={} ".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def checkexistsfile(self,abs_id,filename):
with engine.connect() as conn:
stmt = text("select * from abs_uploads where abs_id ={} and file_name ='{}' ".format(abs_id,filename))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_coauthors_group(self,abs_id):
with engine.connect() as conn:
stmt = text("SELECT u.user_id, group_concat(concat(ifnull(u.prefix,''),ifnull(u.full_name,''))) as full_name FROM users u JOIN sa_topics a ON u.user_id = a.user_id JOIN sa_abstracts ab on a.abs_id = ab.abs_id WHERE a.abs_id = {} and (a.role_id = 33 or a.role_id = 36) order by order_no ;".format(abs_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def update_chief_author(self,abs_id,user_id,role_id):
with engine.connect() as conn:
stmt = text("update sa_abstracts set user_id={} , updated_at = '{}' where abs_id={} ".format(user_id,datetime.now(),abs_id))
result = conn.execute(stmt)
stmt_1 = text("update sa_topics set user_id={} , updated_at = '{}' where abs_id={} and role_id = {}".format(user_id,datetime.now(),abs_id,role_id))
result_1 = conn.execute(stmt_1)
conn.commit()
conn.close()
return result_1
# FullText -------------------------------------------------------------------------------------------------------------------------------------------------------
def get_submitted_abstract(self,user_id,conf_id,selection_type_id):
with engine.connect() as conn:
stmt= text(f"select ab.abs_id,ab.user_id, concat(ab.abs_type,ab.abs_no,'-',ab.title) as abstract,ab.abs_type,ab.conf_id,au.file_name,au.path,upload_ext_type,upload_file_size,upload_image_type,upload_guideline from sa_abstracts ab left join abs_uploads au on au.abs_id = ab.abs_id and img_type is not null left join abs_types abt on abt.upload_selection_type=ab.selection_type_id and abt.conf_id=ab.conf_id where ab.user_id ={user_id} and ab.conf_id={conf_id} and ab.selection_type_id={selection_type_id} and ab.abs_status_id =2 ")
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_img_upload_by_user_id(self,conf_id):
with engine.connect() as conn:
stmt= text("select ab.user_id, ab.abs_id,au.file_name,au.path from sa_abstracts ab left join abs_uploads au on au.abs_id = ab.abs_id where conf_id = {};".format(conf_id));
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_fulltext_by_abs_id(self,abs_id):
with engine.connect() as conn:
stmt= text("select * from abs_uploads au left join sa_abstracts ab on ab.abs_id=au.abs_id where ab.abs_id = {} and img_type is not null ;".format(abs_id));
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_upload_status_data(self,conf_id):
with engine.connect() as conn:
stmt= text("select s.type,count(*) as total,sum(case when upload_id is not null then 1 else 0 end) as received,sum(case when upload_id is null then 1 else 0 end) as pending from sa_abstracts a inner join abs_selection_type s on a.selection_type_id = s.selection_type_id left join abs_uploads au on au.abs_id = a.abs_id where a.conf_id = {} and abs_status_id = 2 and abs_type in ('FP','IC') group by a.selection_type_id ;".format(conf_id))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_upload_data_by_status(self,conf_id,status,selection_type):
with engine.connect() as conn:
where_con = ''
where_con_1 = ''
if status == 'Pending':
where_con = ' and upload_id is null'
if status == 'Received':
where_con = ' and upload_id is not null'
if selection_type and int(selection_type) == 13 :
where_con_1 = ' and role_id = 32'
else:
where_con_1 = ' and role_id = 35'
stmt = text('''select concat(ifnull(u.prefix,''),u.full_name) as full_name,u.email,u.mobile,a.abs_id,abs_type,abs_no,title,au.path,au.file_name,s.type,au.upload_id,s.selection_type_id,s.type from sa_abstracts a inner join sa_topics ast on ast.abs_id=a.abs_id inner join users u on u.user_id=ast.user_id inner join abs_selection_type s on a.selection_type_id = s.selection_type_id left join abs_uploads au on au.abs_id = a.abs_id where a.conf_id = {} and abs_status_id = 2 and a.selection_type_id in ({}) and abs_type in ('FP','IC') {} {} order by s.type,abs_type,abs_no;'''.format(conf_id,selection_type,where_con,where_con_1))
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def UpdateAjaxCall(self,abs_id,data):
with engine.connect() as conn:
stmt = self.sa_abstracts.update().values(data).where(self.sa_abstracts.c.abs_id.in_([abs_id]))
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
app.jinja_env.globals.update(AbstractModel=AbstractModel)
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists