-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement updating of picture metadata on publish #2594
Conversation
superdesk/default_settings.py
Outdated
|
||
#: Map picture item data to photo metadata | ||
#: | ||
#: .. versionadded:: 2.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be 2.8
?
setup.py
Outdated
@@ -67,6 +67,7 @@ | |||
"itsdangerous>=1.1,<2.0", | |||
"pymemcache>=4.0,<4.1", | |||
"xmlsec>=1.3.13,<1.3.15", | |||
"pyexiv2>=2.12.0,<2.13", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using this library may be troublesome on devices with ARM CPUs (LeoHsiao1/pyexiv2#108) such as the Apple M1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep true, haven't really seen any alternatives, and as this won't be used by default might make it import the library only when calling those methods so it won't break anything by default
@@ -914,6 +918,31 @@ def _inherit_publish_schedule(self, original, updates, associated_item): | |||
associated_item[PUBLISH_SCHEDULE] = publish_schedule | |||
associated_item[SCHEDULE_SETTINGS] = schedule_settings | |||
|
|||
def _update_picture_metadata(self, updates, original, updated): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a personal preference.
To avoid nested if statements, and along the idea of fail fast / return early
, this method could be re-written as:
def _update_picture_metadata(self, updates, original, updated):
renditions = updated.get("renditions") or {}
mapping = app.config.get("PHOTO_METADATA_MAPPING")
if not mapping or not renditions:
return
try:
media_id = renditions["original"]["media"]
except (KeyError, TypeError):
return
if not media_id:
return
picture = app.media.get(media_id)
binary = picture.read()
metadata = get_metadata_from_item(updated, mapping)
updated_binary = write_metadata(binary, metadata)
if updated_binary == binary:
return
updated_media_id = app.media.put(
updated_binary, content_type=picture.content_type, filename=picture.filename
)
updates.setdefault("renditions", deepcopy(renditions))["original"].update(
{
"media": updated_media_id,
"href": app.media.url_for_media(updated_media_id, picture.content_type),
}
)
updated["renditions"] = updates["renditions"]
SDCP-737