summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-02-23 10:27:19 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-02-23 10:27:19 +0700
commit75aabb813212ab796a10ee74f7f24e337d6b7ca0 (patch)
treedf2cd1b933f1fe58d6ecda894de7f43c89c8fc46
parent861bb64e5a972b8ce9b09d2345dbb6250d041435 (diff)
add blog replace keyword to link
-rw-r--r--indoteknik_custom/models/blog_post.py35
-rwxr-xr-xindoteknik_custom/models/product_public_category.py6
-rw-r--r--indoteknik_custom/views/blog_post.xml6
3 files changed, 47 insertions, 0 deletions
diff --git a/indoteknik_custom/models/blog_post.py b/indoteknik_custom/models/blog_post.py
index 27f0c125..6e96a311 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,33 @@ 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(string='Product Category', help='Untuk replace keyword sesuai product category yang dipilih')
+
+ def replace_keyword_to_link(self):
+ if self.replace_click:
+ raise UserError('Sudah pernah di click')
+ query = [
+ ('level', '=', 'level4')
+ # ('id', '=', 1057) for debug only
+ ]
+ categories = self.env['product.public.category'].search(query, order='id')
+ for category in categories:
+ category_name = category.name
+ category_name = category_name.replace(' ', '+')
+ link_url = '<a href="https://indoteknik.com/shop/search?product_name=' + category_name + '">' + category.name + '</a>'
+
+ query = [
+ ('content', 'ilike', category.name)
+ ]
+ # blogs = self.env['blog.post'].search(query, order='id')
+
+ # for blog in blogs:
+ content = self.content
+ compiled = re.compile(re.escape(category.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
diff --git a/indoteknik_custom/models/product_public_category.py b/indoteknik_custom/models/product_public_category.py
index 91028ae0..f46646d6 100755
--- a/indoteknik_custom/models/product_public_category.py
+++ b/indoteknik_custom/models/product_public_category.py
@@ -14,4 +14,10 @@ class ProductPublicCategory(models.Model):
parent_frontend_id = fields.Many2one('product.public.category', string='Parent Frontend Category', index=True)
child_frontend_id = fields.One2many('product.public.category', 'parent_frontend_id', string='Children Frontend Categories')
sequence_frontend = fields.Integer(help="Gives the sequence order when displaying a list of product categories.", index=True)
+ level = fields.Selection([
+ ('level1', 'Level 1'),
+ ('level2', 'Level 2'),
+ ('level3', 'Level 3'),
+ ('level4', 'Level 4'),
+ ])
# check
diff --git a/indoteknik_custom/views/blog_post.xml b/indoteknik_custom/views/blog_post.xml
index abb6be8b..d34a82d4 100644
--- a/indoteknik_custom/views/blog_post.xml
+++ b/indoteknik_custom/views/blog_post.xml
@@ -7,7 +7,13 @@
<field name="inherit_id" ref="website_blog.view_blog_post_form" />
<field name="arch" type="xml">
<field name="blog_id" position="before">
+ <button name="replace_keyword_to_link"
+ string="Replace Keyword"
+ type="object"
+ class="oe_highlight oe_edit_only"
+ />
<field name="thumbnail" widget="image" width="240" />
+ <field name="category_id"/>
</field>
<page name="seo" position="attributes">
<attribute name="groups"/>