Sindbad~EG File Manager

Current Path : /home/numerotech/conf-scan.numerotech.com/conference_scan/core/model/
Upload File :
Current File : //home/numerotech/conf-scan.numerotech.com/conference_scan/core/model/AccessRequestModel.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 AccessRequestModel():
	def __init__(self):
		try:
			self.meta = MetaData()
			self.users              = Table("users", self.meta, autoload_with=engine)
			self.conference_active  = Table("conference_active", self.meta, autoload_with=engine)
			self.conf_active_users  = Table("conf_active_users", self.meta, autoload_with=engine)
		
		except Exception as e :
			print("Table not found",e)


	def getAccessRequestData(self,conf_id,active_id):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_conf_access_request",[(conf_id or None),(active_id or None)])
			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.close()
			
		return sets


	def Update_access_bulk(self,conf_id,col_to_update,curr_at):
		with engine.connect() as conn:
			if col_to_update == "access_on":
				stmt 	=text("update conf_active_users SET access_on = NULL,is_active = 1 ,approved_on = '"+str(curr_at)+"',updated_at = '"+str(curr_at)+"' WHERE access_on is not null and conf_id = "+str(conf_id)+"  ;")
			else:
				stmt 	=text("update conf_active_users SET approved_on = NULL,is_active = 0,access_on = '"+str(curr_at)+"',updated_at = '"+str(curr_at)+"' WHERE approved_on is not null and conf_id = "+str(conf_id)+"  ;")
			
			conn 	= engine.connect()
			result 	= conn.execute(stmt)
			conn.commit()
			return 'success' if result else 'fail'

	def UpdateUsers(self,user_id,update_data):
		with engine.connect() as conn:
			print("inside here")
			stmt = self.users.update().where(self.users.c.user_id.in_([user_id])).values(update_data)
			result = conn.execute(stmt)
			conn.commit()
			if result:
				return 'success'
			else :
				return 'fail'


	def check_mobile(self,mobile,society_id,active_id):
		with engine.connect() as conn:
			if active_id :
				where_con = " and active_id = "+str(active_id)+""
			else :
				where_con = " "
			stmt    = text("select u.user_id,u.society_id,c.conf_id,u.full_name,u.mobile,u.is_admin,u.is_active_conf_user ,u.last_login,cau.active_id,cau.access_on,cau.approved_on,cau.is_active  from users u inner join conference c on c.society_id = u.society_id inner join conf_active_users cau on cau.user_id = u.user_id and cau.conf_id = c.conf_id where u.mobile="+str(mobile)+" and u.society_id = "+str(society_id)+" "+where_con+" ;")
			print("-------- check_mobile stmt ---------------")
			print(stmt)
			result  = conn.execute(stmt).one_or_none()
			return dict(result._mapping) if result  else None

	def insert_users(self,insert_data):
		with engine.connect() as conn:
			result = conn.execute(self.users.insert(), insert_data)
			conn.commit()
			return result.lastrowid

	def insert_conf_active_users(self,insert_au_data):
		with engine.connect() as conn:
			result = conn.execute(self.conf_active_users.insert(), insert_au_data)
			conn.commit()
			return result.lastrowid	

	def update_conf_active_users(self,cau_id,update_data):
		with engine.connect() as conn:
			stmt    = self.conf_active_users.update().where(self.conf_active_users.c.cau_id.in_([cau_id])).values(update_data)
			result = conn.execute(stmt)
			conn.commit()
			return 'success' if result else 'fail'

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