etq_results.py
2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from odoo import models, fields, api
import logging
# import requests
# from odoo.http import request
#
# # from datetime import datetime
# # from openerp.tools import html_escape as escape, ustr, image_resize_and_sharpen, image_save_for_web
# # import unicodedata
# # import re
_logger = logging.getLogger(__name__)
#
#
class EtqResults(models.Model):
_name = "etq.result"
_description = "Exam Result"
exam_id = fields.Many2one('etq.exam', string="Exam", readonly=True)
user_id = fields.Many2one('res.users', string="User")
score = fields.Char(string="Score", compute="_compute_score")
results = fields.One2many('etq.result.question', 'result_id',
string="Results", readonly=True)
token = fields.Char(string="Token")
state = fields.Selection(
[('incomplete', 'Incomplete'), ('complete', 'Complete')],
string="State")
# # @api.one
@api.depends('results')
def _compute_score(self):
for rec in self:
num_questions = self.env['etq.result.question'].search_count(
[('result_id', '=', rec.id)])
if num_questions < 1:
rec.score = '0/0 0%'
continue
correct_questions = self.env['etq.result.question'].search_count(
[('result_id', '=', rec.id), ('correct', '=', True)])
rec.score = str(correct_questions) + "/" + \
str(num_questions) + " " + \
str(round(float(float(correct_questions) /
float(num_questions)) * 100, 1)) + "%"
# def name_get(self, context=None):
# return self.token
class EtqResultQuestion(models.Model):
_name = "etq.result.question"
_description = "Exam Result Question"
result_id = fields.Many2one('etq.result', string="Result", readonly=True,
ondelete='cascade', )
question_id = fields.Many2one('etq.question', string="Questions",
readonly=True)
question_options = fields.One2many('etq.result.question.option',
'question_id', string="Options",
readonly=True)
correct = fields.Boolean(string="Correct", readonly=True)
question_name = fields.Html(related="question_id.question",
string="Questions")
class EtqResultQuestionOptions(models.Model):
_name = "etq.result.question.option"
_description = "Exam Result Question Option"
question_id = fields.Many2one('etq.result.question_id',
string="Question ID",
readonly=True, ondelete='cascade', )
option_id = fields.Many2one('etq.question.option', string="Options",
readonly=True)
option_name = fields.Char(related="option_id.option", string="Option")
question_options_value = fields.Char(string="Option Value", readonly=True)