Sindbad~EG File Manager

Current Path : /home/numerotech/bni.numerotech.com/bni_hallmark/core/model/
Upload File :
Current File : //home/numerotech/bni.numerotech.com/bni_hallmark/core/model/MembersModel.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 MembersModel():
	def __init__(self):
		try:
			self.meta = MetaData()
			self.members      = Table("members", self.meta, autoload_with=engine)
			self.visitor_log  = Table("visitor_log", self.meta, autoload_with=engine)
		
		except Exception as e:
			print("Table not found",e)
	# usp_get_bni_members_details
	def Getmembers(self,search_text):
		connection = engine.raw_connection()
		cursor = connection.cursor()
		cursor.callproc("usp_get_bni_members_details",[search_text])
		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 
		
	def insert_visitors(self,data):
		with engine.connect() as conn:
			stmt      = conn.execute(self.visitor_log.insert(),data)
			conn.commit()
			return stmt.lastrowid
		
	def GetData(self,current_dt):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_get_bni_member_and_visitor_data",[current_dt])
			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.close()
			
		return sets
	
	def update_visitor(self,v_log_id,updated_data):
		with engine.connect() as conn:
			stmt    = self.visitor_log.update().where(self.visitor_log.c.v_log_id.in_([v_log_id])).values(updated_data)
			result = conn.execute(stmt)
			conn.commit()
			return 'success' if result else 'fail'
	
	def Get_payment_mode(self):
		with engine.connect() as conn:
			stmt   = text("select * from mode_of_payment;")
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
	
	def Get_visitor_details(self,v_log_id):
		with engine.connect() as conn:
			stmt   = text("select v.v_log_id,v.visitor_name,v.mobile,v.email,v.business_name,v.address,v.city,v.state,p.payment_type from visitor_log v left join mode_of_payment p on p.mode_of_payment_id = v.mode_of_payment_id where v_log_id = "+str(v_log_id)+";")
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None


	def GetMembersForPayment(self):
		with engine.connect() as conn:
			stmt   = text("select * from members where is_test is null order by member_name;")
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
	
	def GetMembersPaymentFor(self):
		with engine.connect() as conn:
			stmt   = text("select * from payments_for;")
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
	
	def GetMembersdetails(self,member_id):
		with engine.connect() as conn:
			stmt   = text("select * from members where member_id ="+str(member_id)+" and is_test is null order by member_name;")
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
	
	def GetVisitorPaymentDetails(self,current_dt):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("get_visitor_payment_details",[current_dt])
			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.close()
			
		return sets

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