108 lines
4.2 KiB
Python
108 lines
4.2 KiB
Python
from odoo import http, _
|
|
from odoo.http import request
|
|
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
|
|
|
|
class ExamPortal(CustomerPortal):
|
|
|
|
def _prepare_home_portal_values(self, counters):
|
|
values = super()._prepare_home_portal_values(counters)
|
|
student = request.env['education.student'].sudo().search([('portal_user_id', '=', request.env.user.id)], limit=1)
|
|
if student:
|
|
if 'exam_count' in counters:
|
|
exam_count = request.env['education.exam'].sudo().search_count([
|
|
('program_id', '=', student.program_id.id),
|
|
('term_id', '=', student.academic_term_id.id),
|
|
('state', 'in', ['scheduled', 'ongoing'])
|
|
])
|
|
values['exam_count'] = exam_count
|
|
|
|
if 'result_count' in counters:
|
|
result_count = request.env['education.exam.result'].sudo().search_count([
|
|
('student_id', '=', student.id),
|
|
('published', '=', True)
|
|
])
|
|
values['result_count'] = result_count
|
|
return values
|
|
|
|
@http.route(['/my/exams', '/my/exams/page/<int:page>'], type='http', auth="user", website=True)
|
|
def portal_my_exams(self, page=1, **kw):
|
|
student = request.env['education.student'].sudo().search([('portal_user_id', '=', request.env.user.id)], limit=1)
|
|
if not student:
|
|
return request.redirect('/my')
|
|
|
|
domain = [
|
|
('program_id', '=', student.program_id.id),
|
|
('term_id', '=', student.academic_term_id.id),
|
|
('state', 'in', ['scheduled', 'ongoing'])
|
|
]
|
|
|
|
exam_count = request.env['education.exam'].sudo().search_count(domain)
|
|
pager = portal_pager(
|
|
url="/my/exams",
|
|
total=exam_count,
|
|
page=page,
|
|
step=10
|
|
)
|
|
exams = request.env['education.exam'].sudo().search(domain, limit=10, offset=pager['offset'], order='start_date desc')
|
|
|
|
values = {
|
|
'exams': exams,
|
|
'page_name': 'exams',
|
|
'pager': pager,
|
|
'default_url': '/my/exams',
|
|
'student': student,
|
|
}
|
|
return request.render("education_exam.portal_my_exams", values)
|
|
|
|
@http.route(['/my/results', '/my/results/page/<int:page>'], type='http', auth="user", website=True)
|
|
def portal_my_results(self, page=1, **kw):
|
|
student = request.env['education.student'].sudo().search([('portal_user_id', '=', request.env.user.id)], limit=1)
|
|
if not student:
|
|
return request.redirect('/my')
|
|
|
|
domain = [
|
|
('student_id', '=', student.id),
|
|
('published', '=', True)
|
|
]
|
|
|
|
result_count = request.env['education.exam.result'].sudo().search_count(domain)
|
|
pager = portal_pager(
|
|
url="/my/results",
|
|
total=result_count,
|
|
page=page,
|
|
step=10
|
|
)
|
|
results = request.env['education.exam.result'].sudo().search(domain, limit=10, offset=pager['offset'])
|
|
|
|
values = {
|
|
'results': results,
|
|
'page_name': 'results',
|
|
'pager': pager,
|
|
'default_url': '/my/results',
|
|
'student': student,
|
|
}
|
|
return request.render("education_exam.portal_my_results", values)
|
|
|
|
@http.route(['/my/results/<int:result_id>'], type='http', auth="user", website=True)
|
|
def portal_my_result_detail(self, result_id, **kw):
|
|
student = request.env['education.student'].sudo().search([('portal_user_id', '=', request.env.user.id)], limit=1)
|
|
if not student:
|
|
return request.redirect('/my')
|
|
|
|
# Ensure the result belongs to the logged in student and is published
|
|
result = request.env['education.exam.result'].sudo().search([
|
|
('id', '=', result_id),
|
|
('student_id', '=', student.id),
|
|
('published', '=', True)
|
|
], limit=1)
|
|
|
|
if not result:
|
|
return request.redirect('/my/results')
|
|
|
|
values = {
|
|
'result': result,
|
|
'page_name': 'result_detail',
|
|
'student': student,
|
|
}
|
|
return request.render("education_exam.portal_result_detail", values)
|