Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,9 @@ from openpyxl import Workbook
|
|
7 |
from openpyxl.styles import Font, PatternFill, Alignment
|
8 |
import tempfile
|
9 |
import re
|
|
|
|
|
|
|
10 |
|
11 |
# Configure logging
|
12 |
logging.basicConfig(level=logging.DEBUG)
|
@@ -271,5 +274,137 @@ def internal_error(error):
|
|
271 |
"message": "Internal server error"
|
272 |
}), 500
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
if __name__ == "__main__":
|
275 |
-
app.run(debug=True, host="0.0.0.0", port=5000)
|
|
|
7 |
from openpyxl.styles import Font, PatternFill, Alignment
|
8 |
import tempfile
|
9 |
import re
|
10 |
+
# Add these imports at the top of your Flask app
|
11 |
+
import uuid
|
12 |
+
from flask import request as flask_request
|
13 |
|
14 |
# Configure logging
|
15 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
274 |
"message": "Internal server error"
|
275 |
}), 500
|
276 |
|
277 |
+
# Add these imports at the top of your Flask app
|
278 |
+
import uuid
|
279 |
+
from flask import request as flask_request
|
280 |
+
|
281 |
+
# Add these constants after your other file paths
|
282 |
+
WAITING_LIST_FILE = os.path.join(DATA_DIR, "waiting_list.json")
|
283 |
+
|
284 |
+
# Add these functions to handle waiting list data
|
285 |
+
def load_waiting_list():
|
286 |
+
"""Load waiting list from JSON file"""
|
287 |
+
try:
|
288 |
+
if os.path.exists(WAITING_LIST_FILE):
|
289 |
+
with open(WAITING_LIST_FILE, 'r', encoding='utf-8') as f:
|
290 |
+
return json.load(f)
|
291 |
+
return []
|
292 |
+
except Exception as e:
|
293 |
+
logging.error(f"Error loading waiting list: {e}")
|
294 |
+
return []
|
295 |
+
|
296 |
+
def save_waiting_list(waiting_list):
|
297 |
+
"""Save waiting list to JSON file"""
|
298 |
+
try:
|
299 |
+
with open(WAITING_LIST_FILE, 'w', encoding='utf-8') as f:
|
300 |
+
json.dump(waiting_list, f, indent=2, ensure_ascii=False)
|
301 |
+
return True
|
302 |
+
except Exception as e:
|
303 |
+
logging.error(f"Error saving waiting list: {e}")
|
304 |
+
return False
|
305 |
+
|
306 |
+
# Add this new route to handle waiting list signups
|
307 |
+
@app.route('/wait/<email>')
|
308 |
+
def add_to_waiting_list(email):
|
309 |
+
"""Add email to waiting list"""
|
310 |
+
try:
|
311 |
+
# Validate email
|
312 |
+
if not validate_email(email):
|
313 |
+
return jsonify({
|
314 |
+
"success": False,
|
315 |
+
"message": "Invalid email format"
|
316 |
+
}), 400
|
317 |
+
|
318 |
+
# Load existing waiting list
|
319 |
+
waiting_list = load_waiting_list()
|
320 |
+
|
321 |
+
# Check if email already exists
|
322 |
+
existing_emails = [entry.get('email') for entry in waiting_list]
|
323 |
+
if email in existing_emails:
|
324 |
+
return jsonify({
|
325 |
+
"success": False,
|
326 |
+
"message": "Email already in waiting list"
|
327 |
+
}), 409
|
328 |
+
|
329 |
+
# Add new entry
|
330 |
+
entry_data = {
|
331 |
+
"id": str(uuid.uuid4()),
|
332 |
+
"email": email.lower().strip(),
|
333 |
+
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
334 |
+
"website": flask_request.args.get('website', '') # Optional website parameter
|
335 |
+
}
|
336 |
+
|
337 |
+
waiting_list.append(entry_data)
|
338 |
+
|
339 |
+
# Save to file
|
340 |
+
if save_waiting_list(waiting_list):
|
341 |
+
logging.info(f"New waiting list entry: {email}")
|
342 |
+
return jsonify({
|
343 |
+
"success": True,
|
344 |
+
"message": "Added to waiting list successfully",
|
345 |
+
"entry_id": entry_data["id"]
|
346 |
+
})
|
347 |
+
else:
|
348 |
+
return jsonify({
|
349 |
+
"success": False,
|
350 |
+
"message": "Failed to save to waiting list"
|
351 |
+
}), 500
|
352 |
+
|
353 |
+
except Exception as e:
|
354 |
+
logging.error(f"Error adding to waiting list: {e}")
|
355 |
+
return jsonify({
|
356 |
+
"success": False,
|
357 |
+
"message": "Internal server error"
|
358 |
+
}), 500
|
359 |
+
|
360 |
+
# Add this route to get waiting list data
|
361 |
+
@app.route('/api/waiting_list')
|
362 |
+
def get_waiting_list_api():
|
363 |
+
"""API endpoint to get waiting list"""
|
364 |
+
waiting_list = load_waiting_list()
|
365 |
+
return jsonify({
|
366 |
+
"success": True,
|
367 |
+
"waiting_list": waiting_list,
|
368 |
+
"total": len(waiting_list)
|
369 |
+
})
|
370 |
+
|
371 |
+
# Add this route to delete a waiting list entry
|
372 |
+
@app.route('/delete_waiting_entry/<entry_id>', methods=['POST'])
|
373 |
+
def delete_waiting_entry(entry_id):
|
374 |
+
"""Delete a waiting list entry"""
|
375 |
+
try:
|
376 |
+
waiting_list = load_waiting_list()
|
377 |
+
original_count = len(waiting_list)
|
378 |
+
|
379 |
+
# Filter out the entry to delete
|
380 |
+
waiting_list = [entry for entry in waiting_list if entry.get('id') != entry_id]
|
381 |
+
|
382 |
+
if len(waiting_list) < original_count:
|
383 |
+
if save_waiting_list(waiting_list):
|
384 |
+
flash(f"Waiting list entry deleted successfully", "success")
|
385 |
+
else:
|
386 |
+
flash("Error deleting waiting list entry", "error")
|
387 |
+
else:
|
388 |
+
flash("Entry not found", "warning")
|
389 |
+
|
390 |
+
return redirect(url_for('admin'))
|
391 |
+
|
392 |
+
except Exception as e:
|
393 |
+
logging.error(f"Error deleting waiting list entry: {e}")
|
394 |
+
flash("Error deleting waiting list entry", "error")
|
395 |
+
return redirect(url_for('admin'))
|
396 |
+
|
397 |
+
# Update your admin route to include waiting list data
|
398 |
+
@app.route('/admin')
|
399 |
+
def admin():
|
400 |
+
"""Admin dashboard to view all tickets and waiting list"""
|
401 |
+
tickets = load_tickets()
|
402 |
+
waiting_list = load_waiting_list()
|
403 |
+
return render_template('admin.html',
|
404 |
+
tickets=tickets,
|
405 |
+
total_tickets=len(tickets),
|
406 |
+
waiting_list=waiting_list,
|
407 |
+
total_waiting=len(waiting_list))
|
408 |
+
|
409 |
if __name__ == "__main__":
|
410 |
+
app.run(debug=True, host="0.0.0.0", port=5000)
|