Skip to content

Commit 7681fac

Browse files
committed
[IMP] util/records: prepare arch for parser also for jsonb arch
In a recent commit c7c95cf, some code to fixup views in preparation for the lxml.etree parser has been added to `edit_vew()`. So far, it only happens in the code path for non-jsonb columns. This patch introduces a sub-function and calls it from both the code branch for jsonb and non-jsonb. closes #4 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 7fd22bc commit 7681fac

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/util/records.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ def edit_view(cr, xmlid=None, view_id=None, skip_if_not_noupdate=True, active=Tr
199199
)
200200
[arch] = cr.fetchone() or [None]
201201
if arch:
202+
203+
def parse(arch):
204+
arch = arch.encode("utf-8") if isinstance(arch, unicode) else arch
205+
return lxml.etree.fromstring(arch.replace(b"&#13;\n", b"\n"))
206+
202207
if jsonb_column:
203208

204209
def get_trans_terms(value):
@@ -207,7 +212,7 @@ def get_trans_terms(value):
207212
return terms
208213

209214
translation_terms = {lang: get_trans_terms(value) for lang, value in arch.items()}
210-
arch_etree = lxml.etree.fromstring(arch["en_US"])
215+
arch_etree = parse(arch["en_US"])
211216
yield arch_etree
212217
new_arch = lxml.etree.tostring(arch_etree, encoding="unicode")
213218
terms_en = translation_terms["en_US"]
@@ -218,9 +223,7 @@ def get_trans_terms(value):
218223
}
219224
)
220225
else:
221-
if isinstance(arch, unicode):
222-
arch = arch.encode("utf-8")
223-
arch_etree = lxml.etree.fromstring(arch.replace(b"&#13;\n", b"\n"))
226+
arch_etree = parse(arch)
224227
yield arch_etree
225228
arch_column_value = lxml.etree.tostring(arch_etree, encoding="unicode")
226229

0 commit comments

Comments
 (0)