Sindbad~EG File Manager
from flask import session
from flask import request, Blueprint, jsonify
from sqlalchemy import create_engine, select, MetaData, Table,text
from sqlalchemy.sql import and_, or_
from core import app
engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class CurrentSessionModel():
def __init__(self):
try:
self.meta = MetaData()
except Exception as e:
print(e)
def getCurrentActiveSession(self,abs_session_table,conf_id,conf_key,current_dt):
with engine.connect() as conn:
stmt = text("select * from "+str(abs_session_table)+" where conf_id ="+str(conf_id)+" and '"+current_dt+"' between date(starts_by) and date(ends_by) and is_active=1;")
result = conn.execute(stmt).all()
conn.close()
return [dict(r._mapping) for r in result] if result else None
# def updateActiveSession(self,conf_id,current_date,hall_id,asession_id,is_active):
# connection = engine.raw_connection()
# cursor = connection.cursor()
# cursor.callproc("usp_update_current_active_session",[conf_id,current_date,hall_id,asession_id,is_active])
# if cursor.description :
# columns = [column[0] for column in cursor.description]
# results = []
# for row in cursor.fetchall():
# results.append(dict(zip(columns, row)))
# cursor.close()
# connection.commit()
# if results :
# return results
# else :
# return None
# else :
# cursor.close()
# connection.commit()
# return None
def getSessionName_activated(self,abs_session_table,conf_id,hall_id,conf_date) :
with engine.connect() as conn:
stmt = text ("SELECT * from "+str(abs_session_table)+" where conf_id=:conf_id and hall_id=:hall_id and dt=:conf_date order by starts_by asc,asession_id ")
results = conn.execute(stmt.bindparams(conf_id=conf_id,hall_id=hall_id,conf_date=conf_date)).all()
conn.close()
return [dict(r._mapping) for r in results] if results else None
# def updateActiveSession(self,table_name,conf_id,current_date,hall_id,asession_id,is_active):
# if int(is_active) == 1:
# stmt=text("update "+str(table_name)+ " set is_active=0 where dt='{}' and hall_id={} and conf_id={}".format(current_date,hall_id,conf_id))
# stmt_1=text("update "+str(table_name)+ " set is_active={} where asession_id={} and conf_id={}".format(is_active,asession_id,conf_id))
# conn = engine_conf.connect()
# result = conn.execute(stmt)
# result_1 = conn.execute(stmt_1)
# conn.close()
# if result:
# return "succes"
# else:
# return None
def updateActiveSession(self,table_name,conf_id,current_date,hall_id,asession_id,is_active):
with engine_conf.connect() as conn:
if int(is_active) == 1:
stmt=text("update "+str(table_name)+ " set is_active=0 where dt='{}' and hall_id={} and conf_id={}".format(current_date,hall_id,conf_id))
result = conn.execute(stmt)
stmt_1=text("update "+str(table_name)+ " set is_active={} where asession_id={} and conf_id={}".format(is_active,asession_id,conf_id))
result_1 = conn.execute(stmt_1)
conn.commit()
conn.close()
if result_1:
return "success"
else:
return None
def updateNoActiveSession(self,table_name,conf_id,current_date,abs_hall_id,is_active):
with engine_conf.connect() as conn:
stmt=text("update "+str(table_name)+ " set is_active={} where dt='{}' and hall_id={} and conf_id={}".format(is_active,current_date,abs_hall_id,conf_id))
result = conn.execute(stmt)
conn.commit()
conn.close()
if result:
return "success"
else:
return None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists