Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
70 views
in Technique[技术] by (71.8m points)

python - Clean html body tags in chatter?

In website support model (Odoo 12), when I close ticket I have to write a message to send it through email. Then, this message will post in the chatter, but I'm receiving this:

Message in chatter

I've tried using regex, to clean the html tags, but still the comment came with tags.

class WebsiteSupportTicketClose(models.TransientModel):

    _inherit = "website.support.ticket.close"

    def close_ticket(self):

        # ... code
        clean_message = self.cleanhtml(self.message)
        print(clean_message)
        self.ticket_id.close_comment = clean_message
        
        # code ...

    def cleanhtml(self, raw_html):
        cleanr = re.compile('<.*?>')
        cleantext = re.sub(cleanr, '', raw_html)
        return cleantext

In the prints, I can see that clean_message variable is formatted without tags, but when I assigned this to self.ticket_id.close_comment is adding the tags.

How can I delete the tags?

question from:https://stackoverflow.com/questions/65851234/clean-html-body-tags-in-chatter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[4] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

57.0k users

...