odoo-addon-search-engine-image-thumbnail


Nameodoo-addon-search-engine-image-thumbnail JSON
Version 16.0.1.0.7 PyPI version JSON
download
home_pagehttps://github.com/OCA/search-engine
SummaryGenerate thumbnails for binded record
upload_time2024-10-11 08:22:23
maintainerNone
docs_urlNone
authorACSONE SA/NV,Odoo Community Association (OCA)
requires_python>=3.10
licenseAGPL-3
keywords
VCS
bugtrack_url
requirements elasticsearch pydantic requests typing-extensions unidecode
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ===================================
Search Engine Multi Image Thumbnail
===================================

.. 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! This file is generated by oca-gen-addon-readme !!
   !! changes will be overwritten.                   !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! source digest: sha256:2b3cfd55ee16e375d602f9abdc8ca8f4c4f705c79e9a75b5878005aa668ad16c
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
    :target: https://odoo-community.org/page/development-status
    :alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
    :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
    :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsearch--engine-lightgray.png?logo=github
    :target: https://github.com/OCA/search-engine/tree/16.0/search_engine_image_thumbnail
    :alt: OCA/search-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
    :target: https://translation.odoo-community.org/projects/search-engine-16-0/search-engine-16-0-search_engine_image_thumbnail
    :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
    :target: https://runboat.odoo-community.org/builds?repo=OCA/search-engine&target_branch=16.0
    :alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module is a technical module with the purpose of easing the export
of image thumbnails to a search engine index.

It extends the functionality of the ``connector_search_engine`` module
by adding specialized methods that can be used to get and generate
thumbnails from an image you want to index.

.. IMPORTANT::
   This is an alpha version, the data model and design can change at any time without warning.
   Only for development or testing purpose, do not use in production.
   `More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
   :local:

Use Cases / Context
===================

When you export images to an index, you may want to ensure that the
images are exported in a format and size that is suitable for the
application that will consume the index.

This module depends on the
`fs_image_thumdbnail <https://github.com/oca/storage/tree/16.0/fs_image_thumbnail>`__
module. This last one provides a method and a mixin used to generate
thumbnails from a ``FSImageValue`` object.

Configuration
=============

If you want to force the format of the generated thumbnail, you define a
a configuration parameter into Odoo with the key
``fs_image_thumbnail.resize_format`` and the value PNG or JPEG or GIF or
ICO. Otherwise, the format of the generated thumbnail will be the same
as the format of the original image.

Usage
=====

As specified, this module will not add any new features by itself once
installed. As a developer, you can depend on this module to benefit from
a set of specialized methods that can be used to get and generate
thumbnails from an image you want to index.

Behind the scenes, this module extend the ``se.indexable.recor`` model
by adding 2 new methods:

-  ``_get_or_create_thumbnails_for_multi_images``: This method is used
   to get or create thumbnails for a set of images.
-  ``_get_or_create_thumbnails_for_image``: This method is used to get
   or create thumbnails for a single image.

Thanks to these methods, you can easily generate thumbnails for images
stored into odoo through three different ways:

-  A relational field referencing record inheriting from
   ``fs.image.relation.mixin``.
-  An odoo's Image field.
-  An FSImage field.

The sizes of the thumbnails generated by these methods are configured
through the creation of a new record into the ``se.thumbnail.size``
model. This model allows you to define the size of thumbnails by search
engine backend, model and field. For example, you can define that you
want to generate thumbnails of size ``100x100`` for all the images
stored into the ``product.template`` model and the ``image`` field when
you export them to the ``opensearch_xyz`` backend. In this way, you can
easily define different thumbnail sizes for different search engine
backends, models and fields according to your needs.

Thumbnails are always retrieved and generated for one image and a
specific ``base_name``. The base name is used as a key to identify the
thumbnails from an image related to a usage and also as base name for
the file name of the thumbnails generated. By default, the ``base_name``
is computed from the display name of the record that contains the image
to ensure a good SEO. To avoid problems with special characters, the
``base_name`` is normalized before being used.

