refactor: split monolithic app.py into modular Flask application with factory pattern
- Created app/ package with 6 modules: - __init__.py: Application factory (create_app function) - routes.py: All route handlers (473 lines) - models.py: Data persistence layer (41 lines) - validators.py: Input validation functions (48 lines) - email_service.py: Email sending functions (85 lines) - utils.py: Utility functions (30 lines) - Implemented Flask application factory pattern - Created run.py as minimal entry point - Updated all test imports to use new module structure - Fixed template/static folder paths for package structure - All 102 tests passing - Improved maintainability with clear separation of concerns - Follows Flask best practices for scalable applications
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
Email service functions for the Flask job application system.
|
||||
"""
|
||||
from datetime import datetime
|
||||
from flask import url_for, current_app
|
||||
from flask_mail import Message
|
||||
from app import mail
|
||||
|
||||
|
||||
def send_resume_email(email, session_id, job_name):
|
||||
"""Send email with resume link"""
|
||||
resume_link = url_for('resume_application', session_id=session_id, _external=True)
|
||||
|
||||
subject = f"Ihre Bewerbung bei {current_app.config['COMPANY_NAME']} - Link zum Fortsetzen"
|
||||
body = f"""Guten Tag,
|
||||
|
||||
vielen Dank für Ihr Interesse an der Position "{job_name}" bei {current_app.config['COMPANY_NAME']}.
|
||||
|
||||
Sie können Ihre Bewerbung jederzeit über den folgenden Link fortsetzen:
|
||||
{resume_link}
|
||||
|
||||
Dieser Link bleibt gültig und Sie können Ihre Bewerbung jederzeit bearbeiten.
|
||||
|
||||
Mit freundlichen Grüßen
|
||||
{current_app.config['COMPANY_NAME']}
|
||||
"""
|
||||
|
||||
try:
|
||||
msg = Message(subject=subject, recipients=[email], body=body)
|
||||
mail.send(msg)
|
||||
return True
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Failed to send email: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def send_hr_notification(session_id, app_data):
|
||||
"""Send HR notification email when application is submitted"""
|
||||
if not current_app.config.get('HR_EMAIL'):
|
||||
current_app.logger.warning("HR_EMAIL not configured, skipping HR notification")
|
||||
return False
|
||||
|
||||
# Build application URL
|
||||
application_url = f"{current_app.config['APPLICATION_URL_BASE']}/application/{session_id}/"
|
||||
|
||||
# Get personal info
|
||||
personal_info = app_data.get('personal_info', {})
|
||||
firstname = personal_info.get('firstname', 'N/A')
|
||||
name = personal_info.get('name', 'N/A')
|
||||
email = app_data.get('email', 'N/A')
|
||||
job_name = app_data.get('job_name', 'N/A')
|
||||
file_count = len(app_data.get('uploaded_files', []))
|
||||
|
||||
# Format timestamp
|
||||
submitted_at = app_data.get('submitted_at', datetime.now().isoformat())
|
||||
try:
|
||||
timestamp = datetime.fromisoformat(submitted_at).strftime('%d.%m.%Y %H:%M')
|
||||
except (ValueError, TypeError):
|
||||
timestamp = submitted_at
|
||||
|
||||
subject = f"Neue Bewerbung eingegangen: {job_name}"
|
||||
body = f"""Sehr geehrtes HR-Team,
|
||||
|
||||
es ist eine neue Bewerbung eingegangen:
|
||||
|
||||
Position: {job_name}
|
||||
Name: {firstname} {name}
|
||||
E-Mail: {email}
|
||||
Eingereicht am: {timestamp}
|
||||
Anzahl der hochgeladenen Dokumente: {file_count}
|
||||
|
||||
Sie können die vollständige Bewerbung hier einsehen:
|
||||
{application_url}
|
||||
|
||||
Mit freundlichen Grüßen,
|
||||
Ihr Bewerbungssystem
|
||||
"""
|
||||
|
||||
try:
|
||||
msg = Message(subject=subject, recipients=[current_app.config['HR_EMAIL']], body=body)
|
||||
mail.send(msg)
|
||||
return True
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Failed to send HR notification email: {e}")
|
||||
return False
|
||||
Reference in New Issue
Block a user