Sindbad~EG File Manager

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

#engine = create_engine(app.config['DATABASE_URI'])
# engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
# engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,max_overflow=100,pool_pre_ping=True,pool_recycle=3600)
# engine = create_engine(app.config['DATABASE_URI'], poolclass=None,pool_size=5000,max_overflow=100,pool_pre_ping=True,pool_recycle=3600)

class MAttachmentType():
	def __init__(self):
		try:
			self.meta               = MetaData()
			self.m_attachment_type  = Table("m_attachment_type", self.meta, autoload_with=engine)
		   
		except Exception as e:
			print(e)
	
	def get_image(self,user_id,is_payment,society_id):
		with engine.connect() as conn:
			str_where = '';
			if is_payment is not None:
				str_where = ' where ma.is_payment= {} and ma.society_id={}'.format(is_payment,society_id)

			if int(society_id) == 12:
				stmt= text("select ma.attach_type_id,attach_type,label_name,ma.desc,ma.is_active,attach_extension,attach_id,attach_path,attach_file_name,user_id, ma.is_upload,mma.is_mandatory " +
							" from m_attachment_type as ma " +
							" inner join map_membertype_attachment mma on mma.attach_type_id = ma.attach_type_id  and mma.member_type_id = 11 " +
							" left join user_attachments as ua  on ma.attach_type_id=ua.attach_type_id   and user_id=:user_id {}  order by ma.order_no".format(str_where))
			else:
				stmt  = text("select ma.attach_type_id,attach_type,label_name,ma.desc,ma.is_active,attach_extension,attach_id,attach_path,attach_file_name,user_id, ma.is_upload,mma.is_mandatory " +
							" from m_attachment_type as ma " +
							" inner join map_membertype_attachment mma on mma.attach_type_id = ma.attach_type_id  and mma.member_type_id = (select choosed_member_type_id from users where user_id = :user_id) " +
							" left join user_attachments as ua  on ma.attach_type_id=ua.attach_type_id   and user_id=:user_id {}  order by ma.order_no".format(str_where))
			
			results = conn.execute(stmt.bindparams(user_id=user_id)).all()
			conn.close()
			return  [dict(r._mapping) for r in results] if results else None

	def get_image_pg(self,user_id,is_payment,is_pg,society_id):
		with engine.connect() as conn:
			str_where = '';
			if is_payment is not None:
				str_where = ' where ma.is_payment= {} and ma.society_id={}'.format(is_payment,society_id)

			if is_pg != 1:
				str_where += ' and ma.attach_type_id not in (20) ' # attach_type_id = 7 is pg upload     
		   
			stmt  = text("select ma.attach_type_id,attach_type,label_name,ma.desc,ma.is_active,attach_extension,attach_id,attach_path,attach_file_name,user_id ,mma.is_mandatory " +
							" from m_attachment_type as ma " +
							" inner join map_membertype_attachment mma on mma.attach_type_id = ma.attach_type_id  and mma.member_type_id = (select choosed_member_type_id from users where user_id = :user_id) " +
							" left join user_attachments as ua  on ma.attach_type_id=ua.attach_type_id   and user_id=:user_id  {}   order by ma.order_no".format(str_where))

			results = conn.execute(stmt.bindparams(user_id=user_id)).all()
			conn.close()
			return  [dict(r._mapping) for r in results] if results else None
		
	def get_attach_type(self,attach_type_id):
		with engine.connect() as conn:
			stmt = text("select attach_type from m_attachment_type where attach_type_id="+str(attach_type_id)+";")
			result = conn.execute(stmt).first()
			conn.close()
			if result :
				return dict(result._mapping)
			else:
				return None 
	
	def get_payment_image(self,user_id,is_upload,society_id):
		with engine.connect() as conn:

			str_where = '';
				
			if is_upload is not None:
				str_where = ' where ma.is_upload= {} and ma.society_id={}'.format(is_upload,society_id)

			stmt  = text("select ma.attach_type_id,attach_type,label_name,ma.desc,ma.is_active,attach_extension,attach_id,attach_path,attach_file_name,user_id, ma.is_upload,mma.is_mandatory " +
							" from m_attachment_type as ma " +
							" inner join map_membertype_attachment mma on mma.attach_type_id = ma.attach_type_id  and mma.member_type_id = (select choosed_member_type_id from users where user_id = :user_id) " +
							" left join user_attachments as ua  on ma.attach_type_id=ua.attach_type_id   and user_id=:user_id {}  order by ma.order_no".format(str_where))
			
			results = conn.execute(stmt.bindparams(user_id=user_id)).all()
			conn.close()
			return  [dict(r._mapping) for r in results] if results else None
		
		
	def get_fellowship_attach_id(self,attach_type_id,user_id,society_id):
		with engine.connect() as conn:
			stmt = text("select ma.attach_type_id,attach_type,label_name,ma.desc,ma.is_active,attach_extension,attach_id,attach_path,attach_file_name,user_id, ma.is_upload,mma.is_mandatory from m_attachment_type as ma inner join map_membertype_attachment mma on mma.attach_type_id = ma.attach_type_id and mma.member_type_id = (select choosed_member_type_id from users where user_id = :user_id) left join user_attachments as ua  on ma.attach_type_id=ua.attach_type_id   and user_id=:user_id  where ma.attach_type_id=:attach_type_id and society_id=:society_id;")
			results = conn.execute(stmt.bindparams(user_id=user_id,society_id=society_id,attach_type_id=attach_type_id)).all()
			results=  [dict(r._mapping) for r in results] if results else None
			conn.close()
			if results :
				return results
			else:
				return None

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