Here is an example of how to use these methods:

.. code:: python


   from odoo import models, fields
   from odoo.addons.fs_imeage.fields import FSImage


   class ProductImageRelation(models.Model):
       _name = "product.image.relation"
       _inherit = ["fs.image.relation.mixin"]

       name = fields.Char(required=True)
       product_id = fields.Many2one(
           "product.product",
           required=True,
           ondelete="cascade",
       )


   class ProductProduct(models.Model):
       _name = "product.product"
       _inherit = ["se.indexable.record", "product.product"]

       name = fields.Char(required=True)
       image = fields.Image(required=True)
       image_ids = fields.One2many(
           "product.image.relation",
           "product_id",
           string="Images",
       )
       fs_image = FSImage(required=True)



   # A creation is always done for a given se.index record.
   index = self.env["se.index"].browse(1)
   product = self.env["product.product"].browse(1)

   # Get or create thumbnails for a single image
   for (thumbnail_size, thumbnail) in product._get_or_create_thumbnails_for_image(
       index,
       field_name="image",
       ):
       # Do something with the thumbnail
       print(f"Thumbnail  for image with size {thumbnail_size.display_name} "
           "is available at url {thumbnail.image.url}")

   # Get or create thumbnails for a single image
   for (thumbnail_size, thumbnail) in product._get_or_create_thumbnails_for_image(
       index,
       field_name="fs_image",
       ):
       # Do something with the thumbnail
       print(f"Thumbnail for fs_image with size {thumbnail_size.display_name} "
           "is available at url {thumbnail.image.url}")


   # Get or create thumbnails for a set of images
   thumbnails_by_image = product._get_or_create_thumbnails_for_multi_images(
       index,
       field_name="image_ids",
       )

   for (image, thumbnails) in thumbnails_by_image.items():
       for (thumbnail_size, thumbnail) in thumbnails:
           # Do something with the thumbnail
           print(f"Thumbnail for image {image.name} with size "
               "{thumbnail_size.display_name} is available at url "
               "{thumbnail.image.url}")

Changelog
=========

16.0.1.0.5 (2024-04-10)
-----------------------

Bugfixes
^^^^^^^^

-  Add new config parameter on the search engine backend to allow the
   user to specify if the serialization of a record should fail if
   thumbnails are requested but no thumbnail sizes are defined for the
   model and field for which it' requested. Defaults to False (i.e.
   don't fail).
   (`#176 <https://github.com/OCA/search-engine/issues/176>`__)

16.0.1.0.4 (2024-04-09)
-----------------------

Bugfixes
^^^^^^^^

-  *Fixes image sizes lookups.*

   When serializing a record and generating thumbnails, the thumbnail
   sizes are looked up on the index. Prior to this change, only sizes
   defined for the model associated with the current index were looked
   up. This means that if you tried to serialize a nested record that
   had an image field that was defined on a different model, the
   thumbnail size was not found and an error was thrown. The lookup
   method takes now the record for which the thumbnail is being
   generated as an argument, so that the correct model can be used to
   look up the thumbnail size. You still need to define the thumbnail
   sizes for each model serialized in the index.

   *Fixes UI error when creating a new thumbnail size.*

   When creating a new record, the UI was throwing an error. This was
   due to the computations of the domain to apply to restrict the
   choices of the possible image fields. When the record is new, no
   model is set, so the domain for the field must be empty. This is now
   handled correctly.
   (`#174 <https://github.com/OCA/search-engine/issues/174>`__)

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/search-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/search-engine/issues/new?body=module:%20search_engine_image_thumbnail%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

