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] util/fields: update default when converting to html #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions src/util/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,21 @@ def convert_field_to_html(cr, model, field, skip_inherit=()):
""",
[field, model],
)

# Update ir.default
if table_exists(cr, "ir_default"):
json_value_html = pg_text2html("json_value")
cr.execute(
"""
UPDATE ir_default AS d
SET json_value = {}
FROM ir_model_fields AS imf
WHERE imf.name = %s
AND imf.model = %s
AND imf.id = d.field_id
""".format(json_value_html),
[field, model],
)
for inh in for_each_inherit(cr, model, skip_inherit):
convert_field_to_html(cr, inh.model, field, skip_inherit=skip_inherit)

Expand Down
19 changes: 11 additions & 8 deletions src/util/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,17 @@ def pg_text2html(s, wrap="p"):
CASE WHEN TRIM(COALESCE({src}, '')) ~ '^<.+</\w+>$' THEN {src}
ELSE CONCAT(
'{opening_tag}',
replace(REGEXP_REPLACE({esc},
-- regex from https://blog.codinghorror.com/the-problem-with-urls/
-- double the %% to allow this code chunk to be used in parameterized queries
'https?://[-A-Za-z0-9+&@#/%%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%%=~_()|]',
'<a href="\&" target="_blank" rel="noreferrer noopener">\&</a>',
'g'),
E'\n',
'<br>'),
replace(
replace(REGEXP_REPLACE({esc},
-- regex from https://blog.codinghorror.com/the-problem-with-urls/
-- double the %% to allow this code chunk to be used in parameterized queries
'https?://[-A-Za-z0-9+&@#/%%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%%=~_()|]',
'<a href="\&" target="_blank" rel="noreferrer noopener">\&</a>',
'g'),
E'\\n',
'<br>'),
E'\\t',
'&Tab;'),
'{closing_tag}')
END
""".format(
Expand Down