Coverage for functions \ flipdare \ mailer \ app_email_params.py: 100%
38 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
3#
4# This file is part of Flipdare's proprietary software and contains
5# confidential and copyrighted material. Unauthorised copying,
6# modification, distribution, or use of this file is strictly
7# prohibited without prior written permission from Flipdare Pty Ltd.
8#
9# This software includes third-party components licensed under MIT,
10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
11#
13from __future__ import annotations
15from dataclasses import dataclass
16from pathlib import Path
17from flipdare.app_log import LOG
18from flipdare.constants import IS_DEBUG
19from flipdare.mailer.app_email_type import AppEmailType
20from flipdare.generated import (
21 InviteSubjectSchema,
22 DareSubjectSchema,
23 GroupDareSubjectSchema,
24 VoteSubjectSchema,
25 SummarySubjectSchema,
26 ContactSubjectSchema,
27 LogSubjectSchema,
28 ReportSubjectSchema,
29 CronSubjectSchema,
30 CommandSubjectSchema,
31 FlagSubjectSchema,
32)
34__all__ = ["AppEmailParams"]
37AppSubjectSchema = (
38 None
39 | InviteSubjectSchema
40 | DareSubjectSchema
41 | GroupDareSubjectSchema
42 | VoteSubjectSchema
43 | SummarySubjectSchema
44 | ContactSubjectSchema
45 | LogSubjectSchema
46 | ReportSubjectSchema
47 | CronSubjectSchema
48 | CommandSubjectSchema
49 | FlagSubjectSchema
50)
53@dataclass
54class AppEmailParams[T: AppSubjectSchema]:
55 email_type: AppEmailType
56 schema: T
58 @property
59 def subject(self) -> str:
60 # Get the template from a simple mapping
61 subj = self.email_type.subject
63 # Handle emails with no data
64 if self.schema is None:
65 return subj.format()
67 # Format the rest safely
68 upper_context = {k.upper(): v for k, v in self.schema.items()}
70 if IS_DEBUG:
71 msg = (
72 f"Formatting subject for email_type={self.email_type} with context={upper_context}"
73 )
74 LOG().debug(msg)
76 return subj.format(**upper_context)
78 @property
79 def abs_template_dir(self) -> Path:
80 return self.email_type.abs_template_dir
82 @property
83 def html_name(self) -> str:
84 return self.email_type.html_name
86 @property
87 def text_name(self) -> str:
88 return self.email_type.text_name
90 @property
91 def html_path(self) -> Path:
92 return self.email_type.html_path
94 @property
95 def text_path(self) -> Path:
96 return self.email_type.text_path