|
@@ -25,7 +25,7 @@ app.config.from_object(Config)
|
|
|
db = SQLAlchemy(app)
|
|
|
migrate = Migrate(app, db)
|
|
|
|
|
|
-from models import ReferenceFile, OriginalFile
|
|
|
+from models import ReferenceFile, OriginalFile, OriginalFileRegex
|
|
|
|
|
|
CORS(app)
|
|
|
Bootstrap(app)
|
|
@@ -44,7 +44,6 @@ def upload_reference_file():
|
|
|
#### UPLOAD
|
|
|
if request.files:
|
|
|
desc = request.form['description']
|
|
|
- regex = request.form['regex']
|
|
|
file_ref = request.files['reference']
|
|
|
files_json = [{'file_ref':file_ref.filename,'uuid':str(uu_id.int), 'desc':desc}]
|
|
|
try:
|
|
@@ -54,8 +53,7 @@ def upload_reference_file():
|
|
|
uuid=str(uu_id.int),
|
|
|
reference_pdf_name=file_ref.filename,
|
|
|
reference_pdf=blob_ref,
|
|
|
- description=desc,
|
|
|
- regex=regex)
|
|
|
+ description=desc)
|
|
|
db.session.add(ref)
|
|
|
db.session.commit()
|
|
|
return jsonify(files_json)
|
|
@@ -130,6 +128,19 @@ def upload_original_file():
|
|
|
desc = request.form['description']
|
|
|
ref_uuid = request.form['reference_uuid']
|
|
|
file_orig = request.files['original']
|
|
|
+ count = 1
|
|
|
+ regex_list = []
|
|
|
+ while True:
|
|
|
+ try:
|
|
|
+ reg = request.form['regex' + str(count)]
|
|
|
+ if reg == '':
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ regex_list.append(reg)
|
|
|
+ except Exception:
|
|
|
+ break
|
|
|
+ count += 1
|
|
|
+
|
|
|
files_json = [{'file_orig':file_orig.filename,'uuid':str(uu_id.int), 'desc':desc, 'ref_uuid':ref_uuid}]
|
|
|
if allowed_file(file_orig.filename):
|
|
|
blob_orig = base64.b64encode(file_orig.read())
|
|
@@ -141,6 +152,13 @@ def upload_original_file():
|
|
|
uuid_ref=ref_uuid)
|
|
|
db.session.add(orig)
|
|
|
db.session.commit()
|
|
|
+
|
|
|
+ for i, reg in enumerate(regex_list):
|
|
|
+ orig_regex = OriginalFileRegex(
|
|
|
+ regex=reg,
|
|
|
+ uuid_orig=str(uu_id.int))
|
|
|
+ db.session.add(orig_regex)
|
|
|
+ db.session.commit()
|
|
|
return jsonify(files_json)
|
|
|
else:
|
|
|
return Response("All fields must be selected", status=422, mimetype='application/json')
|
|
@@ -152,9 +170,15 @@ def upload_original_file():
|
|
|
return Response("All fields must be selected", status=422, mimetype='application/json')
|
|
|
else:
|
|
|
uuid_value = request.json['uuid']
|
|
|
- orig = OriginalFile.query.filter_by(uuid = uuid_value).one()
|
|
|
- db.session.delete(orig)
|
|
|
- db.session.commit()
|
|
|
+ try:
|
|
|
+ OriginalFileRegex.query.filter_by(uuid_orig = uuid_value).delete()
|
|
|
+ db.session.commit()
|
|
|
+
|
|
|
+ orig = OriginalFile.query.filter_by(uuid = uuid_value).one()
|
|
|
+ db.session.delete(orig)
|
|
|
+ db.session.commit()
|
|
|
+ except Exception:
|
|
|
+ pass
|
|
|
return jsonify('')
|
|
|
else:
|
|
|
try:
|
|
@@ -231,6 +255,7 @@ def comparison_():
|
|
|
full_text1 = full_text1.replace(temp, '')
|
|
|
except Exception:
|
|
|
break
|
|
|
+ pdf_file_obj.close()
|
|
|
|
|
|
pdf_file_obj = open(input_file2, 'rb')
|
|
|
|
|
@@ -265,6 +290,8 @@ def comparison_():
|
|
|
except Exception:
|
|
|
break
|
|
|
|
|
|
+ pdf_file_obj.close()
|
|
|
+
|
|
|
str1 = full_text1
|
|
|
str2 = full_text2
|
|
|
|
|
@@ -388,17 +415,41 @@ def comparison_():
|
|
|
except Exception:
|
|
|
logging.error("Exception occurred", exc_info=True)
|
|
|
return Response("Error in Comparison", status=400, mimetype='application/json')
|
|
|
+
|
|
|
+ if one_final == "" and two_final == "":
|
|
|
+ resp = {'result' : 'OK'}
|
|
|
+ return jsonify(resp)
|
|
|
+
|
|
|
+ else:
|
|
|
+ resp = {'result' : {'orig_file_diff' : one_final, 'ref_file_diff': two_final}}
|
|
|
+ return jsonify(resp)
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- return send_file(basedir.joinpath('output', 'output.zip'), as_attachment=True)
|
|
|
else:
|
|
|
return Response("Bad Request", status=400, mimetype='application/json')
|
|
|
|
|
|
-
|
|
|
+@app.route('/download_comparison',methods=['POST', 'GET'])
|
|
|
+def download_comparison_():
|
|
|
+ if request.method == 'GET':
|
|
|
+ basedir = Path.cwd()
|
|
|
+ return send_file(basedir.joinpath('output', 'output.zip'), as_attachment=True)
|
|
|
+
|
|
|
@app.route('/')
|
|
|
def index():
|
|
|
return render_template('default.html')
|
|
|
|
|
|
+@app.after_request
|
|
|
+def add_header(r):
|
|
|
+ """
|
|
|
+ Add headers to both force latest IE rendering engine or Chrome Frame,
|
|
|
+ and also to cache the rendered page for 10 minutes.
|
|
|
+ """
|
|
|
+ r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
|
|
|
+ r.headers["Pragma"] = "no-cache"
|
|
|
+ r.headers["Expires"] = "0"
|
|
|
+ r.headers['Cache-Control'] = 'public, max-age=0'
|
|
|
+ return r
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
|
|
|
app.run(host='0.0.0.0')
|