-  Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu/)
-  Mohamed Alkobrosli alkobroslymohamed@gmail.com
   (https://www.kobros-tech.com/)

Other credits
-------------

The development of this module has been financially supported by:

-`Alcyon Belux <https://www.alcyonbelux.be/>`__

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
   :alt: Odoo Community Association
   :target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px
    :target: https://github.com/lmignon
    :alt: lmignon

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-lmignon| 

This module is part of the `OCA/search-engine <https://github.com/OCA/search-engine/tree/16.0/search_engine_image_thumbnail>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/OCA/search-engine",
    "name": "odoo-addon-search-engine-image-thumbnail",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "ACSONE SA/NV,Odoo Community Association (OCA)",
    "author_email": "support@odoo-community.org",
    "download_url": null,
    "platform": null,
    "description": "===================================\nSearch Engine Multi Image Thumbnail\n===================================\n\n.. \n   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n   !! This file is generated by oca-gen-addon-readme !!\n   !! changes will be overwritten.                   !!\n   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n   !! source digest: sha256:2b3cfd55ee16e375d602f9abdc8ca8f4c4f705c79e9a75b5878005aa668ad16c\n   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png\n    :target: https://odoo-community.org/page/development-status\n    :alt: Alpha\n.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png\n    :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html\n    :alt: License: AGPL-3\n.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsearch--engine-lightgray.png?logo=github\n    :target: https://github.com/OCA/search-engine/tree/16.0/search_engine_image_thumbnail\n    :alt: OCA/search-engine\n.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png\n    :target: https://translation.odoo-community.org/projects/search-engine-16-0/search-engine-16-0-search_engine_image_thumbnail\n    :alt: Translate me on Weblate\n.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png\n    :target: https://runboat.odoo-community.org/builds?repo=OCA/search-engine&target_branch=16.0\n    :alt: Try me on Runboat\n\n|badge1| |badge2| |badge3| |badge4| |badge5|\n\nThis module is a technical module with the purpose of easing the export\nof image thumbnails to a search engine index.\n\nIt extends the functionality of the ``connector_search_engine`` module\nby adding specialized methods that can be used to get and generate\nthumbnails from an image you want to index.\n\n.. IMPORTANT::\n   This is an alpha version, the data model and design can change at any time without warning.\n   Only for development or testing purpose, do not use in production.\n   `More details on development status <https://odoo-community.org/page/development-status>`_\n\n**Table of contents**\n\n.. contents::\n   :local:\n\nUse Cases / Context\n===================\n\nWhen you export images to an index, you may want to ensure that the\nimages are exported in a format and size that is suitable for the\napplication that will consume the index.\n\nThis module depends on the\n`fs_image_thumdbnail <https://github.com/oca/storage/tree/16.0/fs_image_thumbnail>`__\nmodule. This last one provides a method and a mixin used to generate\nthumbnails from a ``FSImageValue`` object.\n\nConfiguration\n=============\n\nIf you want to force the format of the generated thumbnail, you define a\na configuration parameter into Odoo with the key\n``fs_image_thumbnail.resize_format`` and the value PNG or JPEG or GIF or\nICO. Otherwise, the format of the generated thumbnail will be the same\nas the format of the original image.\n\nUsage\n=====\n\nAs specified, this module will not add any new features by itself once\ninstalled. As a developer, you can depend on this module to benefit from\na set of specialized methods that can be used to get and generate\nthumbnails from an image you want to index.\n\nBehind the scenes, this module extend the ``se.indexable.recor`` model\nby adding 2 new methods:\n\n-  ``_get_or_create_thumbnails_for_multi_images``: This method is used\n   to get or create thumbnails for a set of images.\n-  ``_get_or_create_thumbnails_for_image``: This method is used to get\n   or create thumbnails for a single image.\n\nThanks to these methods, you can easily generate thumbnails for images\nstored into odoo through three different ways:\n\n-  A relational field referencing record inheriting from\n   ``fs.image.relation.mixin``.\n-  An odoo's Image field.\n-  An FSImage field.\n\nThe sizes of the thumbnails generated by these methods are configured\nthrough the creation of a new record into the ``se.thumbnail.size``\nmodel. This model allows you to define the size of thumbnails by search\nengine backend, model and field. For example, you can define that you\nwant to generate thumbnails of size ``100x100`` for all the images\nstored into the ``product.template`` model and the ``image`` field when\nyou export them to the ``opensearch_xyz`` backend. In this way, you can\neasily define different thumbnail sizes for different search engine\nbackends, models and fields according to your needs.\n\nThumbnails are always retrieved and generated for one image and a\nspecific ``base_name``. The base name is used as a key to identify the\nthumbnails from an image related to a usage and also as base name for\nthe file name of the thumbnails generated. By default, the ``base_name``\nis computed from the display name of the record that contains the image\nto ensure a good SEO. To avoid problems with special characters, the\n``base_name`` is normalized before being used.\n\nHere is an example of how to use these methods:\n\n.. code:: python\n\n\n   from odoo import models, fields\n   from odoo.addons.fs_imeage.fields import FSImage\n\n\n   class ProductImageRelation(models.Model):\n       _name = \"product.image.relation\"\n       _inherit = [\"fs.image.relation.mixin\"]\n\n       name = fields.Char(required=True)\n       product_id = fields.Many2one(\n           \"product.product\",\n           required=True,\n           ondelete=\"cascade\",\n       )\n\n\n   class ProductProduct(models.Model):\n       _name = \"product.product\"\n       _inherit = [\"se.indexable.record\", \"product.product\"]\n\n       name = fields.Char(required=True)\n       image = fields.Image(required=True)\n       image_ids = fields.One2many(\n           \"product.image.relation\",\n           \"product_id\",\n           string=\"Images\",\n       )\n       fs_image = FSImage(required=True)\n\n\n\n   # A creation is always done for a given se.index record.\n   index = self.env[\"se.index\"].browse(1)\n   product = self.env[\"product.product\"].browse(1)\n\n   # Get or create thumbnails for a single image\n   for (thumbnail_size, thumbnail) in product._get_or_create_thumbnails_for_image(\n       index,\n       field_name=\"image\",\n       ):\n       # Do something with the thumbnail\n       print(f\"Thumbnail  for image with size {thumbnail_size.display_name} \"\n           \"is available at url {thumbnail.image.url}\")\n\n   # Get or create thumbnails for a single image\n   for (thumbnail_size, thumbnail) in product._get_or_create_thumbnails_for_image(\n       index,\n       field_name=\"fs_image\",\n       ):\n       # Do something with the thumbnail\n       print(f\"Thumbnail for fs_image with size {thumbnail_size.display_name} \"\n           \"is available at url {thumbnail.image.url}\")\n\n\n   # Get or create thumbnails for a set of images\n   thumbnails_by_image = product._get_or_create_thumbnails_for_multi_images(\n       index,\n       field_name=\"image_ids\",\n       )\n\n   for (image, thumbnails) in thumbnails_by_image.items():\n       for (thumbnail_size, thumbnail) in thumbnails:\n           # Do something with the thumbnail\n           print(f\"Thumbnail for image {image.name} with size \"\n               \"{thumbnail_size.display_name} is available at url \"\n               \"{thumbnail.image.url}\")\n\nChangelog\n=========\n\n16.0.1.0.5 (2024-04-10)\n-----------------------\n\nBugfixes\n^^^^^^^^\n\n-  Add new config parameter on the search engine backend to allow the\n   user to specify if the serialization of a record should fail if\n   thumbnails are requested but no thumbnail sizes are defined for the\n   model and field for which it' requested. Defaults to False (i.e.\n   don't fail).\n   (`#176 <https://github.com/OCA/search-engine/issues/176>`__)\n\n16.0.1.0.4 (2024-04-09)\n-----------------------\n\nBugfixes\n^^^^^^^^\n\n-  *Fixes image sizes lookups.*\n\n   When serializing a record and generating thumbnails, the thumbnail\n   sizes are looked up on the index. Prior to this change, only sizes\n   defined for the model associated with the current index were looked\n   up. This means that if you tried to serialize a nested record that\n   had an image field that was defined on a different model, the\n   thumbnail size was not found and an error was thrown. The lookup\n   method takes now the record for which the thumbnail is being\n   generated as an argument, so that the correct model can be used to\n   look up the thumbnail size. You still need to define the thumbnail\n   sizes for each model serialized in the index.\n\n   *Fixes UI error when creating a new thumbnail size.*\n\n   When creating a new record, the UI was throwing an error. This was\n   due to the computations of the domain to apply to restrict the\n   choices of the possible image fields. When the record is new, no\n   model is set, so the domain for the field must be empty. This is now\n   handled correctly.\n   (`#174 <https://github.com/OCA/search-engine/issues/174>`__)\n\nBug Tracker\n===========\n\nBugs are tracked on `GitHub Issues <https://github.com/OCA/search-engine/issues>`_.\nIn case of trouble, please check there if your issue has already been reported.\nIf you spotted it first, help us to smash it by providing a detailed and welcomed\n`feedback <https://github.com/OCA/search-engine/issues/new?body=module:%20search_engine_image_thumbnail%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.\n\nDo not contact contributors directly about support or help with technical issues.\n\nCredits\n=======\n\nAuthors\n-------\n\n* ACSONE SA/NV\n\nContributors\n------------\n\n-  Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu/)\n-  Mohamed Alkobrosli alkobroslymohamed@gmail.com\n   (https://www.kobros-tech.com/)\n\nOther credits\n-------------\n\nThe development of this module has been financially supported by:\n\n-`Alcyon Belux <https://www.alcyonbelux.be/>`__\n\nMaintainers\n-----------\n\nThis module is maintained by the OCA.\n\n.. image:: https://odoo-community.org/logo.png\n   :alt: Odoo Community Association\n   :target: https://odoo-community.org\n\nOCA, or the Odoo Community Association, is a nonprofit organization whose\nmission is to support the collaborative development of Odoo features and\npromote its widespread use.\n\n.. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px\n    :target: https://github.com/lmignon\n    :alt: lmignon\n\nCurrent `maintainer <https://odoo-community.org/page/maintainer-role>`__:\n\n|maintainer-lmignon| \n\nThis module is part of the `OCA/search-engine <https://github.com/OCA/search-engine/tree/16.0/search_engine_image_thumbnail>`_ project on GitHub.\n\nYou are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.\n",
    "bugtrack_url": null,
    "license": "AGPL-3",
    "summary": "Generate thumbnails for binded record",
    "version": "16.0.1.0.7",
    "project_urls": {
        "Homepage": "https://github.com/OCA/search-engine"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5edf8e4b0447875c73c68445a0aa131aa01ce65b05bbd80fb040438dd050145d",
                "md5": "76e6ed9e4c8a4e4e5fe49453a7389949",
                "sha256": "24609c101f5e70902eb4ab90f21621c4b8f0910d36c8b4c5ea2ee9324544fd71"
            },
            "downloads": -1,
            "filename": "odoo_addon_search_engine_image_thumbnail-16.0.1.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "76e6ed9e4c8a4e4e5fe49453a7389949",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 52286,
            "upload_time": "2024-10-11T08:22:23",
            "upload_time_iso_8601": "2024-10-11T08:22:23.862802Z",
            "url": "https://files.pythonhosted.org/packages/5e/df/8e4b0447875c73c68445a0aa131aa01ce65b05bbd80fb040438dd050145d/odoo_addon_search_engine_image_thumbnail-16.0.1.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-11 08:22:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "OCA",
    "github_project": "search-engine",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "elasticsearch",
            "specs": [
                [
                    "<=",
                    "7.13.4"
                ],
                [
                    ">=",
                    "7.0.0"
                ]
            ]
        },
        {
            "name": "pydantic",
            "specs": []
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "typing-extensions",
            "specs": []
        },
        {
            "name": "unidecode",
            "specs": []
        }
    ],
    "lcname": "odoo-addon-search-engine-image-thumbnail"
}
        
Elapsed time: 1.83921s