-
Notifications
You must be signed in to change notification settings - Fork 0
/
uiImpl.py
131 lines (118 loc) · 4.83 KB
/
uiImpl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import coreLogic
import os # For File Manipulations like get paths, rename
from flask import Flask, flash, request, redirect, render_template, send_file
from werkzeug.utils import secure_filename
import shutil
import csv
import openpyxl
from openpyxl.drawing.image import Image
from openpyxl.styles import Alignment, Border, Font, NamedStyle, Side
import os
path = os.getcwd()
app=Flask(__name__, static_folder=coreLogic.baseDir)
app.secret_key = "secret key" # for encrypting the session
#It will allow below 4MB contents only, you can change it
app.config['MAX_CONTENT_LENGTH'] = 4 * 1024 * 1024
# file Upload
UPLOAD_FOLDER = os.path.join(path, 'uploads')
transcripts_DIR = os.path.join(path, 'transcriptsIITP')
# Make directory if "uploads" folder not exists
if os.path.exists(UPLOAD_FOLDER):
shutil.rmtree(UPLOAD_FOLDER)
os.mkdir(UPLOAD_FOLDER)
if os.path.exists(transcripts_DIR):
shutil.rmtree(transcripts_DIR)
os.mkdir(transcripts_DIR)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
ALLOWED_EXTENSIONS = set(['csv', 'png', 'jpeg', 'jpg'])
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
def upload_form():
return render_template('upload.html')
@app.route('/download', methods=['GET', 'POST'])
def push_file():
resp = coreLogic.prepareTranscriptsArchive()
if resp:
file_path = os.path.join(os.getcwd(), "transcripts.zip")
return send_file(file_path, as_attachment=True)
else:
flash("Generate Transcripts First")
return redirect("/")
@app.route('/', methods=['GET','POST'])
def file():
if request.method == 'POST':
finfo = False
rejForm = 'application/octet-stream'
rfm = request.form
print("============")
print(rfm)
print("-----------------")
if 'files[]' not in request.files:
flash('No file part')
return redirect(request.url)
files = request.files.getlist('files[]')
rfSign = request.files['sign']
rfSeal = str(request.files['seal'])
print("+++++++")
print(files)
print(str(rfSign))
print(str(rfSeal))
print("++++++++")
if 'sign' in request.files and 'application/octet-stream' not in str(rfSign):
print(f"{request.files['sign']} || {type(request.files['sign'])}")
request.files['sign'].save(os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(request.files['sign'].filename)))
print(f"Saving attempt: {os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(request.files['sign'].filename))}")
if 'seal' in request.files and 'application/octet-stream' not in str(rfSeal):
print(f"{request.files['seal']} || {type(request.files['seal'])}")
request.files['seal'].save(os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(request.files['seal'].filename)))
print(f"Saving attempt: {os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(request.files['seal'].filename))}")
# print(f"saved to:{cPath}")
if rejForm not in str(files):
if len(files) == 3:
for file in files :
print(f"{file} || {type(file)}")
print("________________--8")
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
print(file)
print("***********8")
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
flash('File(s) successfully uploaded')
else:
finfo = True
flash("Please input all the required files!")
return redirect('/')
elif not finfo:
flash("Please input all the required files!")
return redirect('/')
if "range" in rfm and not finfo:
print("yyyyyyyyyy")
if rejForm not in str(files):
if "First" in rfm:
fst = rfm['First']
print(fst)
resp, tlst = coreLogic.prepMs(rfm['First'])
if resp:
flash('Transcripts generated in specified range')
if len(tlst) > 0:
flash(f"Roll Nos: {tlst} do not exist!")
else:
flash("Enter valid range for RollNos!")
else:
flash("Enter valid range for RollNos!")
elif not finfo:
flash("Please upload all the required files!")
if "transcript" in rfm:
if rejForm not in str(files):
resp, tlst = coreLogic.prepMs("", all=True)
if resp:
flash('All Transcript generated')
if len(tlst) > 0:
flash(f"Roll Nos: {tlst} do not exist!")
else:
if not finfo:
flash('Please upload all the required files')
return redirect('/')
if __name__ == "__main__":
app.run(debug=True)