summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-02-23 11:31:59 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-02-23 11:31:59 +0700
commitea39d3aaf90aa99f4e845420cf11223dc993aa7f (patch)
tree17d2d48a6d2a7f5042e8aa99c70b9ef7cb8b0fd0
parent75aabb813212ab796a10ee74f7f24e337d6b7ca0 (diff)
change method replace keyword blog
-rw-r--r--indoteknik_custom/models/blog_post.py37
-rw-r--r--indoteknik_custom/views/blog_post.xml2
2 files changed, 15 insertions, 24 deletions
diff --git a/indoteknik_custom/models/blog_post.py b/indoteknik_custom/models/blog_post.py
index 6e96a311..18844f0f 100644
--- a/indoteknik_custom/models/blog_post.py
+++ b/indoteknik_custom/models/blog_post.py
@@ -15,32 +15,23 @@ class BlogPost(models.Model):
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')
+ 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 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>'
+ 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>'
- 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)
+ 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
diff --git a/indoteknik_custom/views/blog_post.xml b/indoteknik_custom/views/blog_post.xml
index d34a82d4..de346d1f 100644
--- a/indoteknik_custom/views/blog_post.xml
+++ b/indoteknik_custom/views/blog_post.xml
@@ -7,12 +7,12 @@
<field name="inherit_id" ref="website_blog.view_blog_post_form" />
<field name="arch" type="xml">
<field name="blog_id" position="before">
+ <field name="thumbnail" widget="image" width="240" />
<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">