modify upload documents and filter store-proc commit
This commit is contained in:
@@ -30,29 +30,20 @@ class DocumentHandler:
|
||||
return
|
||||
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# --- FILTER QUERY ---
|
||||
query = "SELECT * FROM documents WHERE 1=1"
|
||||
params = []
|
||||
cursor.callproc("GetDocuments", [year, stage])
|
||||
|
||||
if year != "":
|
||||
query += " AND year = %s"
|
||||
params.append(year)
|
||||
|
||||
if stage != "":
|
||||
query += " AND stage = %s"
|
||||
params.append(stage)
|
||||
|
||||
|
||||
cursor.execute(query, params)
|
||||
self.documents = cursor.fetchall()
|
||||
# fetch first result set
|
||||
for result in cursor.stored_results():
|
||||
self.documents = result.fetchall()
|
||||
break
|
||||
|
||||
# ---- GET YEARS FROM STORED PROCEDURE ----
|
||||
cursor.callproc("GetYear")
|
||||
|
||||
for result in cursor.stored_results():
|
||||
year_rows = result.fetchall()
|
||||
break # only first result set
|
||||
break
|
||||
|
||||
self.years = [row['year'] for row in year_rows]
|
||||
|
||||
@@ -60,10 +51,8 @@ class DocumentHandler:
|
||||
connection.close()
|
||||
self.isSuccess = True
|
||||
|
||||
# UPLOAD DOCUMENTS
|
||||
# Upload Documents
|
||||
def Upload(self, request):
|
||||
"""Log user actions with timestamp, user, action, and details."""
|
||||
|
||||
dbconfig = DBConfig()
|
||||
connection = dbconfig.get_db_connection()
|
||||
|
||||
@@ -72,25 +61,17 @@ class DocumentHandler:
|
||||
files = request.files.getlist('documents')
|
||||
year = request.form['year']
|
||||
stage = request.form['stage']
|
||||
|
||||
for file in files:
|
||||
if file is not FileHandler.ALLOWED_EXTENSIONS:
|
||||
continue
|
||||
|
||||
for file in files:
|
||||
extension = file.filename.rsplit('.', 1)[1]
|
||||
if extension not in FileHandler.ALLOWED_EXTENSIONS:
|
||||
print("Skip invalid file type : ",extension)
|
||||
continue
|
||||
|
||||
filename = secure_filename(file.filename)
|
||||
filepath = os.path.join(FileHandler.UPLOAD_FOLDER, filename)
|
||||
extension = file.filename.rsplit('.', 1)[1]
|
||||
# Need to Check whetehr all three items are required
|
||||
|
||||
file.save(filepath)
|
||||
|
||||
# cursor.execute("""
|
||||
# INSERT INTO documents (filename, filepath, filetype, year, stage)
|
||||
# VALUES (%s, %s, %s, %s, %s)
|
||||
# """, (filename, filepath, file.filename.rsplit('.', 1)[1], year, stage))
|
||||
|
||||
|
||||
cursor.callproc('InsertDocument', [ filename, filepath, extension, year, stage ])
|
||||
|
||||
connection.commit()
|
||||
@@ -98,13 +79,11 @@ class DocumentHandler:
|
||||
connection.close()
|
||||
# return redirect(url_for('view_documents'))
|
||||
|
||||
|
||||
|
||||
# Summary report
|
||||
def Summary_report(self, request):
|
||||
|
||||
dbconfig = DBConfig()
|
||||
connection = dbconfig.get_db_connection()
|
||||
|
||||
year = request.args.get('year')
|
||||
|
||||
# if not year get all year in list.
|
||||
@@ -113,11 +92,7 @@ class DocumentHandler:
|
||||
allYears = yearGetter.get_year_by_model("AllYearsInAllModel")
|
||||
yearGetter.close()
|
||||
|
||||
return render_template(
|
||||
'summary_reports.html',
|
||||
years=allYears,
|
||||
message="Please select a year to download."
|
||||
)
|
||||
return render_template('summary_reports.html', years=allYears,message="Please select a year to download.")
|
||||
|
||||
# for excel
|
||||
try:
|
||||
@@ -132,7 +107,6 @@ class DocumentHandler:
|
||||
|
||||
for stage_name, table_name in stages.items():
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
cursor.callproc("sp_get_stage_data", [table_name, year])
|
||||
|
||||
for result in cursor.stored_results():
|
||||
|
||||
Reference in New Issue
Block a user