main flow checked
This commit is contained in:
parent
b5bf3a5dbe
commit
f853ad9784
21 changed files with 365 additions and 89 deletions
|
|
@ -4,6 +4,8 @@ from django.contrib import messages
|
|||
from django.http import JsonResponse
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.template import Template, Context
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from processes.models import ProcessInstance, StepInstance
|
||||
from invoices.models import Invoice
|
||||
|
|
@ -28,20 +30,33 @@ def _render_template(template: CertificateTemplate, instance: ProcessInstance):
|
|||
well = instance.well
|
||||
rep = instance.representative
|
||||
latest_report = InstallationReport.objects.filter(assignment__process_instance=instance).order_by('-created').first()
|
||||
individual = True if rep.profile and rep.profile.user_type == 'individual' else False
|
||||
customer_company_name = rep.profile.company_name if rep.profile and rep.profile.user_type == 'legal' else None
|
||||
city = template.company.broker.affairs.county.city.name if template.company and template.company.broker and template.company.broker.affairs and template.company.broker.affairs.county and template.company.broker.affairs.county.city else None
|
||||
county = template.company.broker.affairs.county.name if template.company and template.company.broker and template.company.broker.affairs and template.company.broker.affairs.county else None
|
||||
|
||||
ctx = {
|
||||
'today_jalali': _to_jalali(timezone.now().date()),
|
||||
'request_code': instance.code,
|
||||
'company_name': (template.company.name if template.company else '') or '',
|
||||
'customer_full_name': rep.get_full_name() if rep else '',
|
||||
'water_subscription_number': getattr(well, 'water_subscription_number', '') or '',
|
||||
'address': getattr(well, 'county', '') or '',
|
||||
'visit_date_jalali': _to_jalali(getattr(latest_report, 'visited_date', None)) if latest_report else '',
|
||||
'today_jalali': mark_safe(f"<span class=\"fw-bold\">{_to_jalali(timezone.now().date())}</span>"),
|
||||
'request_code': mark_safe(f"<span class=\"fw-bold\">{instance.code}</span>"),
|
||||
'company_name': mark_safe(f"<span class=\"fw-bold\">{(template.company.name if template.company else '') or ''}</span>"),
|
||||
'customer_full_name': mark_safe(f"<span class=\"fw-bold\">{rep.get_full_name() if rep else ''}</span>"),
|
||||
'water_subscription_number': mark_safe(f"<span class=\"fw-bold\">{getattr(well, 'water_subscription_number', '') or ''}</span>"),
|
||||
'address': mark_safe(f"<span class=\"fw-bold\">{getattr(well, 'county', '') or ''}</span>"),
|
||||
'visit_date_jalali': mark_safe(f"<span class=\"fw-bold\">{_to_jalali(getattr(latest_report, 'visited_date', None)) if latest_report else ''}</span>"),
|
||||
'city': mark_safe(f"<span class=\"fw-bold\">{city or ''}</span>"),
|
||||
'county': mark_safe(f"<span class=\"fw-bold\">{county or ''}</span>"),
|
||||
'customer_company_name': mark_safe(f"<span class=\"fw-bold\">{customer_company_name or ''}</span>"),
|
||||
'individual': individual,
|
||||
}
|
||||
title = (template.title or '').format(**ctx)
|
||||
body = (template.body or '')
|
||||
# Render body placeholders with bold values
|
||||
for k, v in ctx.items():
|
||||
body = body.replace(f"{{{{ {k} }}}}", f"<strong>{str(v)}</strong>")
|
||||
|
||||
# Render title using Django template engine
|
||||
title_template = Template(template.title or '')
|
||||
title = title_template.render(Context(ctx))
|
||||
|
||||
# Render body using Django template engine
|
||||
body_template = Template(template.body or '')
|
||||
body = body_template.render(Context(ctx))
|
||||
|
||||
return title, body
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue