Skip to content

Commit e89f5bd

Browse files
committed
Refactor position_in_template to look at template property directly
Don’t need the wrapper method on the `EmailPreviewTemplate` object now that placeholders are an `InsensitiveSet` so we can do `placeholders.index` directly
1 parent 4aefb79 commit e89f5bd

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

app/models/template_email_file.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import math
12
import mimetypes
23
import uuid
4+
from contextlib import suppress
35
from datetime import UTC, datetime, timedelta
46
from typing import Any
57

@@ -112,7 +114,9 @@ def file_contents(self):
112114

113115
@property
114116
def position_in_template(self):
115-
return self.template.index_of_placeholder(self.filename)
117+
with suppress(KeyError):
118+
return self.template.all_placeholders.index(self.filename)
119+
return math.inf
116120

117121

118122
class TemplateEmailFiles(SerialisedModelCollection):

app/utils/templates.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import json
2-
import math
3-
from contextlib import suppress
42
from typing import Any
53

64
from flask import current_app, render_template, url_for
@@ -315,11 +313,6 @@ def all_placeholders(self):
315313
def placeholders(self):
316314
return OrderedSet([placeholder for placeholder in self.all_placeholders if placeholder not in self.filenames])
317315

318-
def index_of_placeholder(self, placeholder):
319-
with suppress(KeyError):
320-
return self.all_placeholders.index(placeholder)
321-
return math.inf
322-
323316

324317
class LetterAttachment(JSONModel):
325318
id: Any

0 commit comments

Comments
 (0)