OdooDigitizationService/addons/tx_cms/controllers/activity_exploration.py

85 lines
3.5 KiB
Python

# -*- coding: utf-8 -*-
import logging
from odoo import http, tools, fields
from .tool import MakeResponse
_logger = logging.getLogger(__name__)
class ActivityExploration(http.Controller):
@http.route(['/activity_exploration'], type='http', auth="public", website=True)
def activity_exploration(self, **kw):
return http.request.render('tx_cms.activityExploration')
@http.route(['/activity_exploration_data', '/activity_exploration_data/page/<int:page>'], methods=['get'], auth='public', website=True, csrf=False, cors="*")
def activity_exploration_data(self, page=1, **kw):
search = kw.get("search", False)
state_id = int(kw.get("state_id", 0))
page = int(page)
exploration_obj = http.request.env["tx.activity.exploration"].sudo()
website = http.request.website.sudo()
_post_per_page = 10
state = [
{"id": 0, "name": "全部", "active": True if state_id == 0 else False},
{"id": 1, "name": "报名中", "active": True if state_id == 1 else False},
{"id": 2, "name": "进行中", "active": True if state_id == 2 else False},
{"id": 3, "name": "已结束", "active": True if state_id == 3 else False}
]
domain = []
if state_id == 1:
domain.append(("start_date", ">", fields.Date.today()))
if state_id == 2:
domain.append(("start_date", "<", fields.Date.today()))
domain.append(("end_date", ">", fields.Date.today()))
if state_id == 3:
domain.append(("end_date", "<", fields.Date.today()))
explorationAll = exploration_obj.search(domain)
pager = tools.lazy(
lambda: http.request.website.pager(url='/activity_exploration_data', total=explorationAll.__len__(),
page=page, step=_post_per_page, scope=_post_per_page,
url_args=kw))
explorationData = explorationAll[
(page - 1) * _post_per_page:page * _post_per_page]
records = []
for exploration in explorationData:
records.append({
"id": exploration.id,
"imgUrl": website.image_url(exploration, 'img'),
"name": exploration.name,
"createDate": f"""{exploration.create_date.year}{exploration.create_date.month}{exploration.create_date.day}""",
"briefIntroduction": str(exploration.brief_introduction),
"state": exploration.get_state_value(exploration.state),
})
return MakeResponse.success({
"stateList": state,
"explorationData": records,
"pager": pager._value,
})
@http.route('/activity_exploration_details/<model("tx.activity.exploration"):obj>', type='http', auth="public",
website=True)
def object(self, obj, **kw):
return http.request.render('tx_cms.activityExplorationDetails', {
'object': obj
})
@http.route('/activity_exploration/details', methods=['get'], auth='public')
def record_details(self, recordId, **kw):
record_obj = http.request.env["tx.activity.exploration"].sudo()
obj = record_obj.sudo().browse([int(recordId)])
return MakeResponse.success({
"name": obj.name,
"start_date": obj.start_date.__str__(),
"end_date": obj.end_date.__str__(),
"content": obj.content,
})