- 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
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""
|
|
Data models and storage functions for the Flask job application system.
|
|
"""
|
|
import os
|
|
import yaml
|
|
from pathlib import Path
|
|
from flask import current_app
|
|
|
|
|
|
def get_application_path(session_id):
|
|
"""Get the path to an application folder"""
|
|
return os.path.join(current_app.config['APPLICATIONS_FOLDER'], session_id)
|
|
|
|
|
|
def get_data_file_path(session_id):
|
|
"""Get the path to the application data YAML file"""
|
|
return os.path.join(get_application_path(session_id), 'data.yaml')
|
|
|
|
|
|
def get_attachments_path(session_id):
|
|
"""Get the path to the attachments folder"""
|
|
return os.path.join(get_application_path(session_id), 'attachments')
|
|
|
|
|
|
def load_application_data(session_id):
|
|
"""Load application data from YAML file"""
|
|
data_file = get_data_file_path(session_id)
|
|
if os.path.exists(data_file):
|
|
with open(data_file, 'r', encoding='utf-8') as f:
|
|
return yaml.safe_load(f)
|
|
return None
|
|
|
|
|
|
def save_application_data(session_id, data):
|
|
"""Save application data to YAML file"""
|
|
app_path = get_application_path(session_id)
|
|
Path(app_path).mkdir(parents=True, exist_ok=True)
|
|
|
|
data_file = get_data_file_path(session_id)
|
|
with open(data_file, 'w', encoding='utf-8') as f:
|
|
yaml.dump(data, f, allow_unicode=True, default_flow_style=False)
|