Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sbc_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# pylint: disable=C8101
{
"name": "Sponsor to Participant communication",
"version": "18.0.1.0.6",
"version": "18.0.1.0.7",
"category": "Compassion",
"summary": "SBC - Supporter to Participant Communication",
"sequence": 150,
Expand Down
26 changes: 26 additions & 0 deletions sbc_compassion/migrations/18.0.1.0.7/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging

from openupgradelib import openupgrade

_logger = logging.getLogger(__name__)


@openupgrade.migrate()
def migrate(env, version):
# T3616: pages added to hold overflowing translations got a crop of the
# letter image as background. They are not part of the scanned letter.
pages = env["correspondence.page"].search(
[
("original_page_url", "=", False),
"|",
("cloudinary_original_page_url", "!=", False),
("cloudinary_final_page_url", "!=", False),
]
)
pages = pages.filtered(
lambda page: page.correspondence_id.page_ids.filtered("original_page_url")
)
_logger.info("Remove the letter image from %s added pages", len(pages))
pages.write(
{"cloudinary_original_page_url": False, "cloudinary_final_page_url": False}
)
12 changes: 8 additions & 4 deletions sbc_compassion/models/correspondence_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,20 @@ def _get_cloudinary_url(self, cloudinary_url):
"""
Returns the cloudinary url with the correct crop so that the page is displayed
"""
if not cloudinary_url:
# Pages added to hold overflowing text are not part of the letter image
letter_pages = self.correspondence_id.page_ids
scanned_pages = letter_pages.filtered("original_page_url") or letter_pages
if not cloudinary_url or self not in scanned_pages:
return False
scanned_index = list(scanned_pages).index(self) + 1
if cloudinary_url.endswith("p1.jpg"):
return cloudinary_url.replace("p1.jpg", f"p{str(self.page_index)}.jpg")
return cloudinary_url.replace("p1.jpg", f"p{scanned_index}.jpg")
response = requests.get(cloudinary_url, timeout=3)
if not response.ok:
return False
width, total_height = Image.open(BytesIO(response.content)).size
height = total_height // len(self.correspondence_id.page_ids)
y_start = (self.page_index - 1) * height
height = total_height // len(scanned_pages)
y_start = (scanned_index - 1) * height
crop_operator = f"c_crop,h_{height},w_{width},x_0,y_{y_start}"
url_parts = cloudinary_url.split("upload/")
return f"{url_parts[0]}upload/{crop_operator}/{url_parts[1]}"
Expand Down
Loading