Browse Source

Merge branch 'master' of https://gogs.earthsquad.global/athos/baangt-PDFComparison

Adeel 4 years ago
parent
commit
3248088cab
3 changed files with 17 additions and 8 deletions
  1. 1 0
      .gitignore
  2. 5 1
      pdf_comaprison_flask_api/Dockerfile
  3. 11 7
      pdf_comaprison_flask_api/app.py

+ 1 - 0
.gitignore

@@ -3,3 +3,4 @@
 ################################################################################
 
 /.vs
+/.idea

+ 5 - 1
pdf_comaprison_flask_api/Dockerfile

@@ -10,5 +10,9 @@ RUN mkdir /project
 WORKDIR /project
 ADD . /project
 RUN pip install -r requirements.txt
+RUN export FLASK_APP=app.py
+RUN flask db init
+RUN flask db migrate
+RUN flask db upgrade
 EXPOSE 5050
-CMD ["python","app.py"]
+CMD flask run

+ 11 - 7
pdf_comaprison_flask_api/app.py

@@ -121,7 +121,7 @@ def update_reference_file():
                 file_ref = request.files['reference']
                 files_json = [{'file_ref':file_ref.filename,'uuid':str(uuid),'desc':desc}]
                 try:
-                    if  allowed_file(file_ref.filename):
+                    if allowed_file(file_ref.filename):
                         blob_ref = base64.b64encode(file_ref.read())
                         
                         ref = ReferenceFile.query.filter_by(uuid = uuid).one()
@@ -132,7 +132,7 @@ def update_reference_file():
                         
                         return jsonify(files_json)
                     else:
-                        return Response("All fields must be selected", status=400, mimetype='application/json')
+                        return Response("All fields must be selected - inner", status=400, mimetype='application/json')
                 except Exception:
                     # exc_type, exc_obj, exc_tb = sys.exc_info()
                     # fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
@@ -140,7 +140,7 @@ def update_reference_file():
                     logging.error("Exception occurred", exc_info=True)
                     return Response("Error in uploading", status=400, mimetype='application/json')
             except Exception:
-                return Response("All fields must be selected", status=400, mimetype='application/json')
+                return Response("All fields must be selected - outer", status=400, mimetype='application/json')
     else:
         return Response("Bad request", status=400, mimetype='application/json')    
 
@@ -150,12 +150,16 @@ def upload_original_file():
     uu_id = uuid.uuid1()
     if request.method == 'POST':
         if request.files:
+            resp_String = request.__str__
             try:
                 desc = request.form['description']
+                resp_String += " found descrption"
                 ref_uuid = request.form['reference_uuid']
+                resp_String += " found reference_uuid"
                 file_orig = request.files['original']
+                resp_String += " found file original"
                 files_json = [{'file_orig':file_orig.filename,'uuid':str(uu_id.int), 'desc':desc, 'ref_uuid':ref_uuid}]
-                if  allowed_file(file_orig.filename):
+                if allowed_file(file_orig.filename):
                     blob_orig = base64.b64encode(file_orig.read())
                     orig = OriginalFile(
                         uuid=str(uu_id.int), 
@@ -168,13 +172,13 @@ def upload_original_file():
                     
                     return jsonify(files_json)
                 else:
-                    return Response("All fields must be selected", status=422, mimetype='application/json')
-            except Exception:
+                    return Response("All fields must be selected - inner", status=422, mimetype='application/json')
+            except Exception as e:
                 # exc_type, exc_obj, exc_tb = sys.exc_info()
                 # fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
                 # print(exc_type, fname, exc_tb.tb_lineno)
                 logging.error("Exception occurred", exc_info=True)
-                return Response("All fields must be selected", status=422, mimetype='application/json')
+                return Response(f"All fields must be selected - outer {resp_String}, Exception {e}", status=422, mimetype='application/json')
         else:
             uuid_value = request.json['uuid']
             try: