Sindbad~EG File Manager

Current Path : /home/numerotech/conference.numerotech.com/food_kit_scan_badges/core/model/
Upload File :
Current File : //home/numerotech/conference.numerotech.com/food_kit_scan_badges/core/model/CertificateModel.py

from flask import session
from flask import request, Blueprint, jsonify
from sqlalchemy import create_engine, select, MetaData, Table,text
from sqlalchemy.sql import and_, or_

from core import app

engine      = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_fk   = create_engine(app.config['DATABASE_URI_FK'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)

class CertificateModel():  
	def __init__(self):
		try:
			self.meta = MetaData()
			self.certificates       = Table("certificates",self.meta, autoload_with= engine)
			self.cert_download_logs = Table("certificates",self.meta, cert_download_logs= engine_fk)

			
		except Exception as e:
			print(e)

	def getNameAndRole(self,del_no,del_table_name):
		with engine_fk.connect() as conn:
			if "vrsi23" in del_table_name :
				stmt = text("select delegate_no,prefix,full_name,role,role_in_cert from "+del_table_name+" where delegate_no= "+str(del_no)+";")
			else :
				stmt = text("select delegate_no,prefix,full_name,role,role_in_cert from "+del_table_name+" where delegate_no= "+str(del_no)+";")	
			

			result  = conn.execute(stmt).one_or_none()
			return dict(result._mapping) if result else None	


	def get_Cerf_typ(self,conf_id):
		with engine.connect() as conn:
			# stmt = select([self.certificates])
			stmt = text(" SELECT * FROM certificates where conf_id = "+str(conf_id)+"  ; ")
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None

	def getTemplate(self,conf_id,cerf_id):
		with engine.connect() as conn:
			stmt = text("select  * from certificates where conf_id = "+str(conf_id)+" and cerf_id="+ str(cerf_id) +";")
			print(stmt)
			result  = conn.execute(stmt).one_or_none()
			return dict(result._mapping) if result else None

	def insert_Tempdata(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.certificates.insert(), data)
			conn.commit()
			return result

	def edit_cerf(self,cerf_id):
		with engine.connect() as conn:
			stmt = select([self.certificates]).where(self.certificates.c.cerf_id.in_([cerf_id]))
			result  = conn.execute(stmt).one_or_none()
			return dict(result._mapping) if result else None

	def update_cerf_and_getdata(self,data_for_update,cerf_id):
		with engine.connect() as conn:
			stmt = self.certificates.update().where(self.certificates.c.cerf_id.in_([cerf_id])).values(data_for_update)
			restult_1 = conn.execute(stmt)
			conn.commit()

			stmt_2 = text("SELECT * from certificates;")
			result = conn.execute(stmt_2).all()
			return [dict(r._mapping) for r in result] if result else None

	def delete_cerf_index(self,cerf_id):
		with engine.connect() as conn:
			stmt = self.certificates.delete().where(self.certificates.c.cerf_id.in_([cerf_id]))
			restult_1 = conn.execute(stmt)
			conn.commit()
			stmt_2 = text("SELECT * from certificates;")
			result = conn.execute(stmt_2).all()
			return [dict(r._mapping) for r in result] if result else None

	def checkCertAlreadyPrint(self,conf_id,cert_id,delegate_no , cert_log_table):
		with engine.connect() as conn:
			stmt   = text("select date_format(created_at , '%d-%m-%Y %H:%i:%s') as created_at  from " + cert_log_table+ " where delegate_no = "+ str(delegate_no)+" and conf_id= "+str(conf_id)+"  and cert_id = "+str(cert_id)+"  ;")
			print(stmt)
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None		


	def saveCertDownloadLogs(self,insert_stmt):
		with engine_fk.connect() as conn:
			stmt   = text(insert_stmt)
			result = conn.execute(stmt)
			conn.commit()
			return "success"
			
	# check singed on or not
	def checkSignedOn(self,conf_id,delegate_no,del_table_name):
		with engine.connect() as conn:
			stmt = text("select signed_on from " + del_table_name + " where delegate_no = " + str(delegate_no) + " and  conf_id = "+ str(conf_id) + " and signed_on is not null  limit 1 " )
			result  = conn.execute(stmt).one_or_none()
			return dict(result._mapping) if result else None					
		
	def getCertPringLogs(self,del_table_name,conf_id):	
		with engine_fk.connect() as conn:
			stmt = text("select d.delegate_id,d.delegate_no,d.prefix,d.full_name,d.email,d.mobile,d.membership_no,d.state, "
			+ "  group_concat(date_format(dl.created_at , '%d-%m-%Y %H:%i:%s') separator ',')   as cert_print_on , "
			+ " date_format(d.signed_on , '%d-%m-%Y %H:%i:%s') as signed_on, count(dl.delegate_no) as no_of_times "
			+ " from "+ del_table_name + " d inner join  cert_download_logs dl on dl.delegate_no = d.delegate_no "
			+ "where d.email not like '%numerot%' and dl.conf_id = "+ str(conf_id)+" group by dl.delegate_no ;")	
			print(stmt)
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None		




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