# -*- coding: utf-8 -*- import logging from odoo import http, tools from .tool import MakeResponse _logger = logging.getLogger(__name__) class xinChuangOpen(http.Controller): @http.route(['/xinchuang_open'], type='http', auth="public", website=True) def list(self, **kw): return http.request.render('tx_cms.xinChuangOpen', {}) @http.route(['/xinchuang_open_data', '/xinchuang_open_data/page/'], type='http', auth="public", website=True) def listData(self, industry_id=0, page=1, **kw): open_obj = http.request.env["tx.xinchuang.open"].sudo() _post_per_page = 9 page = int(page) industryList = [] industry_id = int(industry_id) industry_ids = open_obj.is_industry_ids.sudo().search([("code", "=", "II")])._get_dict_values() for index, item in enumerate(industry_ids): item["active"] = True if item["id"] == industry_id else False industryList.append(item) domain = [] if industry_id: domain.append(("is_industry_ids", "in", [industry_id])) openAll = open_obj.search(domain) pager = tools.lazy( lambda: http.request.website.pager(url='/xinchuang_open_data', total=openAll.__len__(), page=page, step=_post_per_page, scope=_post_per_page, url_args=kw)) openData = openAll[(page - 1) * _post_per_page:page * _post_per_page] records = [] for open in openData: records.append({ "id": open.id, "imgUrl": http.request.website.image_url(open, 'img'), "name": open.name, "companyName": open.company_name, "technicalIds": [technical_id.name for technical_id in open.technical_ids], "industryIds": [industry_id.name for industry_id in open.is_industry_ids], }) return MakeResponse.success({ "industryList": industryList, "records": records, "industry_id": industry_id, "pager": pager._value, }) @http.route('/xinchuang_open_details/', type='http', auth="public", website=True) def object(self, obj, **kw): return http.request.render('tx_cms.xinChuangOpenDetails', { 'object': obj }) @http.route('/xinchuang_open/details', methods=['get'], auth='public', website=True) def record_details(self, recordId, **kw): record_obj = http.request.env["tx.xinchuang.open"].sudo() obj = record_obj.sudo().browse([int(recordId)]) return MakeResponse.success({ "imgUrl": http.request.website.image_url(obj, 'img'), "name": obj.name, "briefIntroduction": obj.brief_introduction, "technicalList": [technical_id.name for technical_id in obj.technical_ids], "content": obj.content, })