Added {edited_version} template field, closes #420
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
""" version info """
|
||||
|
||||
__version__ = "0.42.11"
|
||||
__version__ = "0.42.12"
|
||||
|
||||
@@ -2317,7 +2317,7 @@ def export_photo(
|
||||
if export_edited and photo.hasadjustments:
|
||||
# if export-edited, also export the edited version
|
||||
edited_filenames = get_filenames_from_template(
|
||||
photo, filename_template, original_name, strip=strip
|
||||
photo, filename_template, original_name, strip=strip, edited=True
|
||||
)
|
||||
for edited_filename in edited_filenames:
|
||||
edited_filename = pathlib.Path(edited_filename)
|
||||
@@ -2461,7 +2461,7 @@ def export_photo_with_template(
|
||||
results = ExportResults()
|
||||
|
||||
dest_paths = get_dirnames_from_template(
|
||||
photo, directory, export_by_date, dest, dry_run, strip=strip
|
||||
photo, directory, export_by_date, dest, dry_run, strip=strip, edited=edited
|
||||
)
|
||||
|
||||
# export the photo to each path in dest_paths
|
||||
@@ -2602,13 +2602,17 @@ def export_photo_with_template(
|
||||
return results
|
||||
|
||||
|
||||
def get_filenames_from_template(photo, filename_template, original_name, strip=False):
|
||||
def get_filenames_from_template(
|
||||
photo, filename_template, original_name, strip=False, edited=False
|
||||
):
|
||||
"""get list of export filenames for a photo
|
||||
|
||||
Args:
|
||||
photo: a PhotoInfo instance
|
||||
filename_template: a PhotoTemplate template string, may be None
|
||||
original_name: boolean; if True, use photo's original filename instead of current filename
|
||||
strip: if True, strips leading/trailing white space from resulting template
|
||||
edited: if True, sets {edited_version} field to True, otherwise it gets set to False; set if you want template evaluated for edited version
|
||||
|
||||
Returns:
|
||||
list of filenames
|
||||
@@ -2620,7 +2624,11 @@ def get_filenames_from_template(photo, filename_template, original_name, strip=F
|
||||
photo_ext = pathlib.Path(photo.original_filename).suffix
|
||||
try:
|
||||
filenames, unmatched = photo.render_template(
|
||||
filename_template, path_sep="_", filename=True, strip=strip
|
||||
filename_template,
|
||||
path_sep="_",
|
||||
filename=True,
|
||||
strip=strip,
|
||||
edited=edited,
|
||||
)
|
||||
except ValueError as e:
|
||||
raise click.BadOptionUsage(
|
||||
@@ -2644,7 +2652,7 @@ def get_filenames_from_template(photo, filename_template, original_name, strip=F
|
||||
|
||||
|
||||
def get_dirnames_from_template(
|
||||
photo, directory, export_by_date, dest, dry_run, strip=False
|
||||
photo, directory, export_by_date, dest, dry_run, strip=False, edited=False
|
||||
):
|
||||
"""get list of directories to export a photo into, creates directories if they don't exist
|
||||
|
||||
@@ -2654,6 +2662,8 @@ def get_dirnames_from_template(
|
||||
export_by_date: boolean; if True, creates output directories in form YYYY-MM-DD
|
||||
dest: top-level destination directory
|
||||
dry_run: boolean; if True, runs in dry-run mode and does not create output directories
|
||||
strip: if True, strips leading/trailing white space from resulting template
|
||||
edited: if True, sets {edited_version} field to True, otherwise it gets set to False; set if you want template evaluated for edited version
|
||||
|
||||
Returns:
|
||||
list of export directories
|
||||
@@ -2674,7 +2684,7 @@ def get_dirnames_from_template(
|
||||
# got a directory template, render it and check results are valid
|
||||
try:
|
||||
dirnames, unmatched = photo.render_template(
|
||||
directory, dirname=True, strip=strip
|
||||
directory, dirname=True, strip=strip, edited=edited
|
||||
)
|
||||
except ValueError as e:
|
||||
raise click.BadOptionUsage(
|
||||
|
||||
@@ -937,6 +937,7 @@ class PhotoInfo:
|
||||
filename=False,
|
||||
dirname=False,
|
||||
strip=False,
|
||||
edited=False,
|
||||
):
|
||||
"""Renders a template string for PhotoInfo instance using PhotoTemplate
|
||||
|
||||
@@ -952,6 +953,7 @@ class PhotoInfo:
|
||||
filename: if True, template output will be sanitized to produce valid file name
|
||||
dirname: if True, template output will be sanitized to produce valid directory name
|
||||
strip: if True, strips leading/trailing white space from resulting template
|
||||
edited: if True, sets {edited_version} field to True, otherwise it gets set to False; set if you want template evaluated for edited version
|
||||
|
||||
Returns:
|
||||
([rendered_strings], [unmatched]): tuple of list of rendered strings and list of unmatched template values
|
||||
@@ -966,6 +968,7 @@ class PhotoInfo:
|
||||
filename=filename,
|
||||
dirname=dirname,
|
||||
strip=strip,
|
||||
edited_version=edited,
|
||||
)
|
||||
|
||||
@property
|
||||
|
||||
@@ -48,7 +48,8 @@ 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}'",
|
||||
"{edited}": "True if photo has been edited (has adjustments), otherwise False; use in format '{edited?VALUE_IF_TRUE,VALUE_IF_FALSE}'",
|
||||
"{edited_version}": "True if template is being rendered for the edited version of a photo, otherwise 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",
|
||||
@@ -257,6 +258,9 @@ class PhotoTemplate:
|
||||
# get parser singleton
|
||||
self.parser = PhotoTemplateParser()
|
||||
|
||||
# should {edited_version} render True?
|
||||
self.edited_version = False
|
||||
|
||||
def render(
|
||||
self,
|
||||
template,
|
||||
@@ -267,6 +271,7 @@ class PhotoTemplate:
|
||||
filename=False,
|
||||
dirname=False,
|
||||
strip=False,
|
||||
edited_version=False,
|
||||
):
|
||||
""" Render a filename or directory template
|
||||
|
||||
@@ -281,6 +286,7 @@ class PhotoTemplate:
|
||||
filename: if True, template output will be sanitized to produce valid file name
|
||||
dirname: if True, template output will be sanitized to produce valid directory name
|
||||
strip: if True, strips leading/trailing whitespace from rendered templates
|
||||
edited_version: set to True if you want {edited_version} to resolve to True (e.g. exporting edited version of photo)
|
||||
|
||||
Returns:
|
||||
([rendered_strings], [unmatched]): tuple of list of rendered strings and list of unmatched template values
|
||||
@@ -304,6 +310,8 @@ class PhotoTemplate:
|
||||
# empty string
|
||||
return [], []
|
||||
|
||||
self.edited_version = edited_version
|
||||
|
||||
return self._render_statement(
|
||||
model,
|
||||
none_str=none_str,
|
||||
@@ -669,6 +677,8 @@ class PhotoTemplate:
|
||||
value = "hdr" if self.photo.hdr else None
|
||||
elif field == "edited":
|
||||
value = "edited" if self.photo.hasadjustments else None
|
||||
elif field == "edited_version":
|
||||
value = "edited_version" if self.edited_version else None
|
||||
elif field == "favorite":
|
||||
value = "favorite" if self.photo.favorite else None
|
||||
elif field == "created.date":
|
||||
|
||||
Reference in New Issue
Block a user