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 ConferenceModel():
def __init__(self):
try:
# conference
self.meta = MetaData()
self.society_applications = Table("society_applications", self.meta, autoload_with=engine)
except Exception as e:
print(e)
def get_conference_data(self,current_dt,email):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("get_admin_conference_data",[current_dt,email])
if cursor.description :
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
else :
return None
else :
cursor.close()
connection.commit()
return None
def get_conf_status_count(self,current_dt):
with engine.connect() as conn:
stmt = text("select COUNT(*) AS total_conf,"
+ " SUM(CASE WHEN is_active = 1 AND conf_end_time > '"+str(current_dt)+"' THEN 1 ELSE 0 END) AS upcoming_conf,"
+ " SUM(CASE WHEN is_active = 1 AND conf_end_time < '"+str(current_dt)+"' THEN 1 ELSE 0 END) AS past_conf,"
+ " SUM(CASE WHEN conf_start_time IS NOT NULL AND conf_end_time IS NOT NULL AND is_active = 0 THEN 1 ELSE 0 END) AS inactive_conf,"
+ " SUM(CASE WHEN conf_start_time IS NULL OR conf_end_time IS NULL OR is_active IS NULL THEN 1 ELSE 0 END) AS incompleted_conf"
+ " from conference ;");
result = conn.execute(stmt).first()
conn.close()
return dict(result._mapping) if result else None
def Insert_user_data_by_society_id(self, super_admin_email, society_id):
with engine.connect() as conn:
# Check if the user already exists (parameterized query to prevent SQL injection)
stmt_1 = text("SELECT * FROM users WHERE email = :email AND society_id = :society_id")
result_1 = conn.execute(stmt_1, {"email": super_admin_email, "society_id": society_id}).first()
if result_1 is None:
# Insert the user data if not already present
stmt_2 = text("INSERT INTO users (email, society_id) VALUES (:email, :society_id)")
conn.execute(stmt_2, {"email": super_admin_email, "society_id": society_id})
conn.commit()
# Fetch and return the newly inserted user data
result_3 = conn.execute(stmt_1, {"email": super_admin_email, "society_id": society_id}).first()
return dict(result_3._mapping) if result_3 else None
else:
# Return the existing user data
return dict(result_1._mapping)
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists