Sindbad~EG File Manager

Current Path : /home/numerotech/conf-certificates.numerotech.com/certificates/core/model/
Upload File :
Current File : //home/numerotech/conf-certificates.numerotech.com/certificates/core/model/DashboardModel.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 DashboardModel():
	def __init__(self):
		try:
			self.meta = MetaData()
			self.conference_active = Table("conference_active", self.meta, autoload_with=engine)
			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()
	# 		return dict(result._mapping) if result else None
		
	def get_usp_conf_certificate_dashboard(self,conf_id,is_only_count,is_view_data,view_type):
		print("usp_conf_certificate_dashboard")
		print(conf_id,is_only_count,is_view_data,view_type)
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_conf_certificate_dashboard",[conf_id,is_only_count,is_view_data,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 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):
		with engine.connect() as conn:
			stmt   = text("select * from 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):
		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.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):
		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