Added {favorite} template, partial fix for #289

This commit is contained in:
Rhet Turnbull
2021-04-11 19:45:50 -07:00
parent 958f8c343a
commit d9f24307ac
5 changed files with 27 additions and 0 deletions

View File

@@ -962,6 +962,10 @@ Substitution Description
True/False value, use in format
'{edited?VALUE_IF_TRUE,VALUE_IF_FALSE}'
{favorite} Photo has been marked as favorite?; True/False
value, use in format
'{favorite?VALUE_IF_TRUE,VALUE_IF_FALSE}'
{created.date} Photo's creation date in ISO format, e.g.
'2020-03-22'
@@ -2705,6 +2709,7 @@ The following template field substitutions are availabe for use with `PhotoInfo.
|{photo_or_video}|'photo' or 'video' depending on what type the image is. To customize, use default value as in '{photo_or_video,photo=fotos;video=videos}'|
|{hdr}|Photo is HDR?; True/False value, use in format '{hdr?VALUE_IF_TRUE,VALUE_IF_FALSE}'|
|{edited}|Photo has been edited (has adjustments)?; True/False value, use in format '{edited?VALUE_IF_TRUE,VALUE_IF_FALSE}'|
|{favorite}|Photo has been marked as favorite?; True/False value, use in format '{favorite?VALUE_IF_TRUE,VALUE_IF_FALSE}'|
|{created.date}|Photo's creation date in ISO format, e.g. '2020-03-22'|
|{created.year}|4-digit year of photo creation time|
|{created.yy}|2-digit year of photo creation time|

Binary file not shown.

View File

@@ -48,6 +48,7 @@ TEMPLATE_SUBSTITUTIONS = {
"{photo_or_video}": "'photo' or 'video' depending on what type the image is. To customize, use default value as in '{photo_or_video,photo=fotos;video=videos}'",
"{hdr}": "Photo is HDR?; True/False value, use in format '{hdr?VALUE_IF_TRUE,VALUE_IF_FALSE}'",
"{edited}": "Photo has been edited (has adjustments)?; True/False value, use in format '{edited?VALUE_IF_TRUE,VALUE_IF_FALSE}'",
"{favorite}": "Photo has been marked as favorite?; True/False value, use in format '{favorite?VALUE_IF_TRUE,VALUE_IF_FALSE}'",
"{created.date}": "Photo's creation date in ISO format, e.g. '2020-03-22'",
"{created.year}": "4-digit year of photo creation time",
"{created.yy}": "2-digit year of photo creation time",
@@ -539,6 +540,8 @@ class PhotoTemplate:
value = "hdr" if self.photo.hdr else None
elif field == "edited":
value = "edited" if self.photo.hasadjustments else None
elif field == "favorite":
value = "favorite" if self.photo.favorite else None
elif field == "created.date":
value = DateTimeFormatter(self.photo.date).date
elif field == "created.year":

View File

@@ -23,6 +23,14 @@ class PhotoInfoMock(PhotoInfo):
else self._photo.hdr
)
@property
def favorite(self):
return (
self._mock_favorite
if getattr(self, "_mock_favorite", None) is not None
else self._photo.favorite
)
@property
def hasadjustments(self):
return (

View File

@@ -28,6 +28,7 @@ UUID_DICT = {
"mojave_album_1": "15uNd7%8RguTEgNPKHfTWw",
"date_modified": "A9B73E13-A6F2-4915-8D67-7213B39BAE9F",
"date_not_modified": "128FB4C6-0B16-4E7D-9108-FB2E90DA1546",
"favorite": "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51",
}
UUID_MEDIA_TYPE = {
@@ -176,6 +177,8 @@ TEMPLATE_VALUES = {
"{exif.lens_model}": "iPhone 6s back camera 4.15mm f/2.2",
"{album?{folder_album},{created.year}/{created.mm}}": "2020/02",
"{title?Title is '{title} - {descr}',No Title}": "Title is 'Glen Ord - Jack Rose Dining Saloon'",
"{favorite}": "_",
"{favorite?FAV,NOTFAV}": "NOTFAV",
}
@@ -831,6 +834,14 @@ def test_edited(photosdb):
assert rendered == ["edited"]
def test_favorite(photosdb):
""" Test favorite"""
photo = photosdb.get_photo(UUID_MULTI_KEYWORDS)
photomock = PhotoInfoMock(photo, favorite=True)
rendered, _ = photomock.render_template("{favorite}")
assert rendered == ["favorite"]
def test_nested_template_bool(photosdb):
photo = photosdb.get_photo(UUID_MULTI_KEYWORDS)
template = "{hdr?{edited?HDR_EDITED,HDR_NOT_EDITED},{edited?NOT_HDR_EDITED,NOT_HDR_NOT_EDITED}}"