93 lines
3.8 KiB
Python
93 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
from odoo import http, tools
|
|
from .tool import MakeResponse
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class digitalServiceProvider(http.Controller):
|
|
|
|
@http.route(['/digital_serviceProvider'], type='http', auth="public", website=True)
|
|
def list(self, **kw):
|
|
return http.request.render('tx_cms.digitalServiceProvider', {})
|
|
|
|
@http.route(['/digital_serviceProvider_data', '/digital_serviceProvider_data/page/<int:page>'], type='http', auth="public",
|
|
website=True)
|
|
def listData(self, nature_id=0, industry_id=0, page=1, **kw):
|
|
provider_obj = http.request.env["tx.digital.service.provider"].sudo()
|
|
_post_per_page = 9
|
|
page = int(page)
|
|
|
|
natureList = []
|
|
industryList = []
|
|
|
|
nature_id = int(nature_id)
|
|
industry_id = int(industry_id)
|
|
|
|
nature_ids = provider_obj.nature_ids.sudo().search([("code", "=", "EN")])._get_dict_values()
|
|
for index, item in enumerate(nature_ids):
|
|
item["active"] = True if item["id"] == nature_id else False
|
|
natureList.append(item)
|
|
|
|
industry_ids = provider_obj.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 nature_id:
|
|
domain.append(("nature_ids", "in", [nature_id]))
|
|
if industry_id:
|
|
domain.append(("industry_ids", "in", [industry_id]))
|
|
|
|
providerAll = provider_obj.search(domain)
|
|
|
|
pager = tools.lazy(
|
|
lambda: http.request.website.pager(url='/digital_serviceProvider_data', total=providerAll.__len__(),
|
|
page=page, step=_post_per_page, scope=_post_per_page,
|
|
url_args=kw))
|
|
|
|
providerData = providerAll[(page - 1) * _post_per_page:page * _post_per_page]
|
|
|
|
records = []
|
|
for provider in providerData:
|
|
records.append({
|
|
"id": provider.id,
|
|
"iconUrl": http.request.website.image_url(provider, 'icon'),
|
|
"imgUrl": http.request.website.image_url(provider, 'img'),
|
|
"name": provider.name,
|
|
"companyName": provider.company_name,
|
|
"natureIds": [nature_id.name for nature_id in provider.nature_ids],
|
|
"industryIds": [industry_id.name for industry_id in provider.industry_ids],
|
|
})
|
|
|
|
return MakeResponse.success({
|
|
"natureList": natureList,
|
|
"industryList": industryList,
|
|
"records": records,
|
|
"nature_id": nature_id,
|
|
"industry_id": industry_id,
|
|
"pager": pager._value,
|
|
})
|
|
|
|
@http.route('/digital_serviceProvider_details/<model("tx.digital.service.provider"):obj>', type='http', auth="public",
|
|
website=True)
|
|
def object(self, obj, **kw):
|
|
return http.request.render('tx_cms.digitalServiceProviderDetails', {
|
|
'object': obj
|
|
})
|
|
|
|
@http.route('/digital_serviceProvider/details', methods=['get'], auth='public', website=True)
|
|
def record_details(self, recordId, **kw):
|
|
record_obj = http.request.env["tx.digital.service.provider"].sudo()
|
|
obj = record_obj.sudo().browse([int(recordId)])
|
|
return MakeResponse.success({
|
|
"iconUrl": http.request.website.image_url(obj, 'icon'),
|
|
"imgUrl": http.request.website.image_url(obj, 'img'),
|
|
"name": obj.name,
|
|
"companyName": obj.company_name,
|
|
"natureList": [nature_id.name for nature_id in obj.nature_ids],
|
|
"briefIntroduction": obj.brief_introduction,
|
|
"content": obj.content,
|
|
})
|