Sindbad~EG File Manager

Current Path : /home/numerotech/hs.aios-scientificcommittee.org/scan_v1/core/model/
Upload File :
Current File : //home/numerotech/hs.aios-scientificcommittee.org/scan_v1/core/model/CurrentSessionModel.py

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_pre_ping=True,pool_recycle=3600,future=True)
engine_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_pre_ping=True,pool_recycle=3600,future=True)


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()
			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()
			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,updated_at):
		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={} ,updated_at= '{}' where asession_id={} and  conf_id={}".format(is_active,updated_at,asession_id,conf_id))
			result_1 = conn.execute(stmt_1)
			conn.commit()
			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()
			if result:
				return "success"
			else:
				return None


	def usp_get_current_session_hall_scan_counts(self,conf_id,conf_key):
		sets = []
		try:
			connection = engine_conf.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_get_current_session_hall_scan_counts",[conf_id,conf_key])
			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 usp_get_days_session_hall_scan_counts(self,conf_id,conf_key,conf_date):
		sets = []
		try:
			connection = engine_conf.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_get_days_session_hall_scan_counts",[conf_id,conf_key,conf_date])
			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		

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists