-
Notifications
You must be signed in to change notification settings - Fork 0
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
[4981][ADD] attachment_image_resize #49
base: 15.0
Are you sure you want to change the base?
Conversation
9a3202c
to
14a83c5
Compare
b317a75
to
b46bb2a
Compare
@yostashiro @kanda999 Please review this PR. |
b46bb2a
to
832a42d
Compare
ICP = self.env["ir.config_parameter"].sudo().get_param | ||
max_resolution = self.env.company.attachment_image_max_resolution or "1920x1920" | ||
max_width, max_height = map(int, max_resolution.split("x")) | ||
quality = int(ICP("base.image_autoresize_quality", 80)) |
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.
ICP = self.env["ir.config_parameter"].sudo().get_param | |
max_resolution = self.env.company.attachment_image_max_resolution or "1920x1920" | |
max_width, max_height = map(int, max_resolution.split("x")) | |
quality = int(ICP("base.image_autoresize_quality", 80)) | |
max_resolution = self.env.company.attachment_image_max_resolution or "1920x1920" | |
max_width, max_height = map(int, max_resolution.split("x")) | |
ICP = self.env["ir.config_parameter"].sudo().get_param | |
quality = int(ICP("base.image_autoresize_quality", 80)) |
return datas | ||
|
||
@api.model | ||
def _cron_resize_attachment_image(self, limit): |
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.
Move this method to the bottom.
and mimetype in IMAGE_TYPES | ||
): | ||
# Resize raw binary or Base64 data | ||
if "raw" in values and values["raw"]: |
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.
if "raw" in values and values["raw"]: | |
if values.get("raw"): |
# Resize raw binary or Base64 data | ||
if "raw" in values and values["raw"]: | ||
values["raw"] = self._resize_image(values["raw"], is_raw=True) | ||
elif "datas" in values and values["datas"]: |
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.
elif "datas" in values and values["datas"]: | |
elif values.get("datas"): |
values["raw"] = self._resize_image(values["raw"], is_raw=True) | ||
elif "datas" in values and values["datas"]: | ||
values["datas"] = self._resize_image(values["datas"], is_raw=False) | ||
return super(IrAttachment, self).create(vals_list) |
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.
return super(IrAttachment, self).create(vals_list) | |
return super().create(vals_list) |
attachment_image_max_resolution = fields.Char( | ||
help="This resolution will be applied to the resizing of images" | ||
" for the specified models." | ||
) |
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.
Another approach is to have this in ir.model, which makes the size control more granular.
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.
It makes sense to me.
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.
As we talked, we will use current approach to avoid same configuration for each model and there may be rare case to use each resolution for each model.
attachment_image_resize_models = fields.Char( | ||
help="When users attach images to these models, the images will be resized " | ||
"based on the maximum resolution specified for attachments." | ||
) |
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.
If we keep this field, help text should contain an example of how it should be populated.
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.
I added the placeholder for this.
): | ||
# Resize raw binary or Base64 data | ||
if "raw" in values and values["raw"]: | ||
values["raw"] = self._resize_image(values["raw"], is_raw=True) |
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.
values["raw"] = self._resize_image(values["raw"], is_raw=True) | |
values["raw"] = self._resize_image(values["raw"], is_raw=True) | |
values["resize_done"] = True |
if "raw" in values and values["raw"]: | ||
values["raw"] = self._resize_image(values["raw"], is_raw=True) | ||
elif "datas" in values and values["datas"]: | ||
values["datas"] = self._resize_image(values["datas"], is_raw=False) |
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.
values["datas"] = self._resize_image(values["datas"], is_raw=False) | |
values["datas"] = self._resize_image(values["datas"], is_raw=False) | |
values["resize_done"] = True |
if len(attachments) == limit: | ||
self.env.ref( | ||
"attachment_image_resize.resize_attachment_image" | ||
)._trigger() |
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.
What is the reason we are reviving this approach?
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.
I revived this because this module will be OCA module and I don't want to make user runs and check there is still attachment that haven't resized and rerun.
4981