Some checks failed
Build, Test, and Deploy / build-and-deploy (push) Failing after 29s
- Add zero-trust AST-based formula engine in custom_objects/formula_engine.py supporting arithmetic, logical, string, and date operations. - Enforce strict AST whitelisting and attribute/function safety checks. - Add cycle detection and topological sorting of formula dependencies. - Extend CustomFieldDefinition model with formula_expression and formula_return_type fields. - Wire pre-save signals to evaluate formula fields across standard models and CustomRecord. - Expose AST syntax validator endpoint at POST /api/custom-fields/validate-formula/. - Add comprehensive test suite in tests/test_formula_engine.py with 100% pass rate.
17 lines
687 B
Python
17 lines
687 B
Python
from django.db.models.signals import pre_save
|
|
from django.dispatch import receiver
|
|
from custom_objects.models import CustomRecord
|
|
from crm_core.models import Account, Contact, Lead, Opportunity, Activity
|
|
from outreach.models import Campaign
|
|
from custom_objects.formula_engine import evaluate_all_formulas_for_instance
|
|
|
|
|
|
@receiver(pre_save, sender=Account)
|
|
@receiver(pre_save, sender=Contact)
|
|
@receiver(pre_save, sender=Lead)
|
|
@receiver(pre_save, sender=Opportunity)
|
|
@receiver(pre_save, sender=Activity)
|
|
@receiver(pre_save, sender=Campaign)
|
|
@receiver(pre_save, sender=CustomRecord)
|
|
def evaluate_record_formulas(sender, instance, **kwargs):
|
|
evaluate_all_formulas_for_instance(instance)
|