62 lines
2.4 KiB
Python
62 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
from odoo import http, tools
|
|
from .tool import MakeResponse
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class policyXiaoLingTong(http.Controller):
|
|
|
|
@http.route(['/policy_xiaolingtong'], type='http', auth="public",website=True)
|
|
def list(self, **kw):
|
|
return http.request.render('tx_cms.policyXiaolingtong', {})
|
|
|
|
@http.route(['/policy_xiaolingtong_data', '/policy_xiaolingtong_data/page/<int:page>'], type='http', auth="public",
|
|
website=True)
|
|
def listData(self, page=1, **kw):
|
|
policy_obj = http.request.env["tx.policy.xiaolingtong"].sudo()
|
|
_post_per_page = 10
|
|
page = int(page)
|
|
|
|
policyDomain = []
|
|
|
|
policyData = policy_obj.sudo().search(policyDomain)
|
|
pager = tools.lazy(
|
|
lambda: http.request.website.pager(url='/policy_xiaolingtong_data', total=policyData.__len__(),
|
|
page=page, step=_post_per_page, scope=_post_per_page,
|
|
url_args=kw))
|
|
policyRecords = policyData[(page - 1) * _post_per_page:page * _post_per_page]
|
|
records = []
|
|
for policy in policyRecords:
|
|
records.append({
|
|
"id": policy.id,
|
|
"imgUrl": http.request.website.image_url(policy, 'img'),
|
|
"name": policy.name,
|
|
"startDate": f"""{policy.start_date.year}年{policy.start_date.month}月{policy.start_date.day}日""",
|
|
"endDate": f"""{policy.end_date.year}年{policy.end_date.month}月{policy.end_date.day}日""",
|
|
})
|
|
|
|
return MakeResponse.success({
|
|
"records": records,
|
|
"pager": pager._value,
|
|
})
|
|
|
|
@http.route('/policy_xiaolingtong_details/<model("tx.policy.xiaolingtong"):obj>', type='http', auth="public",
|
|
website=True)
|
|
def object(self, obj, **kw):
|
|
return http.request.render('tx_cms.policyXiaolingtongDetails', {
|
|
'object': obj
|
|
})
|
|
|
|
@http.route('/policy_xiaolingtong/details', methods=['get'], auth='public', website=True)
|
|
def record_details(self, recordId, **kw):
|
|
record_obj = http.request.env["tx.policy.xiaolingtong"].sudo()
|
|
obj = record_obj.sudo().browse([int(recordId)])
|
|
return MakeResponse.success({
|
|
"name": obj.name,
|
|
"startDate": obj.start_date.__str__(),
|
|
"endDate": obj.end_date.__str__(),
|
|
"content": obj.content,
|
|
})
|
|
|