-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
111 lines (83 loc) · 2.96 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
import io
from flask import Flask, render_template, request
from docxtpl import DocxTemplate, InlineImage
from docx.shared import Mm
from pdf_parser import name_talent_file, generate_cv_front_page, generate_cv
from utils import render_and_send_file, unflatten_dict
# Config
app = Flask(__name__)
app.secret_key = "234hj32v4k32b4jb32lj4b32lj4"
app.config["WTF_CSRF_ENABLED"] = False # Disable CSRF protection
# Routing
@app.route("/")
def index():
return render_template("index.html")
@app.route("/employeneur_profile_form", methods=["GET", "POST"])
def employeneur_profile_form():
if request.method == "GET":
return render_template("employeneur_profile_form.html")
# Parse data
tpl = DocxTemplate("docx_templates/cv-template.docx")
data = unflatten_dict(request.form.to_dict())
# Handle file upload
profile_pic = request.files["profile_pic"]
data["profile_pic"] = (
InlineImage(tpl, profile_pic, height=Mm(40)) if profile_pic else None
)
# Transform expertise sections
def parse_expertise(ex: dict) -> dict:
return {
"name": ex["name"],
"basic": "X" if ex["level"] == "1" else "",
"good": "X" if ex["level"] == "2" else "",
"excellent": "X" if ex["level"] == "3" else "",
}
expertise = data.get("expertise")
if expertise:
for ex in expertise:
ex["list"] = list(map(parse_expertise, ex["list"]))
print(data)
return render_and_send_file(
data=data,
tpl=tpl,
download_name=name_talent_file(data),
)
@app.route("/employeneur_profile_form_ai", methods=["GET", "POST"])
def employeneur_profile_form_ai():
if request.method == "GET":
return render_template("employeneur_profile_form_ai.html")
cv_pdf = request.files["pdfFile"]
form = request.form.to_dict() # Get form data
job_description = form.get("jobDescription")
tpl = DocxTemplate("docx_templates/cv-template.docx")
cv = generate_cv(io.BytesIO(cv_pdf.stream.read()))
if job_description:
cv.update(generate_cv_front_page(job_description, cv))
return render_and_send_file(
data=cv,
tpl=tpl,
download_name=name_talent_file(cv),
)
@app.route("/qm-meeting-report", methods=["GET", "POST"])
def qm_meeting_report():
if request.method == "GET":
return render_template("qm_meeting_report.html")
# Parse data
data = unflatten_dict(request.form.to_dict())
def concat_list(l: None | list):
if l is None:
return ""
return ", ".join(l)
for attr in ("tmc_attendees", "company_attendees"):
data[attr] = concat_list(data.get(attr))
return render_and_send_file(
data=data,
tpl=DocxTemplate("docx_templates/qm-template.docx"),
download_name="Qualifications Meeting Report.docx",
)
if __name__ == "__main__":
app.run(
port=int(os.getenv("PORT", default=8000)),
debug=True,
)