AdityaAdaki commited on
Commit
fae4149
·
1 Parent(s): 443465b
Files changed (2) hide show
  1. app.py +5 -5
  2. templates/index.html +33 -3
app.py CHANGED
@@ -134,15 +134,15 @@ def process_certificate(image_path, cert_name):
134
  def home():
135
  if request.method == "POST":
136
  try:
 
137
  cert_name = "Affiliation Certificate"
138
 
139
- # Debug print
140
- print("File received in request:", request.files)
141
-
142
  if 'certificate' not in request.files:
 
143
  return render_template("index.html", error="No file part in the request")
144
 
145
  file = request.files['certificate']
 
146
 
147
  if file.filename == '':
148
  return render_template("index.html", error="No file selected")
@@ -174,8 +174,8 @@ def home():
174
  return render_template("index.html", error=f"Error processing certificate: {str(e)}")
175
 
176
  except Exception as e:
177
- print(f"Error in file handling: {str(e)}")
178
- return render_template("index.html", error=f"Error saving file: {str(e)}")
179
 
180
  return render_template("index.html")
181
 
 
134
  def home():
135
  if request.method == "POST":
136
  try:
137
+ print("POST request received") # Debug print
138
  cert_name = "Affiliation Certificate"
139
 
 
 
 
140
  if 'certificate' not in request.files:
141
+ print("No file in request") # Debug print
142
  return render_template("index.html", error="No file part in the request")
143
 
144
  file = request.files['certificate']
145
+ print(f"File received: {file.filename}") # Debug print
146
 
147
  if file.filename == '':
148
  return render_template("index.html", error="No file selected")
 
174
  return render_template("index.html", error=f"Error processing certificate: {str(e)}")
175
 
176
  except Exception as e:
177
+ print(f"Error occurred: {str(e)}") # Debug print
178
+ return render_template("index.html", error=f"Error processing request: {str(e)}")
179
 
180
  return render_template("index.html")
181
 
templates/index.html CHANGED
@@ -296,9 +296,39 @@
296
  document.getElementById('file-name').textContent = fileName;
297
  });
298
 
299
- // Show loading animation on form submit
300
- document.getElementById('upload-form').addEventListener('submit', function() {
301
- document.getElementById('loading').style.display = 'block';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  });
303
  </script>
304
  </body>
 
296
  document.getElementById('file-name').textContent = fileName;
297
  });
298
 
299
+ // Handle form submission
300
+ document.getElementById('upload-form').addEventListener('submit', async function(e) {
301
+ e.preventDefault(); // Prevent default form submission
302
+
303
+ const form = e.target;
304
+ const loadingElement = document.getElementById('loading');
305
+
306
+ try {
307
+ // Show loading animation
308
+ loadingElement.style.display = 'block';
309
+
310
+ // Create FormData object
311
+ const formData = new FormData(form);
312
+
313
+ // Send POST request
314
+ const response = await fetch('/', {
315
+ method: 'POST',
316
+ body: formData
317
+ });
318
+
319
+ // Get the response text
320
+ const result = await response.text();
321
+
322
+ // Update the page content
323
+ document.body.innerHTML = result;
324
+
325
+ } catch (error) {
326
+ console.error('Error:', error);
327
+ alert('An error occurred while processing the certificate. Please try again.');
328
+ } finally {
329
+ // Hide loading animation
330
+ loadingElement.style.display = 'none';
331
+ }
332
  });
333
  </script>
334
  </body>