1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
from odoo import models
from pytz import timezone
class BlogPost(models.Model):
_inherit = 'blog.post'
def api_single_response(self, blog, with_detail=False):
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
data = {
'id': blog.id,
# 'thumbnail': base_url + 'api/image/blog.post/thumbnail/' + str(blog.id) if blog.thumbnail else '',
'thumbnail': self.env['ir.attachment'].api_image('blog.post', 'thumbnail', blog.id),
'title': blog.name,
'category': {},
'author': {},
'post_date': blog.post_date.astimezone(timezone('Asia/Jakarta')).strftime('%d/%m/%Y') or '',
}
if blog.blog_id:
data['category'] = {
'id': blog.blog_id.id,
'name': blog.blog_id.name,
}
if blog.author_id:
data['author'] = {
'id': blog.author_id.id,
'name': blog.author_id.name
}
if with_detail:
data_with_detail = {
'meta': {
'title': blog.website_meta_title,
'description': blog.website_meta_description,
'keywords': blog.website_meta_keywords
},
'tags': [],
'content': blog.content,
}
for tag in blog.tag_ids:
data_with_detail['tags'].append({
'id': tag.id,
'name': tag.name,
})
data.update(data_with_detail)
return data
|