OdooDigitizationService/addons/tx_cms_upgrade/controllers/xinchuang_open.py

132 lines
5.2 KiB
Python

# -*- coding: utf-8 -*-
import json
import math
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_upgrade.xinChuangOpen', {})
@http.route(['/xinchuang_open_data', '/xinchuang_open_data/page/<int: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/<model("tx.xinchuang.open"):obj>', type='http', auth="public",
website=True)
def object(self, obj, **kw):
return http.request.render('tx_cms_upgrade.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,
})
# 有数了 -- 信创开源 列表
@http.route("/tx_base/api/open/list", methods=['POST'], auth='public', csrf=False, website=True, cors="*")
def scenes_list(self, **kw):
params = json.loads(http.request.httprequest.data.decode("utf-8"))
page_num = params.get("pageNum", 1)
page_size = params.get("pageSize", 10)
open_name = params.get("openName", "")
industry_type = params.get("industryType", [])
model_obj = http.request.env["tx.xinchuang.open"].sudo()
records = []
domain = []
if industry_type.__len__():
domain.append(("is_industry_ids", "in", industry_type))
if open_name:
domain.append(("name", "like", f"%{open_name}%"))
total = model_obj.search_count(domain)
offset = (page_num - 1) * page_size if page_num > 1 else 0
dataAll = model_obj.search(domain, offset, page_size)
for data in dataAll:
records.append({
"id": data.id,
"openAvatar": f"""{data.get_base_url()}{http.request.website.image_url(data, 'img')}""",
"openName": f"{data.name}",
"industryType": ",".join([industry_id.name for industry_id in data.is_industry_ids]),
})
pages = math.ceil(total / page_size)
return MakeResponse.opontekr_success(records, total, pages)
# 有数了 -- 信创开源 详情
@http.route("/tx_base/api/open/info", methods=['GET'], auth='public', csrf=False, website=True, cors="*")
def record_info(self, **kwargs):
try:
openId = kwargs.get("openId", False)
model_obj = http.request.env["tx.xinchuang.open"].sudo()
record = model_obj.search([("id", "=", openId)])
data = {
"openAvatar": f"""{record.get_base_url()}{http.request.website.image_url(record, 'img')}""",
"openName": record.name,
"openDescription": record.brief_introduction,
"openContent": record.content,
}
return MakeResponse.success(data)
except Exception as e:
_logger.error(e)
return MakeResponse.error("参数错误")