Fix remaining controller serialization and model mismatches
- Replace all _serialize_group/exam/assignment/stat/session calls with _serialize - Fix sessions controller to use exam_data JSON field instead of nonexistent columns - Fix stats controller to use correct model fields (score_correct/total/missing, solutions) Made-with: Cursor
This commit is contained in:
@@ -24,29 +24,19 @@ class SessionsController(EncoachMixin, http.Controller):
|
||||
session_id = body.get('_id') or body.get('id')
|
||||
Session = request.env['encoach.session'].sudo()
|
||||
|
||||
vals = {}
|
||||
if body.get('examId'):
|
||||
vals['exam_id'] = int(body['examId'])
|
||||
if body.get('module'):
|
||||
vals['module'] = body['module']
|
||||
if body.get('answers') is not None:
|
||||
vals['answers'] = json.dumps(body['answers']) if isinstance(body['answers'], dict) else body['answers']
|
||||
if body.get('startedAt'):
|
||||
vals['started_at'] = body['startedAt']
|
||||
if body.get('completedAt'):
|
||||
vals['completed_at'] = body['completedAt']
|
||||
if body.get('assignmentId'):
|
||||
vals['assignment_id'] = int(body['assignmentId'])
|
||||
exam_data = {k: v for k, v in body.items() if k not in ('_id', 'id')}
|
||||
|
||||
if session_id:
|
||||
record = Session.browse(int(session_id))
|
||||
if record.exists():
|
||||
record.write(vals)
|
||||
return self._json_response(self._serialize_session(record))
|
||||
record.write({'exam_data': exam_data})
|
||||
return self._json_response(self._serialize(record))
|
||||
|
||||
vals['user_id'] = user.id
|
||||
record = Session.create(vals)
|
||||
return self._json_response(self._serialize_session(record), status=201)
|
||||
record = Session.create({
|
||||
'user_id': user.id,
|
||||
'exam_data': exam_data,
|
||||
})
|
||||
return self._json_response(self._serialize(record), status=201)
|
||||
except Exception:
|
||||
_logger.exception("Save session error")
|
||||
return self._error_response('Internal server error', 500)
|
||||
|
||||
Reference in New Issue
Block a user