# -*- coding: utf-8 -*- import logging from odoo import http, tools from .tool import MakeResponse _logger = logging.getLogger(__name__) class digitalAlly(http.Controller): @http.route(['/digital_ally'], type='http', auth="public", website=True) def list(self, **kw): return http.request.render('tx_cms.digitalAlly', {}) @http.route(['/digital_ally_data', '/digital_ally_data/page/'], type='http', auth="public", website=True) def listData(self, industry_id=0, page=1, **kw): ally_obj = http.request.env["tx.digital.ally"].sudo() _post_per_page = 9 page = int(page) industryList = [] industry_id = int(industry_id) industry_ids = ally_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])) allyAll = ally_obj.search(domain) pager = tools.lazy( lambda: http.request.website.pager(url='/digital_ally_data', total=allyAll.__len__(), page=page, step=_post_per_page, scope=_post_per_page, url_args=kw)) allyData = allyAll[(page - 1) * _post_per_page:page * _post_per_page] records = [] for ally in allyData: records.append({ "id": ally.id, "imgUrl": http.request.website.image_url(ally, 'img'), "name": ally.name, "companyName": ally.company_name, "technicalIds": [technical_id.name for technical_id in ally.technical_ids], "industryIds": [industry_id.name for industry_id in ally.is_industry_ids], }) return MakeResponse.success({ "industryList": industryList, "records": records, "industry_id": industry_id, "pager": pager._value, }) @http.route('/digital_ally_details/', type='http', auth="public", website=True) def object(self, obj, **kw): return http.request.render('tx_cms.digitalAllyDetails', { 'object': obj }) @http.route('/digital_ally/details', methods=['get'], auth='public', website=True) def record_details(self, recordId, **kw): record_obj = http.request.env["tx.digital.ally"].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, })