88from notifications_utils .base64_uuid import uuid_to_base64
99from notifications_utils .s3 import s3download
1010from notifications_utils .serialised_model import SerialisedModelCollection
11+ from notifications_utils .template import Template
1112
1213from app .models import JSONModel
1314from app .s3_client .s3_template_email_file_upload_client import upload_template_email_file_to_s3
@@ -20,7 +21,7 @@ def _get_file_location(file_id: uuid, service_id: uuid) -> str:
2021class TemplateEmailFile (JSONModel ):
2122 id : Any
2223 service_id : Any
23- template_id : Any
24+ template : Any
2425 filename : str
2526 link_text : str
2627 retention_period : int
@@ -57,15 +58,16 @@ def update(self, **kwargs):
5758 } | kwargs
5859
5960 return template_email_file_client .update_file (
60- service_id = self .service_id , template_id = self .template_id , file_id = self .id , ** data
61+ service_id = self .service_id , template_id = self .template . id , file_id = self .id , ** data
6162 )
6263
6364 @classmethod
64- def get_by_id (cls , template_email_file_id : str , service_id : str , template_id : str ):
65+ def get_by_id (cls , template_email_file_id : str , service_id : str , template : Template ):
6566 from app import template_email_file_client
6667
67- template_email_file = template_email_file_client .get_file_by_id (template_email_file_id , service_id , template_id )
68+ template_email_file = template_email_file_client .get_file_by_id (template_email_file_id , service_id , template . id )
6869 template_email_file ["data" ]["service_id" ] = service_id
70+ template_email_file ["data" ]["template" ] = template
6971 return cls (template_email_file .get ("data" ))
7072
7173 @property
@@ -74,7 +76,7 @@ def link_as_markdown(self):
7476 "main.document_download_landing" ,
7577 service_id = self .service_id ,
7678 document_id = self .id ,
77- key = uuid_to_base64 (self .template_id ),
79+ key = uuid_to_base64 (self .template . id ),
7880 _external = True ,
7981 )
8082 if self .link_text :
@@ -116,7 +118,7 @@ def __init__(self, template):
116118 from app import current_service
117119
118120 self .service_id = current_service .id
119- self .template_id = template . id
121+ self .template = template
120122
121123 email_files = template ._template .get ("email_files" , [])
122124 super ().__init__ (email_files )
@@ -125,7 +127,7 @@ def __init__(self, template):
125127 self .items = sorted (email_files , key = lambda _ : next (position_in_template ))
126128
127129 def __getitem__ (self , index ):
128- return self .model (self .items [index ] | {"service_id" : self .service_id , "template_id " : self .template_id })
130+ return self .model (self .items [index ] | {"service_id" : self .service_id , "template " : self .template })
129131
130132 @property
131133 def as_personalisation (self ):
0 commit comments