HR notification added

This commit is contained in:
2025-12-27 21:57:10 +01:00
parent ce19237444
commit 733ee756c7
7 changed files with 1124 additions and 1 deletions
+96 -1
View File
@@ -4,7 +4,7 @@ import yaml
import re
from datetime import datetime, timedelta
from pathlib import Path
from flask import Flask, render_template, request, redirect, url_for, flash, session
from flask import Flask, render_template, request, redirect, url_for, flash, session, send_from_directory, abort
from flask_mail import Mail, Message
from flask_wtf.csrf import CSRFProtect, CSRFError
from werkzeug.utils import secure_filename
@@ -120,6 +120,57 @@ Mit freundlichen Grüßen
return False
def send_hr_notification(session_id, app_data):
"""Send HR notification email when application is submitted"""
if not app.config.get('HR_EMAIL'):
app.logger.warning("HR_EMAIL not configured, skipping HR notification")
return False
# Build application URL
application_url = f"{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=[app.config['HR_EMAIL']], body=body)
mail.send(msg)
return True
except Exception as e:
app.logger.error(f"Failed to send HR notification email: {e}")
return False
def validate_email(email):
"""Validate email format"""
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
@@ -522,6 +573,9 @@ def submit_application(session_id):
save_application_data(session_id, app_data)
# Send HR notification
send_hr_notification(session_id, app_data)
return redirect(url_for('page5_confirmation', session_id=session_id))
@@ -539,6 +593,47 @@ def page5_confirmation(session_id):
email=app_data['email'])
@app.route('/application/<session_id>/')
def view_application(session_id):
"""View complete application details (for HR)"""
app_data = load_application_data(session_id)
if not app_data:
abort(404)
return render_template('application_view.html',
session_id=session_id,
app_data=app_data)
@app.route('/application/<session_id>/download/<filename>')
def download_file(session_id, filename):
"""Download an uploaded file"""
app_data = load_application_data(session_id)
if not app_data:
abort(404)
# Verify the file is in the uploaded files list
uploaded_files = app_data.get('uploaded_files', [])
file_found = False
for file_info in uploaded_files:
if file_info.get('stored_name') == filename:
file_found = True
break
if not file_found:
abort(404)
# Serve the file
attachments_path = get_attachments_path(session_id)
file_path = os.path.join(attachments_path, filename)
if not os.path.exists(file_path):
abort(404)
return send_from_directory(attachments_path, filename, as_attachment=True)
@app.route('/resume/<session_id>')
def resume_application(session_id):
"""Resume application from email link"""