ac0418083b
Модель вакансий, флоу рекрутинга и панели HR-портала (заявки/вакансии). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
84 lines
2.7 KiB
Python
84 lines
2.7 KiB
Python
"""PDF з обліковими даними після затвердження кандидата."""
|
|
from pathlib import Path
|
|
|
|
from django.http import HttpResponse
|
|
from django.utils.translation import gettext as _
|
|
|
|
_FONT_CANDIDATES = (
|
|
Path('/usr/share/fonts/google-noto/NotoSans-Regular.ttf'),
|
|
Path('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf'),
|
|
Path('/usr/share/fonts/dejavu/DejaVuSans.ttf'),
|
|
)
|
|
|
|
|
|
def _resolve_font():
|
|
for path in _FONT_CANDIDATES:
|
|
if path.is_file():
|
|
return str(path)
|
|
return None
|
|
|
|
|
|
def build_credentials_pdf(hiring_request, *, invite_url: str = '') -> bytes:
|
|
from fpdf import FPDF
|
|
from fpdf.enums import XPos, YPos
|
|
|
|
employee = hiring_request.employee
|
|
if employee is None:
|
|
raise ValueError('HiringRequest has no employee')
|
|
|
|
pdf = FPDF()
|
|
pdf.set_auto_page_break(auto=True, margin=15)
|
|
pdf.add_page()
|
|
pdf.set_margins(20, 20, 20)
|
|
|
|
font_path = _resolve_font()
|
|
font_name = 'Portal' if font_path else 'Helvetica'
|
|
if font_path:
|
|
pdf.add_font('Portal', fname=font_path)
|
|
pdf.set_font(font_name, size=14)
|
|
|
|
pdf.cell(
|
|
0, 10, _('Учётные данные сотрудника'),
|
|
new_x=XPos.LMARGIN, new_y=YPos.NEXT,
|
|
)
|
|
pdf.ln(4)
|
|
pdf.set_font(font_name, size=11)
|
|
|
|
dash = '-'
|
|
lines = [
|
|
f"{_('ФИО')}: {employee.last_name} {employee.first_name} {employee.middle_name}".strip(),
|
|
f"{_('Должность')}: {employee.post.name if employee.post_id else dash}",
|
|
f"{_('Тип локации')}: {hiring_request.get_user_location_type_display()}",
|
|
f"{_('Логин')}: {employee.username}",
|
|
f"{_('Посилання для пароля')}: {invite_url or dash}",
|
|
f"{_('Рабочий email')}: {employee.email or dash}",
|
|
'',
|
|
f"{_('Запрошенные доступы')}:",
|
|
]
|
|
accesses = list(hiring_request.requested_access.all())
|
|
if accesses:
|
|
for access in accesses:
|
|
lines.append(f' - {access.name}')
|
|
else:
|
|
lines.append(f" {_('(не указано)')}")
|
|
|
|
for line in lines:
|
|
if not line:
|
|
pdf.ln(4)
|
|
continue
|
|
pdf.set_x(pdf.l_margin)
|
|
pdf.multi_cell(
|
|
pdf.epw, 7, line,
|
|
new_x=XPos.LMARGIN, new_y=YPos.NEXT,
|
|
)
|
|
|
|
return bytes(pdf.output())
|
|
|
|
|
|
def credentials_pdf_response(hiring_request) -> HttpResponse:
|
|
content = build_credentials_pdf(hiring_request)
|
|
filename = f'credentials-{hiring_request.employee.username}.pdf'
|
|
response = HttpResponse(content, content_type='application/pdf')
|
|
response['Content-Disposition'] = f'attachment; filename="{filename}"'
|
|
return response
|