Skip to content
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

[IMP]convert_field_to_html: manage translated fields #384

Merged
Merged
Changes from 1 commit
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
22 changes: 21 additions & 1 deletion openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import inspect
import json
import logging as _logging_module
import os
import sys
Expand Down Expand Up @@ -2461,12 +2462,31 @@ def default_func(cr, pool, rec_id, vals):
)


def convert_field_to_html(cr, table, field_name, html_field_name, verbose=True):
def convert_field_to_html(
cr, table, field_name, html_field_name, verbose=True, translate=False
):
"""
Convert field value to HTML value.

.. versionadded:: 7.0
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add empty lines inside a method, please (and the same for the next one)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty lines still exist

# For translated fields
if translate:
if version_info[0] < 16:
do_raise("Translatable fields are only managed in version 16.0 or higher")
cr.execute(f"SELECT id, {field_name} FROM {table};") # pylint: disable=E8103
for row in cr.fetchall():
record_id, translations = row
for lang in translations:
translations[lang] = plaintext2html(translations[lang])
query = f"update {table} set {html_field_name} = %s::jsonb where id = %s"
if verbose:
logged_query(cr, query, (json.dumps(translations), record_id))
else:
cr.execute(query, translations, record_id)
pedrobaeza marked this conversation as resolved.
Show resolved Hide resolved
return

if version_info[0] < 7:
logger.error(
"You cannot use this method in an OpenUpgrade version prior to 7.0."
Expand Down
Loading