Sindbad~EG File Manager

Current Path : /home/numerotech/test-membership.numerotech.com/CommonMembershipApp/core/model/
Upload File :
Current File : //home/numerotech/test-membership.numerotech.com/CommonMembershipApp/core/model/Society.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
from .. import engine

class Society():
	def __init__(self):
		try:
			self.meta       = MetaData()
			self.societies  = Table("societies", self.meta, autoload_with=engine)
		   
		except Exception as e:
			print(e)

	def getSocietybyId(self,society_id):
		with engine.connect() as conn:
			stmt 	= text("select * from societies where society_id = :society_id")
			result = conn.execute(stmt.bindparams(society_id=society_id)).first()
			if result :
				return dict(result._mapping)
			else:
				return None 		

	def getSociety(self,society_id,society_key):
		with engine.connect() as conn:
			stmt    = text("select * from m_app_type mat "+
				" inner join society_applications sa on sa.app_type_id=mat.app_type_id"+
				" inner join societies s on s.society_id=sa.society_id"+
				" inner join mail_setting ms on ms.mail_setting_id=sa.mail_setting_id where mat.app_type_id=1 and s.society_id=:society_id and s.society_key=:society_key;")
			result = conn.execute(stmt.bindparams(society_id=society_id,society_key=society_key)).first()
			if result :
				return dict(result._mapping)
			else:
				return None

	def setSociety(self,app_host):
		with engine.connect() as conn:
			stmt    = text("select * from m_app_type mat "+
				" inner join society_applications sa on sa.app_type_id=mat.app_type_id"+
				" inner join societies s on s.society_id=sa.society_id "+
				" inner join mail_setting ms on ms.mail_setting_id=sa.mail_setting_id where mat.app_type_id=1 and sa.app_host=:app_host;")
			result  = conn.execute(stmt.bindparams(app_host=app_host)).first()
			if result :
				return dict(result._mapping)
			else:
				return None
				
	def society_application(self,society_id):
		with engine.connect() as conn:
			stmt    = text("select * from society_applications where society_id=:society_id and app_type_id=1;")
			result  = conn.execute(stmt.bindparams(society_id=society_id)).one_or_none()
			if result :
				return dict(result._mapping)
			else:
				return None

	def getAllSociety(self):
		with engine.connect() as conn:
			stmt    = text("select * from m_app_type mat "+
				" inner join society_applications sa on sa.app_type_id=mat.app_type_id"+
				" inner join societies s on s.society_id=sa.society_id where mat.app_type_id=1 and sa.is_daily_report_mail=1;")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None

	def get_emails_data(self):
		with engine.connect() as conn:
			stmt    = text("select  group_concat(t.society_id)as society_id ,group_concat(s.society_key) as society_key,t.full_name,t.email,t.mobile from trigger_daily_reports_mails t inner join societies s on find_in_set(s.society_id,t.society_id) where t.is_mem =1 and t.is_active =1  group by t.full_name order by s.society_id asc")
			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