Sindbad~EG File Manager

Current Path : /home/numerotech/status.numerotech.com/status_app/core/model/
Upload File :
Current File : //home/numerotech/status.numerotech.com/status_app/core/model/BoModel.py

from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from .. import Cryptography,Auth
from core import app
import json

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



class BoModel():
	def __init__(self):
		try:
			self.meta = MetaData()
			self.abstracts   = Table("abstracts", self.meta, autoload_with=engine)
			self.date_config = Table("abs_types",self.meta,  autoload_with=engine)
			self.abs_session_types   = Table("abs_session_types", self.meta,  autoload_with=engine)
			self.author      = Table("abs_topics", self.meta, autoload_with=engine)
			self.setting     = Table("abs_settings",self.meta,  autoload_with=engine)
			self.abs_judges  = Table("abs_judges",self.meta,  autoload_with=engine)
			self.template    = Table("abs_mail_templete",self.meta, autoload_with=engine)
			self.mail_templates    = Table("mail_templates",self.meta, autoload_with=engine)
		except Exception as e:
			print(e)


# abs_status
	
	def get_curt_conferences(self):
		with engine.connect() as conn:
			stmt=text("select *,(select count(*) from conference c inner join society_applications sa on sa.conf_id=c.conf_id and app_type_id in (2,3) and c.is_active=1) as total_count "
					+" from conference c inner join society_applications sa on sa.conf_id=c.conf_id and app_type_id in (2,3)" 
					+" left join societies s on s.society_id=c.society_id "
					+" left join m_app_type a on a.app_type_id=sa.app_type_id "
					+" where c.is_active=1 and (c.conf_start_time > current_time() or c.conf_start_time is null) order by sa.is_active desc;")
			# print(stmt)
			result = conn.execute(stmt).all()
			if result :
				return [dict(r._mapping) for r in result] if result else None
			else:
				return None

	def get_closed_conferences(self):
		with engine.connect() as conn:
			stmt=text("select *,(select count(*) from conference c inner join society_applications sa on sa.conf_id=c.conf_id and app_type_id = 3 and c.is_active=1) as total_count "
					+" from conference c inner join society_applications sa on sa.conf_id=c.conf_id and app_type_id = 3" 
					+" left join societies s on s.society_id=c.society_id "
					+" where c.is_active=1 and c.conf_start_time < current_time() order by sa.is_active desc;")
			# print(stmt)
			result = conn.execute(stmt).all()
			if result :
				return [dict(r._mapping) for r in result] if result else None
			else:
				return None

	def Get_ABS_type(self,conf_id):
		with engine.connect() as conn:
			stmt=text("select *,(select count(*) from abs_types where conf_id=1) as total_count from abs_types where conf_id="+str(conf_id)+" order by start_date desc;")
			# print(stmt)
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None


	
	def Get_Abs_type_date(self,limit):
		with engine.connect() as conn:
			stmt=text("select abt.*,DATE_FORMAT(start_date,'%y-%m-%d'),c.conf_name,c.conf_id,c.conf_title as date from abs_types abt left join conference c on c.conf_id=abt.conf_id where (DATE_FORMAT(start_date,'%y-%m-%d') <= CURRENT_DATE() or date_format(end_date,'%y-%m-%d') <= current_date()) and start_date is not null order by start_date desc,end_date")
			# print(stmt)
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def GetTotalCountDay(self):
		with engine.connect() as conn:
			# stmt=text("SELECT DATEDIFF(CURRENT_DATE(),(select DATE_FORMAT(start_date,'%y-%m-%d') as start_date from abs_types where (DATE_FORMAT(start_date,'%y-%m-%d') <= CURRENT_DATE() or date_format(end_date,'%y-%m-%d') <= current_date()) order by start_date asc,end_date asc limit 1)) AS days FROM abs_types;")
			stmt=text("SELECT DATEDIFF(CURRENT_DATE(),(select DATE_FORMAT(start_date,'%y-%m-%d') as start_date from abs_types where (DATE_FORMAT(start_date,'%y-%m-%d') <= CURRENT_DATE() or date_format(end_date,'%y-%m-%d') <= current_date()) limit 1)) AS days FROM abs_types;")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def FindDateData(self,date):
		with engine.connect() as conn:
			stmt=text("select abt.*,c.conf_id,c.conf_key,c.conf_name from abs_types abt left join conference c on abt.conf_id=c.conf_id where (start_date like '%{d}%' or end_date like '%{d}%');".format(d=date))
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def AbsTypeData(self):
		with engine.connect() as conn:
			stmt=text("select * from abs_types;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def GetSociety(self):
		with engine.connect() as conn:
			stmt=text("select * from societies;")
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None

	def GetAppType(self):
		with engine.connect() as conn:
			stmt=text("select * from m_app_type;")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None
	
	def getconf_active(self,is_active):
		with engine.connect() as conn:
			if is_active:
				is_actives='where is_active=1'
			else:
				is_actives=''
			stmt=text("select * from conference "+str(is_actives)+" ;")
			results=conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None
			
			
	# delegate registration model starts here
	def GetAddonsdate(self,limit):
		with engine.connect() as conn:
			stmt=text("select a.*,DATE_FORMAT(a.start_by,'%y-%m-%d'),c.conf_name,c.conf_id,c.conf_title as date from addons a left join conference c on c.conf_id=a.conference_id where (DATE_FORMAT(a.start_by,'%y-%m-%d') <= CURRENT_DATE() or date_format(a.end_by,'%y-%m-%d') <= current_date()) and a.start_by is not null order by a.start_by desc,a.end_by;")
			print(stmt)
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None
			
			
	def GetTotalDelCountDay(self):
		with engine.connect() as conn:
			stmt=text("SELECT DATEDIFF(CURRENT_DATE(),(select DATE_FORMAT(start_by,'%y-%m-%d') as start_date from addons where  (DATE_FORMAT(start_by,'%y-%m-%d') <= CURRENT_DATE() or date_format(end_by,'%y-%m-%d') <= current_date()) limit 1))  AS days  from addons;")
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None
				
				
	def FindDelDateData(self,date):
		with engine.connect() as conn:
			stmt=text("select a.*,c.conf_id,c.conf_key,c.conf_name from addons a left join conference c on a.conference_id=c.conf_id where (a.start_by like '%{d}%' or a.end_by like '%{d}%');".format(d=date))
			results = conn.execute(stmt).all()
			return [dict(r._mapping) for r in results] if results else None			


app.jinja_env.globals.update(BoModel=BoModel)   

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