64 lines
2.5 KiB
Python
64 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
from odoo import http, tools
|
|
from .tool import MakeResponse
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class insightDirectTrains(http.Controller):
|
|
|
|
@http.route(['/insight_direct_trains'], type='http', auth="public",website=True)
|
|
def list(self, **kw):
|
|
return http.request.render('tx_cms_upgrade.insightDirectTrains', {})
|
|
|
|
@http.route(['/insight_direct_trains_data', '/insight_direct_trains_data/page/<int:page>'], type='http', auth="public",
|
|
website=True)
|
|
def listData(self, page=1, **kw):
|
|
trains_obj = http.request.env["tx.insight.direct.trains"].sudo()
|
|
_post_per_page = 10
|
|
page = int(page)
|
|
|
|
trainsDomain = []
|
|
|
|
trainsData = trains_obj.sudo().search(trainsDomain)
|
|
pager = tools.lazy(
|
|
lambda: http.request.website.pager(url='/insight_direct_trains_data', total=trainsData.__len__(),
|
|
page=page, step=_post_per_page, scope=_post_per_page,
|
|
url_args=kw))
|
|
trainsRecords = trainsData[(page - 1) * _post_per_page:page * _post_per_page]
|
|
|
|
records = []
|
|
for trains in trainsRecords:
|
|
records.append({
|
|
"id": trains.id,
|
|
"imgUrl": http.request.website.image_url(trains, 'img'),
|
|
"name": trains.name,
|
|
"startDate": f"""{trains.start_date.year}年{trains.start_date.month}月{trains.start_date.day}日""",
|
|
"endDate": f"""{trains.end_date.year}年{trains.end_date.month}月{trains.end_date.day}日""",
|
|
})
|
|
|
|
return MakeResponse.success({
|
|
"records": records,
|
|
"pager": pager._value,
|
|
})
|
|
|
|
@http.route('/insight_direct_trains_details/<model("tx.insight.direct.trains"):obj>', type='http', auth="public",
|
|
website=True)
|
|
def object(self, obj, **kw):
|
|
return http.request.render('tx_cms_upgrade.insightDirectTrainsDetails', {
|
|
'object': obj
|
|
})
|
|
|
|
@http.route('/insight_direct_trains/details', methods=['get'], auth='public', website=True)
|
|
def record_details(self, recordId, **kw):
|
|
record_obj = http.request.env["tx.insight.direct.trains"].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,
|
|
})
|
|
|
|
|