Sindbad~EG File Manager
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_pre_ping=True,pool_recycle=3600)
engine_app = create_engine(app.config['APP_DATABASE_URI'],pool_pre_ping=True,pool_recycle=3600)
class ImagePollModel():
def __init__(self):
try:
self.meta = MetaData()
self.users = Table("users", self.meta, autoload_with=engine)
# self.img_poll_rate = Table("img_poll_rate", self.meta, autoload=True, autoload_with=engine)
# self.image_poll = Table("image_poll", self.meta, autoload=True, autoload_with=engine)
self.img_poll_rate = Table("img_poll_rate", self.meta, autoload_with=engine_app)
self.image_poll = Table("image_poll", self.meta, autoload_with=engine_app)
except Exception as e:
print(e)
def get_conference_by_host(self,host):
with engine.connect() as conn:
stmt = text("select * from society_applications sa inner join societies s on s.society_id=sa.society_id where app_host = '{}' and app_type_id = 7".format(host))
conn = engine.connect()
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def get_autologin_data(self,user_uuid):
with engine.connect() as conn:
stmt = text("select * from users u inner join societies s on s.society_id=u.society_id where u.user_uuid=:user_uuid")
# results = conn.execute(stmt,user_uuid=user_uuid)
result = conn.execute(stmt.bindparams(user_uuid=user_uuid)).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def GetSessionImagePoll(self,session_id,session_key):
with engine.connect() as conn:
stmt = text("select c.*,soc.app_title from numerote_imagepoll_db.image_poll_session c"
+" left join society_applications soc"
+" on c.society_id=soc.society_id"
+" where (c.session_id="+str(session_id)+" )and c.session_key='"+str(session_key)+"' and soc.app_type_id=7;")
print(stmt)
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def GetSession_date(self,society_id,current_dt):
with engine_app.connect() as conn:
stmt = text("select * from numerote_imagepoll_db.image_poll_session where society_id="+str(society_id)+" and is_active=1 and (start_date <'"+str(current_dt)+"' and end_date >'"+str(current_dt)+"') ;")
# print(stmt)
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def GetSessionFinalDate(self,society_id,current_dt):
with engine_app.connect() as conn:
stmt = text("select * from numerote_imagepoll_db.image_poll_session where society_id="+str(society_id)+" and is_active=1 and is_final=1 and (start_date <'"+str(current_dt)+"' and end_date >'"+str(current_dt)+"') ;")
# print(stmt)
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def Get_img_count(self,society_id,session_id):
with engine_app.connect() as conn:
stmt = text("select * from numerote_imagepoll_db.image_poll where society_id="+str(society_id)+" and session_id="+str(session_id)+";")
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def Get_final_img_count(self,society_id,session_id):
with engine_app.connect() as conn:
stmt = text("select * from numerote_imagepoll_db.image_poll where society_id="+str(society_id)+" and final_session_id="+str(session_id)+";")
print(stmt)
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def GetLastImgData(self,society_id,session_id):
with engine_app.connect() as conn:
# stmt = text("select * from numerote_imagepoll_db.image_poll where society_id="+str(society_id)+" and (session_id="+str(session_id)+" or final_session_id="+str(session_id)+") order by IFNULL(final_order_no ,order_by) desc limit 1;")
stmt=text("select i.*,case when s.is_final=1 then final_order_no else order_by end as temp_order from numerote_imagepoll_db.image_poll as i inner join image_poll_session s on (s.session_id=i.session_id or i.final_session_id= s.session_id) where s.society_id="+str(society_id)+" and s.session_id="+str(session_id)+" order by temp_order desc limit 1;")
print(stmt)
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def GetSession(self,society_id):
with engine_app.connect() as conn:
stmt = text("select * from numerote_imagepoll_db.image_poll_session where society_id="+str(society_id)+" and is_active=1 limit 1;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def getSocietyImagePolldata(self,society_id,society_key):
with engine.connect() as conn:
stmt = text("select s.*,soc.app_host,soc.app_title,mt.mail_setting_id,mt.driver,mt.is_active,mt.secret_key,mt.domain,soc.app_style from societies s"
+" left join society_applications soc on s.society_id=soc.society_id"
+" left join mail_setting mt on soc.mail_setting_id=mt.mail_setting_id"
+" where soc.society_id="+str(society_id)+" and s.society_id="+str(society_id)+" and soc.app_type_id=7;")
# print(stmt)
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
# def Get_count_ImagePoll(self,society_id,session_id):
# with engine_app.connect() as conn:
# # stmt = text("select count(img_poll_id) as total_count from image_poll where conf_id="+str(conf_id)+" and session_id='"+str(session_id)+"' order by order_by asc limit 1;")
# stmt=text("select order_by as total_count from numerote_imagepoll_db.image_poll where society_id="+str(society_id)+" and session_id='"+str(session_id)+"' order by order_by desc limit 1;")
# result = conn.execute(stmt)
# conn.close()
# results = [dict(r) for r in result] if result else None
# if results :
# return results[0]
# else:
# return None
# def Get_Next(self,society_id,conf_key,order_by):
# with engine_app.connect() as conn:
# stmt = text("select * from numerote_imagepoll_db.image_poll where order_by=("+str(order_by)+"+1) and society_id="+str(society_id)+" and conf_key='"+str(conf_key)+"';")
# result = conn.execute(stmt)
# conn.close()
# results = [dict(r) for r in result] if result else None
# if results :
# return results
# else:
# return None
# def PreviousPage(self,society_id,conf_key,order_by):
# with engine_app.connect() as conn:
# stmt = text("select * from numerote_imagepoll_db.image_poll where order_by=("+str(order_by)+"-1) and society_id="+str(society_id)+" and conf_key='"+str(conf_key)+"';")
# results = conn.execute(stmt).all()
# return [dict(r._mapping) for r in results] if results else None
# def Get_Society_Id(self,society_id,conf_key):
# conn =engine.connect()
# stmt = text("select society_id from conference where society_id="+str(society_id)+" and conf_key='"+str(conf_key)+"';")
# result = conn.execute(stmt)
# conn.close()
# results = [dict(r) for r in result] if result else None
# if results :
# return results[0]
# else:
# return None
def GetUserData(self,email,society_id):
with engine.connect() as conn:
stmt = text("select * from users where email='"+str(email)+"' and society_id="+str(society_id)+" ;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def update_member(self,user_id,data):
with engine.connect() as conn:
stmt = self.users.update().values(data).where(self.users.c.user_id.in_([user_id]))
conn.execute(stmt)
conn.commit()
select_stmt = text("select * from users where user_id = "+str(user_id)+" ")
result = conn.execute(select_stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def get_otp_random(self,user_id):
with engine.connect() as conn:
stmt = text("select otp from users where user_id = {} ".format(user_id))
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def get_mail_templates(self,template_name,society_id):
with engine.connect() as conn:
stmt = text("SELECT * FROM mail_templates where template_name='"+str(template_name)+"' and society_id="+str(society_id)+" and app_type_id=7 and is_active=1;")
return conn.execute(stmt).first()
if result :
return dict(result._mapping)
else:
return None
def insert_new_user(self,email,society_id,current_dt):
with engine.connect() as conn:
stmt = text("insert into users (email,society_id,created_at) values('{}',{},'{}')".format(email,society_id,current_dt))
result = conn.execute(stmt)
conn.commit()
stmt = text("select * from users where email = '{}' and society_id = {}".format(email,society_id))
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def Verify_OTP(self,user_id,otp):
with engine.connect() as conn:
stmt = text("select * from users where user_id="+str(user_id)+" ;")
# print(stmt)
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def get_user_data(self,user_id):
with engine.connect() as conn:
stmt = text("select u.*,s.state_name from users u left join states s on u.state_id=s.state_id where u.user_id="+str(user_id)+";")
# print(stmt)
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def update_User_Data(self,user_id,data):
with engine.connect() as conn:
stmt = self.users.update().where(self.users.c.user_id.in_([user_id])).values(data)
result = conn.execute(stmt)
conn.commit()
return result
def Get_States(self):
with engine.connect() as conn:
stmt = text("select * from states where country_id=101;")
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def Insert_Poll_Rate(self,data,society_id,user_id,session_id):
with engine_app.connect() as conn:
stmt = self.img_poll_rate.insert().values(data)
results = conn.execute(stmt)
conn.commit()
stmt_1 = text("select count(*) as total_poll_count from img_poll_rate where society_id="+str(society_id)+" and user_id="+str(user_id)+" and session_id="+str(session_id)+" ;")
result = conn.execute(stmt_1).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def Get_poll_rate(self,user_id,society_id,img_poll_id):
with engine_app.connect() as conn:
stmt=text("select * from numerote_imagepoll_db.img_poll_rate where user_id="+str(user_id)+" and society_id="+str(society_id)+" and img_poll_id="+str(img_poll_id)+";")
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def Check_already_Poll(self,img_poll_id,user_id,society_id,session_id):
with engine.connect() as conn:
stmt=text("select count(img_poll_id) as poll_count from numerote_imagepoll_db.img_poll_rate where user_id='"+str(user_id)+"' and img_poll_id="+str(img_poll_id)+" and society_id="+str(society_id)+" and session_id="+str(session_id)+";")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def check_mobile(self,society_id,mobile,user_id):
with engine.connect() as conn:
stmt=text("select count(*) as mobile_count from users where society_id="+str(society_id)+" and mobile="+str(mobile)+" and user_id !="+str(user_id)+" ;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def Get_Count_Rate(self,society_id,user_id):
with engine_app.connect() as conn:
stmt=text("select count(*) as rate_count,poll_on from numerote_imagepoll_db.img_poll_rate where society_id="+str(society_id)+" and user_id="+str(user_id)+" ;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
# def Get_last_rate(self,society_id,user_id):
# conn=engine.connect()
# stmt=text("select * from img_poll_rate where society_id="+str(society_id)+" and user_id="+str(user_id)+" order by poll_rate_id desc limit 1;")
# result = conn.execute(stmt)
# results = [dict(r) for r in result] if result else None
# conn.close()
# if results :
# return results[0]
# else:
# return None
def Set_OTP_Null(self,user_id):
with engine.connect() as conn:
stmt = text("update users set otp=null where user_id="+str(user_id)+";")
result = conn.execute(stmt)
conn.commit()
return result
def Get_otp_expire(self,data,user_id):
with engine.connect() as conn:
stmt = self.users.update().values(data).where(self.users.c.user_id.in_([user_id]))
results = conn.execute(stmt)
conn.commit()
select_stmt = text("select * from users where user_id = "+str(user_id)+" ")
result = conn.execute(select_stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
# def Get_last_poll_rate(self,society_id,user_id):
# conn=engine.connect()
# stmt=text("select * from numerote_imagepoll_db.image_poll im left join img_poll_rate mp on im.img_poll_id=mp.img_poll_id where mp.user_id="+str(user_id)+" and im.society_id="+str(society_id)+" and mp.society_id="+str(society_id)+" order by im.order_by desc limit 1;")
# result = conn.execute(stmt)
# results = [dict(r) for r in result] if result else None
# conn.close()
# if results :
# return results[0]
# else:
# return None
def usp_get_user_image_poll(self,society_id,user_id,session_id,img_poll_id):
sets = []
try:
connection = engine_app.raw_connection()
cursor = connection.cursor()
cursor.callproc("numerote_imagepoll_db.usp_get_user_image_poll",[society_id,user_id,session_id,img_poll_id])
while 1:
#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
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()
# print(sets)
return sets
def usp_generate_pc_no(self,img_poll_id,society_id):
sets = []
try:
connection = engine_app.raw_connection()
cursor = connection.cursor()
cursor.callproc("numerote_imagepoll_db.usp_generate_pc_no",[img_poll_id,society_id])
while 1:
#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
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.commit()
connection.close()
# print(sets)
return sets[0]
# def GetTotalCount(self,society_id,user_id,session_id,order_by,page):usp_generate_pc_no
# sets = []
# try:
# connection = engine.raw_connection()
# cursor = connection.cursor()
# cursor.callproc("get_img_data_count",[society_id,user_id,session_id,order_by,page])
# while 1:
# #(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
# 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()
# # print(sets)
# return sets
def Get_max_img_id(self,society_id,session_id):
with engine_app.connect() as conn:
stmt=text("select count(*) as total_count from numerote_imagepoll_db.image_poll where society_id="+str(society_id)+" and (session_id="+str(session_id)+" or final_session_id="+str(session_id)+") ;")
print(stmt)
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def Get_total_user_poll(self,society_id,session_id,user_id):
with engine_app.connect() as conn:
stmt=text("select count(*) as total_count from numerote_imagepoll_db.img_poll_rate where society_id="+str(society_id)+" and session_id="+str(session_id)+" and user_id="+str(user_id)+" ;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def Update_Poll_Rate(self,img_poll_id,user_id,society_id,session_id,rate,current_dt):
with engine_app.connect() as conn:
stmt_1=text("update numerote_imagepoll_db.img_poll_rate set rate="+str(rate)+" , poll_on='"+str(current_dt)+"' where user_id='"+str(user_id)+"' and img_poll_id="+str(img_poll_id)+" and society_id="+str(society_id)+" and session_id="+str(session_id)+";")
# print(stmt_1)
results = conn.execute(stmt_1)
conn.commit()
# return result
stmt=text("select count(*) as total_poll_count from numerote_imagepoll_db.img_poll_rate where society_id="+str(society_id)+" and user_id="+str(user_id)+" and session_id="+str(session_id)+" ;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def UpdateConfirmPoll(self,user_id,society_id,session_id,current_dt):
with engine_app.connect() as conn:
stmt_1=text("update numerote_imagepoll_db.img_poll_rate set confirm_on='"+str(current_dt)+"' where user_id='"+str(user_id)+"' and society_id="+str(society_id)+" and session_id="+str(session_id)+";")
result = conn.execute(stmt_1)
conn.commit()
return result
# def Check_Mem(self,user_id):
# conn=engine.connect()
# stmt=text("select u.user_id as user_user_id,u.membership_no,u.prefix,u.full_name,u.email as user_email,u.mobile as user_mobile,u.member_type_id,im.* from users u left join numerote_imagepoll_db.image_poll im on u.user_id=im.user_id where u.user_id="+str(user_id)+";")
# result=conn.execute(stmt)
# results = [dict(r) for r in result] if result else None
# conn.close()
# if results :
# return results[0]
# else:
# return None
def Check_Mem(self,user_id,society_id):
with engine.connect() as conn:
if society_id==2:
stmt=text("select u.user_id as user_user_id,u.membership_no,u.prefix,u.full_name,u.email as user_email,u.mobile as user_mobile,u.member_type_id,u.society_id,im.* from users u left join numerote_imagepoll_db.image_poll im on u.user_id=im.user_id where u.user_id="+str(user_id)+" and u.member_type_id != 2;")
else:
stmt=text("select u.user_id as user_user_id,u.membership_no,u.prefix,u.full_name,u.email as user_email,u.mobile as user_mobile,u.member_type_id,u.society_id,im.* from users u left join numerote_imagepoll_db.image_poll im on u.user_id=im.user_id where u.user_id="+str(user_id)+";")
# print(stmt)
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
def Get_Image_data(self,user_id):
with engine_app.connect() as conn:
stmt = text("select * from numerote_imagepoll_db.image_poll where user_id = '{}' order by img_poll_id asc;".format(user_id))
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
# def Delete_Img(self,img_poll_id):
# conn=engine.connect()
# stmt_1=text("update numerote_imagepoll_db.image_poll set image_url=null where img_poll_id="+str(img_poll_id)+" ;")
# result_1=conn.execute(stmt_1)
# conn.close()
# if result_1:
# return 'success'
# else :
# return 'fail'
# def get_img_upload(self,user_id,society_id,session_id):
# stmt = text("select * from image_poll where user_id="+str(user_id)+" and society_id="+str(society_id)+" and session_id="+str(session_id)+";")
# conn = engine.connect()
# result = conn.execute(stmt)
# results = [dict(r) for r in result] if result else None
# conn.close()
# if results:
# return results[0]
# else:
# return results
def get_img_upload(self,user_id,society_id,img_poll_id):
with engine_app.connect() as conn:
# stmt = text("select * from numerote_imagepoll_db.image_poll where user_id="+str(user_id)+" and society_id="+str(society_id)+" ;")
stmt=text("select * from numerote_imagepoll_db.image_poll where user_id="+str(user_id)+" and society_id="+str(society_id)+" and img_poll_id="+str(img_poll_id)+" ;")
result = conn.execute(stmt).first()
if result :
return dict(result._mapping)
else:
return None
def update_imge_db(self,data_1,img_poll_id):
with engine_app.connect() as conn:
stmt = self.image_poll.update().where(self.image_poll.c.img_poll_id.in_([img_poll_id])).values(data_1)
results = conn.execute(stmt)
conn.commit()
stmt_2=text("select * from numerote_imagepoll_db.image_poll where img_poll_id="+str(img_poll_id)+" ;")
result = conn.execute(stmt_2).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def Check_Img_Data(self,img_url,society_id,session_id,user_id):
with engine_app.connect() as conn:
stmt = text("select * from numerote_imagepoll_db.image_poll where image_url = '"+str(img_url)+"' and society_id="+str(society_id)+" and session_id="+str(session_id)+" and user_id="+str(user_id)+";")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
# def Insert_Image_data(self,data_1,image_url):
# stmt = self.image_poll.insert().values(data_1)
# conn = engine_app.connect()
# result = conn.execute(stmt)
# stmt_1=text("select * from image_poll where image_url='"+str(image_url)+"' ;")
# result_1 = conn.execute(stmt_1)
# results = [dict(r) for r in result_1] if result_1 else None
# conn.close()
# if results:
# return results[0]
# else:
# return results
def Insert_Image_data(self,data_1,user_id,society_id):
with engine_app.connect() as conn:
stmt = self.image_poll.insert().values(data_1)
results = conn.execute(stmt)
conn.commit()
stmt_1=text("select * from numerote_imagepoll_db.image_poll where society_id="+str(society_id)+" and user_id="+str(user_id)+" order by img_poll_id desc limit 1;")
result = conn.execute(stmt_1).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def Update_Image_Poll_data(self,data,img_poll_id):
with engine_app.connect() as conn:
stmt = self.image_poll.update().where(self.image_poll.c.img_poll_id.in_([img_poll_id])).values(data)
result = conn.execute(stmt)
conn.commit()
return result
def Get_img_poll_data(self,img_poll_id):
with engine.connect() as conn:
stmt = text("select im.*,u.membership_no from numerote_imagepoll_db.image_poll im left join users u on im.user_id=u.user_id where img_poll_id ="+str(img_poll_id)+" ;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
def get_img_upload_bo(self,img_poll_id,society_id):
with engine_app.connect() as conn:
stmt = text("select * from numerote_imagepoll_db.image_poll where img_poll_id="+str(img_poll_id)+" and society_id="+str(society_id)+" ;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists