Files
govoplan-campaign/src/govoplan_campaign/backend/campaign/template_values.py
T
2026-06-24 01:43:27 +02:00

26 lines
982 B
Python

from __future__ import annotations
from typing import Any
from .addressing import effective_address_lists, recipient_template_values
from .field_values import effective_entry_field_values
from .models import CampaignConfig, EntryConfig
def build_template_values(config: CampaignConfig, entry: EntryConfig) -> dict[str, Any]:
values: dict[str, Any] = {}
for field in config.fields:
values.setdefault(field.name, "")
values.setdefault(f"global::{field.name}", "")
values.setdefault(f"local::{field.name}", "")
for key, value in config.global_values.items():
values[f"global::{key}"] = value
for key, value in effective_entry_field_values(config, entry).items():
values[key] = value
values[f"local::{key}"] = value
if entry.id:
values["local::id"] = entry.id
values["local::active"] = entry.active
values.update(recipient_template_values(effective_address_lists(config, entry)))
return values