Dodato full regenerisanje dokumenta,dodat fallback za incomplete document
This commit is contained in:
@@ -2,15 +2,22 @@ from celery import shared_task
|
||||
from backend.core.models import Organization, Document, Risk, Control, DocumentRiskControl
|
||||
from backend.core.utils import get_top_risk, get_controls_for_risk, generate_key_findings, generate_recommendations
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from .utils import send_payment_email
|
||||
from .utils import send_payment_email, send_document_to_reviewer
|
||||
from backend.core.tables import get_risk_table
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@shared_task
|
||||
def create_document_for_organization(confirmation_email):
|
||||
|
||||
organization = get_object_or_404(Organization, email=confirmation_email)
|
||||
is_incomplete = False
|
||||
|
||||
organization = get_object_or_404(Organization, email=confirmation_email)
|
||||
top_risk_ids = get_top_risk(organization)
|
||||
print(f"Risks number: {len(top_risk_ids)}")
|
||||
if len(top_risk_ids) != 10:
|
||||
is_incomplete = True
|
||||
top_risk_ids = get_top_risk(organization)
|
||||
top_risks = Risk.objects.filter(risk_id__in=top_risk_ids)
|
||||
organization.risks.set(top_risks)
|
||||
|
||||
@@ -36,7 +43,11 @@ def create_document_for_organization(confirmation_email):
|
||||
controls_content += f"Risk: {risk.risk_id} - {risk.risk_name}\n"
|
||||
|
||||
selected_controls = get_controls_for_risk(risk ,organization=organization)
|
||||
|
||||
print(f"Controls for current risk: {len(selected_controls)}")
|
||||
if len(selected_controls) < 10:
|
||||
is_incomplete = True
|
||||
selected_controls = get_controls_for_risk(risk, organization=organization)
|
||||
|
||||
for control_id, weight, likelihood in selected_controls:
|
||||
control = Control.objects.filter(id=control_id).first()
|
||||
if control:
|
||||
@@ -65,4 +76,10 @@ def create_document_for_organization(confirmation_email):
|
||||
document.recomendations = recommendations
|
||||
document.save()
|
||||
|
||||
if is_incomplete:
|
||||
# mark document incomplete and update modified timestamp
|
||||
logger.info("Marking document %s as INCOMPLETE (is_incomplete=%s)", document.id, is_incomplete)
|
||||
document.status = Document.STATUS_INCOMPLETE
|
||||
document.save(update_fields=['status', 'modified_at'])
|
||||
|
||||
send_payment_email(confirmation_email)
|
||||
|
||||
@@ -63,6 +63,27 @@ def send_documet_to_expert(email, document):
|
||||
fail_silently=False,
|
||||
)
|
||||
|
||||
def send_document_to_reviewer(email, document):
|
||||
subject = "Incomplete Document Review Needed"
|
||||
document_link = f"{site_domain}{reverse('core:document', args=[document.id])}"
|
||||
edit_link = f"{site_domain}{reverse('admin:core_document_change', args=[document.id])}"
|
||||
|
||||
message = f"""
|
||||
We had some problems generating document, please review and complete it as needed.
|
||||
When u are done, please save document, and send it to the customer.
|
||||
Document ID: {document.id}
|
||||
Document Link: {document_link}
|
||||
Edit Document: {edit_link}
|
||||
"""
|
||||
|
||||
send_mail(
|
||||
subject=subject,
|
||||
message=message,
|
||||
from_email=settings.DEFAULT_FROM_EMAIL,
|
||||
recipient_list=[email],
|
||||
fail_silently=False,
|
||||
)
|
||||
|
||||
def send_document_email(email, document_link, document):
|
||||
image_io = generate_first_page_image(document)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user