Sindbad~EG File Manager

Current Path : /home/numerotech/conference.aios-scientificcommittee.org/aios_conf_app/core/model/
Upload File :
Current File : //home/numerotech/conference.aios-scientificcommittee.org/aios_conf_app/core/model/SignUpModel.py

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

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

class SignUpModel():
	def __init__(self):
		try:
			self.meta       = MetaData()
		except Exception as e:
			print(e)

	def usp_save_signed_data(self,conf_id,delegate_no,signed_by,comments,del_table_name):
		connection  = engine_conf.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_save_signed_data",[conf_id,delegate_no,signed_by,comments,del_table_name])
		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 usp_search_regdesk(self,del_table_name,search_data,is_delegate,conf_id):
		connection  = engine_conf.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_search_regdesk",[del_table_name,search_data,is_delegate,conf_id])
		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 getCount(self ,conf_id,del_table_name) : 
		with engine.connect() as conn:
			stmt = text ("SELECT (select count(*) as total_signed_on from " +del_table_name+ " where conf_id =:conf_id  and signed_on is not null limit 1 ) as total_signed_on , "+
			" (select count(*) as total_count from " +del_table_name+ " where conf_id =:conf_id and role not in ('TRADE','VOLUNTEER','SUPPORT FABRICATTION','AUDIO VISUAL','IT-SUPPORT')) as total_count  from " +del_table_name+ " limit 1 ;")
			results = conn.execute(stmt.bindparams(conf_id=conf_id)).one_or_none()
			if results : 
				return dict(results._mapping)
			else:
				return None 	


# unsignup delegate number start
	def getsigned_data(self,conf_id,del_table_name):
		with engine.connect() as conn:
			stmt   =text("select * from "+del_table_name+" where conf_id = '"+str(conf_id)+"'  and signed_on is not null; ")
			result = conn.execute(stmt).all()
			results = [dict(r._mapping) for r in result] if result else None
			if results : 
				return results
			else:
				return None

	# Multiple result set
	def unsignupdata_andbackup(self,main_db,conf_id,delegate_no,del_table_name,reason):
		sets = []
		try:
			connection = engine_conf.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_unsignup_data",[main_db,conf_id,delegate_no,del_table_name,reason])
			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
	 
				# 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 

# unsignup delegate number end


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