93 lines
3.9 KiB
Python
93 lines
3.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
from odoo import http, tools
|
|
from .tool import MakeResponse
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class highQualitySolutions(http.Controller):
|
|
|
|
@http.route(['/high_quality_solutions'], type='http', auth="public", website=True)
|
|
def list(self, **kw):
|
|
return http.request.render('tx_cms.highQualitySolutions', {})
|
|
|
|
@http.route(['/high_quality_solutions_data', '/high_quality_solutions_data/page/<int:page>'], type='http', auth="public",
|
|
website=True)
|
|
def listData(self, technical_id=0, industry_id=0, page=1, **kw):
|
|
solutions_obj = http.request.env["tx.high.quality.solutions"].sudo()
|
|
_post_per_page = 9
|
|
page = int(page)
|
|
|
|
technicalList = []
|
|
industryList = []
|
|
technical_id = int(technical_id)
|
|
industry_id = int(industry_id)
|
|
|
|
technical_ids = solutions_obj.technical_ids.sudo().search([("code", "=", "TF")])._get_dict_values()
|
|
for index, item in enumerate(technical_ids):
|
|
item["active"] = True if item["id"] == technical_id else False
|
|
technicalList.append(item)
|
|
|
|
industry_ids = solutions_obj.industry_ids.sudo().search([("code", "=", "IF")])._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(("industry_ids", "in", [industry_id]))
|
|
if technical_id:
|
|
domain.append(("technical_ids", "in", [technical_id]))
|
|
|
|
solutionsAll = solutions_obj.search(domain)
|
|
|
|
pager = tools.lazy(
|
|
lambda: http.request.website.pager(url='/high_quality_solutions_data', total=solutionsAll.__len__(),
|
|
page=page, step=_post_per_page, scope=_post_per_page,
|
|
url_args=kw))
|
|
|
|
solutionsData = solutionsAll[(page - 1) * _post_per_page:page * _post_per_page]
|
|
|
|
records = []
|
|
for solutions in solutionsData:
|
|
records.append({
|
|
"id": solutions.id,
|
|
"recommend": solutions.recommend,
|
|
"imgUrl": http.request.website.image_url(solutions, 'img'),
|
|
"name": solutions.name,
|
|
"companyName": solutions.company_name,
|
|
"createDate": f"""{solutions.create_date.year}年{solutions.create_date.month}月{solutions.create_date.day}日""",
|
|
"briefIntroduction": str(solutions.brief_introduction),
|
|
"technicalIds": [technical_id.name for technical_id in solutions.technical_ids],
|
|
})
|
|
|
|
return MakeResponse.success({
|
|
"technicalList": technicalList,
|
|
"industryList": industryList,
|
|
"records": records,
|
|
"technical_id": technical_id,
|
|
"industry_id": industry_id,
|
|
"pager": pager._value,
|
|
})
|
|
|
|
@http.route('/high_quality_solutions_details/<model("tx.high.quality.solutions"):obj>', type='http', auth="public",
|
|
website=True)
|
|
def object(self, obj, **kw):
|
|
return http.request.render('tx_cms.highQualitySolutionsDetails', {
|
|
'object': obj
|
|
})
|
|
|
|
@http.route('/high_quality_solutions/details', methods=['get'], auth='public', website=True)
|
|
def record_details(self, recordId, **kw):
|
|
record_obj = http.request.env["tx.high.quality.solutions"].sudo()
|
|
obj = record_obj.sudo().browse([int(recordId)])
|
|
return MakeResponse.success({
|
|
"name": obj.name,
|
|
"briefIntroduction": obj.brief_introduction,
|
|
"technicalList": [technical_id.name for technical_id in obj.technical_ids],
|
|
"imgUrl": http.request.website.image_url(obj, 'img'),
|
|
"companyName": obj.company_name,
|
|
"content": obj.content,
|
|
})
|