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)
class AIOSSlottingModel():
def __init__(self):
try:
self.meta = MetaData()
self.workshop_admim = Table("workshop_admim", self.meta,autoload_with=engine)
self.facultyslot = Table("facultyslot", self.meta,autoload_with=engine)
self.mcourseslots = Table("mcourseslots", self.meta,autoload_with=engine)
self.delegateslot = Table("delegateslot", self.meta,autoload_with=engine)
except Exception as e:
print(e)
def Get_Course(self,workshopId,conf_id):
with engine.connect() as conn:
stmt=text(f"select * from m_workshop where workshopId in ({workshopId}) and conf_id = {conf_id};")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
def Last_login(self,data,admin_id):
with engine.connect() as conn:
stmt = self.workshop_admim.update().where(self.workshop_admim.c.admin_id.in_([admin_id])).values(data)
result = conn.execute(stmt)
conn.commit()
return 'success'
def Check_login(self,username,password,conf_id):
with engine.connect() as conn:
stmt=text(f"select * from workshop_admim where user_name='{username}' and pwd='{password}' and conf_id = {conf_id} ;")
result=conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results
def get_slot_time(self,course_id):
with engine.connect() as conn:
stmt=text(f"select ms.*,(SELECT COUNT(ds1.SlotId) from delegateslot ds1 where ds.SlotId=ds1.SlotId) as total_slot_done,(SELECT COUNT(fs1.SlotId) from facultyslot fs1 where fs.SlotId=fs1.SlotId) as Faculty_slot from mcourseslots ms left join delegateslot ds on ds.SlotId=ms.SlotId left join facultyslot fs on ms.SlotId=fs.SlotId where ms.WorkshopCourseId = {course_id} group by ms.SlotId;")
result=conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def Get_Course_name(self,course_id):
with engine.connect() as conn:
stmt=text("select * from workshopcourses c inner join m_workshop m on c.workshopId = m.workshopId where WorkshopCourseId="+str(course_id)+";")
result=conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def Get_Faculty_data(self,full_name):
with engine.connect() as conn:
stmt=text("select * from users where first_name like '%{n}%' or mobile like '%{n}%' or email like '%{n}%';".format(n=full_name))
result=conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_course_data(self,SlotId):
with engine.connect() as conn:
stmt=text("select * from mcourseslots where SlotId='"+str(SlotId)+"'")
result=conn.execute(stmt).one_or_none()
results=dict(result._mapping) if result else None
return results
def UpdateSlotData(self,SlotId,data):
with engine.connect() as conn:
stmt = self.mcourseslots.update().where(self.mcourseslots.c.SlotId.in_([SlotId])).values(data)
result = conn.execute(stmt)
conn.commit()
return 'success'
def InsertSlotData(self,data):
with engine.connect() as conn:
result = conn.execute(self.mcourseslots.insert(), data)
conn.commit()
return "success"
def Get_workshop_course_Data(self,workshopId,conf_id):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("get_total_count_data",[workshopId,conf_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()
return sets[0]
def Set_Faculty_Slot(self,data):
with engine.connect() as conn:
result = conn.execute(self.facultyslot.insert(), data)
conn.commit()
return "success"
def Set_Delegate_Slot(self,data):
with engine.connect() as conn:
result = conn.execute(self.delegateslot.insert(), data)
conn.commit()
return "success"
def Get_faculty(self,SlotId):
with engine.connect() as conn:
stmt=text("select * from facultyslot where SlotId ="+str(SlotId)+" ;")
result=conn.execute(stmt).all()
results=[dict(r._mapping) for r in result] if result else None
return results
def get_session_speakers(self,SlotID):
with engine.connect() as conn:
stmt = text (f"select * from ((select DelSlotID,SlotId,DelegateNo COLLATE utf8mb4_unicode_ci as DelegateNo,ifnull(ds.name,wd.name) COLLATE utf8mb4_unicode_ci as name ,ifnull(ds.email,wd.email) COLLATE utf8mb4_unicode_ci as email ,ifnull(ds.mobile,wd.mobile) COLLATE utf8mb4_unicode_ci as mobile,is_present COLLATE utf8mb4_unicode_ci as is_present,0 as is_faculty from delegateslot ds left join workshop_delegates wd on ds.DelegateNo = wd.delegate_no where SlotId = :SlotID ) union (select FacSlotId,SlotId,FacultySlotID COLLATE utf8mb4_unicode_ci as DelegateNo,ifnull(ds.name,wd.name) COLLATE utf8mb4_unicode_ci as name ,ifnull(ds.email,wd.email) COLLATE utf8mb4_unicode_ci as email ,ifnull(ds.mobile,wd.mobile) COLLATE utf8mb4_unicode_ci as mobile ,is_present COLLATE utf8mb4_unicode_ci as is_present ,1 as is_faculty from facultyslot ds left join workshop_delegates wd on ds.FacultySlotID = wd.delegate_no where SlotId = {SlotID})) as delegates;")
results = conn.execute(stmt).all()
result = [dict(r._mapping) for r in results] if results else None
return result
def get_session(self,SlotId):
with engine.connect() as conn:
stmt = text (f"select * from mcourseslots mc inner join workshopcourses wc on wc.WorkshopCourseId = mc.WorkshopCourseId inner join m_workshop mw on mw.WorkshopId = wc.WorkshopId where mc.SlotId = {SlotID}")
result = conn.execute(stmt).one_or_none()
results = dict(result._mapping) if results else None
return results
def update_attendance(self,speaker_data):
with engine.connect() as conn:
stmt = 'UPDATE delegateslot SET '
stmt1 = 'UPDATE facultyslot SET '
keyname = ["is_present"]
judge_pkid = []
author_pkid = []
for j in keyname:
stmt = stmt + j +" = case "
stmt1 = stmt1 + j +" = case "
for i in speaker_data:
if int(i["is_faculty"]) == 0:
stmt = stmt + ' When DelSlotID = ' + str(i["DelSlotID"]) + " then " + i[j]
author_pkid.append(i["DelSlotID"])
else:
stmt1 = stmt1 + ' When FacSlotId = ' + str(i["DelSlotID"]) + " then " + i[j]
judge_pkid.append(i["DelSlotID"])
stmt = stmt + ' END, '
stmt1 = stmt1 + ' END, '
stmt = stmt[:-2]
stmt1 = stmt1[:-2]
author_pkid = ','.join(str(e) for e in author_pkid)
judge_pkid = ','.join(str(e) for e in judge_pkid)
stmt = stmt + ' Where DelSlotID in (' +str(author_pkid)+' );'
stmt1 = stmt1 + ' Where FacSlotId in (' +str(judge_pkid)+' );'
if author_pkid:
result = conn.execute(stmt)
if judge_pkid:
result = conn.execute(stmt1)
conn.commit()
return "Success"
def Get_Delegates(self,SlotId):
with engine.connect() as conn:
stmt=text("SELECT ds.DelSlotID, ds.SlotId, ds.DelegateNo, ds.user_id, ifnull(ds.name,wd.name) as name, ifnull(ds.email,wd.email) as email, ifnull(ds.mobile ,wd.mobile ) as mobile FROM delegateslot ds left join workshop_delegates wd on ds.DelegateNo collate utf8mb4_unicode_ci = wd.delegate_no where ds.SlotId="+str(SlotId))
# stmt=text("SELECT fs.SlotId,u.full_name,u.email,u.mobile FROM users u left join facultyslot fs on fs.FacultySlotID=u.user_id where fs.SlotId='"+str(SlotId)+"' UNION SELECT name as full_name,email,mobile FROM facultyslot where SlotId="+str(SlotId)+";")
result=conn.execute(stmt).all()
results=[dict(r._mapping) for r in result] if result else None
return results
def Get_faculty_slot_time(self,SlotId):
with engine.connect() as conn:
# stmt=text("select * from workshopcourses wc left join mcourseslots ms on wc.WorkshopCourseId=ms.WorkshopCourseId where wc.WorkshopCourseId="+str(course_id)+";")
stmt=text("SELECT * FROM facultyslot fs left join mcourseslots ms on fs.SlotId=ms.SlotId left join workshopcourses wc on wc.WorkshopCourseId=ms.WorkshopCourseId where fs.SlotId="+str(SlotId))
result=conn.execute(stmt).all()
results=[dict(r._mapping) for r in result] if result else None
return results
def CheckFacultyAlreadyExsits(self,SlotId,name):
with engine.connect() as conn:
stmt=text("select count(*) as count from facultyslot where name='"+str(name)+"' and SlotId="+str(SlotId))
result=conn.execute(stmt).one_or_none()
results=dict(result._mapping) if result else None
return results
def CheckDelegateAlreadyExsits(self,SlotId,name):
with engine.connect() as conn:
stmt=text("select count(*) as count from delegateslot where name='"+str(name)+"' and SlotId="+str(SlotId))
result=conn.execute(stmt).one_or_none()
results = dict(result._mapping) if result else None
return results
def DeleteFacultySlot(self,FacSlotId):
with engine.connect() as conn:
stmt=text("DELETE FROM facultyslot WHERE FacSlotId="+str(FacSlotId))
result=conn.execute(stmt)
conn.commit()
return "success"
def DeleteDelegateSlot(self,DelSlotID):
with engine.connect() as conn:
stmt = text("DELETE FROM delegateslot WHERE DelSlotID="+str(DelSlotID))
result = conn.execute(stmt)
conn.commit()
return "success"
def get_admin_data(self,conf_id):
with engine.connect() as conn:
stmt = text(f"select * from workshop_admim where conf_id = {conf_id};")
result = conn.execute(stmt).all()
results=[dict(r._mapping) for r in result] if result else None
return results
def edit_admin(self,admin_id):
with engine.connect() as conn:
stmt=text("select * from workshop_admim where admin_id="+str(admin_id))
result=conn.execute(stmt).one_or_none()
results=dict(result._mapping) if result else None
return results
def Update_admin_data(self,admin_id,data):
with engine.connect() as conn:
stmt = self.workshop_admim.update().where(self.workshop_admim.c.admin_id.in_([admin_id])).values(data)
result = conn.execute(stmt)
conn.commit()
return 'success'
def add_admin_data(self,data):
with engine.connect() as conn:
result = conn.execute(self.workshop_admim.insert(), data)
conn.commit()
return "success"
def get_workshop_name(self,conf_id):
with engine.connect() as conn:
stmt=text(f"select WorkshopName from m_workshop where conf_id = {conf_id} ")
result=conn.execute(stmt).all()
results=[dict(r._mapping) for r in result] if result else None
return results
def get_workshop_id(self,WorkshopName):
with engine.connect() as conn:
stmt=text("select workshopId from m_workshop where WorkshopName in ("+str(WorkshopName)+")")
result=conn.execute(stmt).all()
results=[dict(r._mapping) for r in result] if result else None
return results
def check_user_name(self,user_name,admin_id):
with engine.connect() as conn:
if admin_id==0:
stmt=text("SELECT count(*) as user_name FROM workshop_admim where user_name='"+str(user_name)+"'")
else:
stmt=text("SELECT count(*) as user_name FROM workshop_admim where user_name='"+str(user_name)+"' and admin_id!="+str(admin_id))
result=conn.execute(stmt).one_or_none()
results=dict(result._mapping) if result else None
return results
def view_delegate_data(self,SlotId):
with engine.connect() as conn:
stmt=text("SELECT wd.* FROM delegateslot ds left join workshop_delegates wd on ds.DelegateNo collate utf8mb4_general_ci =wd.delegate_no where ds.SlotId="+str(SlotId))
result=conn.execute(stmt).all()
results=[dict(r._mapping) for r in result] if result else None
return results
def add_new_faculty(self,data):
with engine.connect() as conn:
result = conn.execute(self.facultyslot.insert(), data)
conn.commit()
return "success"
def add_new_delegate(self,data):
with engine.connect() as conn:
result = conn.execute(self.delegateslot.insert(), data)
conn.commit()
return "success"
def Chosen_delegates(self,course_id):
with engine.connect() as conn:
stmt=text("select wd.*,dc.*,cs.* from delegatecourse dc inner join workshop_delegates wd on dc.Delegate_no = wd.Delegate_no inner join delegateslot ds on ds.DelegateNo = wd.delegate_no and ds.course_id = dc.course_id inner join mcourseslots cs on ds.SlotId = cs.SlotId where dc.course_id = {}".format(course_id))
result=conn.execute(stmt)
results=[dict(r._mapping) for r in result] if result else None
return results
def nonchosen_deleg(self,course_id):
with engine.connect() as conn:
stmt=text("select * from delegatecourse dc inner join workshop_delegates wd on dc.Delegate_no = wd.Delegate_no and dc.Delegate_no not in (select ds.DelegateNo from delegateslot ds where course_id = dc.course_id) where course_id = {} ".format(course_id))
result=conn.execute(stmt).all()
results=[dict(r._mapping) for r in result] if result else None
return results
def get_slot_list(self,course_id):
with engine.connect() as conn:
stmt = text("select m.*,(select count(*) from delegateslot where slotId = m.SlotId) as total_delegate_count from mcourseslots m where WorkshopCourseId = {}".format(course_id))
results = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results] if results else None
return results
def insert_delegate_Slot(self,slot_id,delegate_no,course_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("delegate_sloting",[delegate_no,course_id,slot_id])
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
if results :
return results[0]
else :
return None
def insert_delegate_Slot_v1(self,slot_id,delegate_no,course_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("delegate_sloting_v1",[delegate_no,course_id,slot_id])
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
if results :
return results[0]
else :
return None
def get_date_session_data(self,date,workshop_id):
with engine.connect() as conn:
stmt = text("select * from mcourseslots cs inner join workshopcourses wc on cs.WorkshopCourseId = wc.WorkshopCourseId where WorkshopId = {} and Date = '{}' order by Date,StartTime".format(workshop_id,date))
results = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results] if results else None
return results
def get_date_session_speaker_data(self,date,workshop_id):
with engine.connect() as conn:
stmt = text(f"(SELECT DelSlotID,ds.SlotId,DelegateNo COLLATE utf8mb4_general_ci, IFNULL(ds.name, wd.name) COLLATE utf8mb4_general_ci AS name,IFNULL(ds.email, wd.email) COLLATE utf8mb4_general_ci AS email,IFNULL(ds.mobile, wd.mobile) COLLATE utf8mb4_general_ci AS mobile,is_present COLLATE utf8mb4_general_ci,0 AS is_faculty,'Delegate' COLLATE utf8mb4_general_ci AS Role FROM delegateslot ds LEFT JOIN workshop_delegates wd ON ds.DelegateNo COLLATE utf8mb4_general_ci = wd.delegate_no COLLATE utf8mb4_general_ci INNER JOIN mcourseslots mcs ON ds.SlotId = mcs.SlotId INNER JOIN workshopcourses wc ON wc.WorkshopCourseId = mcs.WorkshopCourseId WHERE WorkshopId = :workshop_id AND Date = :date) UNION (SELECT FacSlotId,ds.SlotId,FacultySlotID COLLATE utf8mb4_general_ci, IFNULL(ds.name, wd.name) COLLATE utf8mb4_general_ci AS name,IFNULL(ds.email, wd.email) COLLATE utf8mb4_general_ci AS email,IFNULL(ds.mobile, wd.mobile) COLLATE utf8mb4_general_ci AS mobile,is_present COLLATE utf8mb4_general_ci,1 AS is_faculty,'Faculty' COLLATE utf8mb4_general_ci AS Role FROM facultyslot ds LEFT JOIN workshop_delegates wd ON ds.FacultySlotID COLLATE utf8mb4_general_ci = wd.delegate_no COLLATE utf8mb4_general_ci INNER JOIN mcourseslots mcs ON ds.SlotId = mcs.SlotId INNER JOIN workshopcourses wc ON wc.WorkshopCourseId = mcs.WorkshopCourseId WHERE WorkshopId = {workshop_id} AND Date = {date})")
results = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results] if results else None
return results
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists