Skip to content

Commit

Permalink
Update openverse-attribution with new features and improvements (#4250
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dhruvkb authored May 6, 2024
1 parent 12e7c87 commit 1736a13
Show file tree
Hide file tree
Showing 15 changed files with 1,097 additions and 257 deletions.
7 changes: 4 additions & 3 deletions api/api/admin/media_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ def _get_media_obj_data(self, obj):
additional_data = {
"other_reports": self.get_other_reports(obj),
"media_obj": obj.media_obj,
"license": License(obj.media_obj.license).name(
obj.media_obj.license_version
),
"license": License(
obj.media_obj.license,
obj.media_obj.license_version,
).full_name,
"tags": tags_by_provider,
"description": obj.media_obj.meta_data.get("description", ""),
}
Expand Down
18 changes: 9 additions & 9 deletions api/api/models/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,25 @@ def license_url(self) -> str | None:
if self.meta_data and (url := self.meta_data.get("license_url")):
return url
try:
lic = License(self.license.lower())
return License(self.license.lower(), self.license_version).url
except ValueError:
return None
return lic.url(self.license_version)

@property
def attribution(self) -> str | None:
"""Legally valid attribution for the media item in plain-text English."""

try:
lic = License(self.license)
return License(
self.license.lower(),
self.license_version,
).get_attribution_text(
self.title,
self.creator,
self.license_url,
)
except ValueError:
return None
return lic.attribution(
self.title,
self.creator,
self.license_version,
self.license_url,
)

class Meta:
"""
Expand Down
4 changes: 2 additions & 2 deletions api/api/serializers/media_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ def to_representation(self, *args, **kwargs):

if output.get("license_url") is None:
try:
lic = License(output["license"])
output["license_url"] = lic.url(output["license_version"])
lic = License(output["license"], output["license_version"])
output["license_url"] = lic.url
except ValueError:
pass

Expand Down
7 changes: 3 additions & 4 deletions api/api/utils/watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _print_attribution_on_image(img: Image.Image, image_info):
"""

try:
lic = License(image_info["license"])
lic = License(image_info["license"], image_info["license_version"])
except ValueError:
return img

Expand All @@ -195,11 +195,10 @@ def _print_attribution_on_image(img: Image.Image, image_info):

font = ImageFont.truetype(_get_font_path(), size=font_size)

text = lic.attribution(
text = lic.get_attribution_text(
image_info["title"],
image_info["creator"],
image_info["license_version"],
False,
url=False,
)
text = _fit_in_width(text, font, new_width)
attribution_height = _get_attribution_height(text, font)
Expand Down
Loading

0 comments on commit 1736a13

Please sign in to comment.