Sindbad~EG File Manager

Current Path : /home/numerotech/mcinfo.numerotech.com/mc_info_update/core/model/
Upload File :
Current File : //home/numerotech/mcinfo.numerotech.com/mc_info_update/core/model/McUpdateDashboardModel.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

engine      = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_recycle=3600)


class McUpdateDashboardModel():
	def __init__(self):
		try:
			self.meta = MetaData()

			self.conference        = Table("conference", self.meta, autoload_with=engine)
			# self.delegates         = Table("delegates", self.meta, autoload_with=engine)
			self.states            = Table("states", self.meta, autoload_with=engine)
		
		except Exception as e:
			print("Table not found",e)
		
	def GetConf(self,conf_id,conf_key):
		with engine.connect() as conn:
			stmt   = text("select * from conference c inner join society_applications s on s.conf_id = c.conf_id and app_type_id = 2  inner join mail_setting  m on s.mail_setting_id = m.mail_setting_id where c.conf_id = "+str(conf_id)+" and c.conf_key = '"+conf_key+"'  limit 1;")
			result = conn.execute(stmt)
			result = result.first()
			conn.close()
			return dict(result._mapping) if result else None
		
	def get_mc_update_data(self,conf_id):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_conf_mc_update_data",[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 get_mc_dashboard_delegates_data(self,conf_id,view_type):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_conf_mc_update_delegates_data",[conf_id,view_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 mc_update_edit_data(self,conf_id,conf_key,delegate_id,conf_schema):
		with engine.connect() as conn:
			stmt   = text("select * from "+str(conf_schema)+".delegates where conference_id= "+str(conf_id)+" and delegate_id = "+str(delegate_id)+";")
			result = conn.execute(stmt)
			result = result.first()
			conn.close()
			return dict(result._mapping) if result else None
	
	def get_states(self,country_id):
		with engine.connect() as conn:
			stmt    = text("select * from states s where s.country_id = "+str(country_id)+" ;")
			result  = conn.execute(stmt).all()
			results = [dict(r._mapping) for r in result] if result else None
			conn.close()
			return results if results else None
	
	def delegateDataByUUID(self,conf_id,conf_key,user_uuid,conf_schema):
		with engine.connect() as conn:
			stmt = text("select d.*, s.state_name as mc_state_name from  "+str(conf_schema)+".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.del_status_id is not null and d.delegate_no > 0 ;")
			result = conn.execute(stmt).first()
			conn.close()
			return dict(result._mapping) if result  else None
	
	def update_mc_data(self,data,delegate_id,conf_schema):
		self.delegates = Table("delegates", self.meta,schema=conf_schema,  autoload_with=engine)
		with engine.connect() as conn:
			try:					
				update_stmt = self.delegates.update().where(self.delegates.c.delegate_id.in_([delegate_id])).values(data)
				conn.execute(update_stmt)
				conn.commit()
				conn.close()
				return "success"
			except Exception as e:
				conn.close()
				return str(e)

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