Sindbad~EG File Manager

Current Path : /home/numerotech/workshops.numerotech.com/common_workshop_reg/core/model/
Upload File :
Current File : //home/numerotech/workshops.numerotech.com/common_workshop_reg/core/model/MCDetailModel.py

from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from core import app
import json
from .. import engine

# engine = create_engine(app.config['DATABASE_URI'],pool_pre_ping=True,pool_recycle=3600)


class MCDetailModel():
	def __init__(self):
		try:
			self.meta = MetaData()
			self.delegates = Table("delegates", self.meta,  autoload_with=engine)
			self.users     = Table("users", self.meta,  autoload_with=engine)
			

				
		except Exception as e:
			print(e)

	def checkConfData(self,conf_id,conf_key):
		with engine.connect() as conn:
			stmt   = text("select * from conference c where c.conf_id = "+str(conf_id)+" and c.conf_key = '"+conf_key+"' ;")
			result = conn.execute(stmt).one_or_none()
			return dict(result._mapping) if results else None
			

	def delegateDataByUUID(self,conf_id,conf_key,user_uuid):
		with engine.connect() as conn:
			stmt = text("select d.*, s.state_name as mc_state_name from delegates d left join states s on s.state_id = d.mc_state_id  and s.country_id = 101 " 
			+ " where d.conference_id = "+str(conf_id)+" and d.user_uuid = '"+user_uuid+"'  and d.delegate_no is not null and d.delegate_no > 0 ;")
			results= conn.execute(stmt).one_or_none()
			return dict(result._mapping) if results else None			

	def getStates(self,country_id):
		with engine.connect() as conn:
			stmt = text("select * from states s where s.country_id = "+str(country_id)+" ;")
			results= conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None
							



# 	def updateMCData(self,data,user_uuid,email,conf_id,conf_key):
# 		conn = engine.connect()
# 		try:
# 			update_stmt = self.delegates.update().where(self.delegates.c.user_uuid.in_([user_uuid])).values(data) 
# 			conn.execute(update_stmt)
# 			conn.close()
# 			return "success"
# 		except Exception as e:
# 			conn.close()
# 			return str(e)

	# April 01  2023
	def updateMCData(self,data,user_uuid,email,conf_id,conf_key,update_stmt_conf_del_table):
		with engine.connect() as conn:
			try:
				update_stmt = self.delegates.update().where(self.delegates.c.user_uuid.in_([user_uuid])).values(data)
				conn.execute(update_stmt) 
				conn.commit()
				if update_stmt_conf_del_table and len(update_stmt_conf_del_table) > 10 :
					stmt_2  = text(update_stmt_conf_del_table)
					conn.execute(stmt_2)
					conn.commit()
				return "success"
			except Exception as e:
				conn.close()
				return str(e)

	# April 01  2023
	def getStateNameByStateId(self,state_id):
		with engine.connect() as conn:
			stmt = text("select state_name from states s where s.state_id = "+str(state_id)+"  limit 1;")
			results= conn.execute(stmt).one_or_none()
			return dict(result._mapping) if results else None
				



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