Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

how to output json from char field to html?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
jsonhtmlv14
2 Răspunsuri
4542 Vizualizări
Imagine profil
Denis Lutsak

I have a field of type char into which a string with json code will be inserted from parsing:

custom_data = fields.Char()

and I need to display this json in the form of html. It is reliably known that the json code will contain only the key, value, lang fields, for example:

[{"key":"rdhh","value":"sdasd","lang":"sada"},{"key":"rd123hh","value":"sd123asd","lang":"sad123a"},{"key":"rdh111h","value": "s111dasd","lang":"sa11da"},{"key":"rd44hh","value":"42sdasd","lang":"s4ada"},{"key":"rdhh6","value":"sd5asd","lang":"sa7da"}]


I did this with numpy, pandas libraries but I keep getting the message that my json code is equal to a binary value, even after I set it to default="[]".

Here is the code of my implementation:


personalization_html = fields.Html(string="Product property", compute='_json_conf')

def _json_conf(self):
cd = self.custom_data
names = ["key", "value", "lang"]

if cd == "[]":
df = pd.DataFrame(columns=names)
else:
z = json.dumps(cd)
y = json.loads(z)

arrs = []
for i in y:
value = []
value.append(i["key"])
value.append(i["value"])
value.append(i["lang"])

arrs.append(value)

a = np.array(arrs)

df = pd.DataFrame(a, columns=names)

return df.to_html(index=False)

I've been struggling with this for a week now, I've tried everything, but still nothing works...



0
Imagine profil
Abandonează
Imagine profil
Denis Lutsak
Autor Cel mai bun răspuns
it didn't help me, but thanks to this code I rewrote my code and it worked)
def _compute_personalization_html(self):
cd = str(self.custom_data)
 
if cd == "False":
df = pd.DataFrame(columns=["#", "Key", "Value", "Lang"])
else:
custom_data = json.loads(cd)
data = []
num = 1
for row in custom_data:
data.append([num, row["key"], row["value"], row["lang"]])
num += 1

df = pd.DataFrame(data, columns=["#", "Key", "Value", "Lang"])

self.personalization_html = df.to_html(classes="table", index=False).replace('', '').replace(' border="1"', '')
0
Imagine profil
Abandonează
Imagine profil
Savya Sachin
Cel mai bun răspuns

Hi,

Can you just try like this,


    custom_data = fields.Char(default="[]")
    personalization_html = fields.Html(string="Product property", compute='_compute_personalization_html')

    def _compute_personalization_html(self):
        for record in self:
            cd = record.custom_data
            names = ["key", "value", "lang"]

            if cd == "[]":
                html = ""
            else:
                data = json.loads(cd)
                rows = []
                for item in data:
                    row = [item.get("key", ""), item.get("value", ""), item.get("lang", "")]
                    rows.append(row)

                html = ""
                html += "".format(*names)
                for row in rows:
                    html += "".format(*row)
                html += "
{}{}{}
{}{}{}
"
record.personalization_html = html

Thanks

0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Tracking Html field Rezolvat
project tracking html v14
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
aug. 24
8936
How to remove pre-filled input value from Odoo newsletter block
html newsletter input v14
Imagine profil
1
sept. 22
3995
Odoo 14 type http
json http.route v14 router
Imagine profil
0
aug. 22
4351
Discard changes when an exception happens in Odoo 14 JSON RPC
json exception jsonrpc v14
Imagine profil
0
mai 21
4366
Attached PDF file is not formatted properly
v14
Imagine profil
Imagine profil
1
dec. 25
327
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now