diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-23 14:41:48 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-23 14:41:48 +0700 |
| commit | ae475a8d1dc9fa291d079e00d4194c55a0bb408c (patch) | |
| tree | 82a7d96f161e1c0b2ece24171bd5ac3d4f4484d7 /indoteknik_custom/models/blog_post.py | |
| parent | 6538d8958c541e208df9a5fd83d5bdd5a0ae021c (diff) | |
| parent | de4a6c2c2ce115d169a3a85548ff95c8789e25c8 (diff) | |
Merge branch 'release' of bitbucket.org:altafixco/indoteknik-addons into release
Diffstat (limited to 'indoteknik_custom/models/blog_post.py')
| -rw-r--r-- | indoteknik_custom/models/blog_post.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/indoteknik_custom/models/blog_post.py b/indoteknik_custom/models/blog_post.py index 27f0c125..18844f0f 100644 --- a/indoteknik_custom/models/blog_post.py +++ b/indoteknik_custom/models/blog_post.py @@ -1,4 +1,9 @@ from odoo import models, fields +from odoo.exceptions import UserError +import logging +import re + +_logger = logging.getLogger(__name__) class BlogPost(models.Model): @@ -9,3 +14,24 @@ class BlogPost(models.Model): thumbnail_256 = fields.Image("Thumbnail 256", related="thumbnail", max_width=256, max_height=256, store=True) thumbnail_512 = fields.Image("Thumbnail 512", related="thumbnail", max_width=512, max_height=512, store=True) thumbnail_1024 = fields.Image("Thumbnail 1024", related="thumbnail", max_width=1024, max_height=1024, store=True) + replace_click = fields.Boolean(string='Replace Clicked', help='Penanda bahwa Replace Keyword sudah di klik atau belum') + category_id = fields.Many2one('product.public.category', string='Product Category', help='Untuk replace keyword sesuai product category yang dipilih') + + def replace_keyword_to_link(self): + if not self.category_id: + return + if self.replace_click: + raise UserError('Sudah pernah di klik sekali') + + category_name = self.category_id.name + category_name = category_name.replace(' ', '+') + link_url = '<a href="https://indoteknik.com/shop/search?product_name=' + category_name + '">' + self.category_id.name + '</a>' + + content = self.content + compiled = re.compile(re.escape(self.category_id.name), re.IGNORECASE) + res = compiled.sub(link_url, content) + # content = content.replace(category.name, link_url) + self.content = res + _logger.info('Blog: Success Replace text to URL %s' % self.id) + + self.replace_click = True |
