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:
@@ -28,24 +28,36 @@ class StatsController(EncoachMixin, http.Controller):
|
||||
vals['session_id'] = int(body['sessionId'])
|
||||
if body.get('module'):
|
||||
vals['module'] = body['module']
|
||||
if 'score' in body:
|
||||
vals['score'] = body['score']
|
||||
if body.get('result') is not None:
|
||||
vals['result'] = json.dumps(body['result']) if isinstance(body['result'], dict) else body['result']
|
||||
if body.get('solutions') is not None:
|
||||
vals['solutions'] = body['solutions'] if isinstance(body['solutions'], (dict, list)) else json.loads(body['solutions'])
|
||||
if body.get('exercise'):
|
||||
vals['exercise'] = body['exercise']
|
||||
if 'scoreCorrect' in body:
|
||||
vals['score_correct'] = int(body['scoreCorrect'])
|
||||
if 'scoreTotal' in body:
|
||||
vals['score_total'] = int(body['scoreTotal'])
|
||||
if 'scoreMissing' in body:
|
||||
vals['score_missing'] = int(body['scoreMissing'])
|
||||
if body.get('examId'):
|
||||
vals['exam_id'] = int(body['examId'])
|
||||
if body.get('assignmentId'):
|
||||
vals['assignment_id'] = int(body['assignmentId'])
|
||||
if body.get('type'):
|
||||
vals['stat_type'] = body['type']
|
||||
if 'timeSpent' in body:
|
||||
vals['time_spent'] = int(body['timeSpent'])
|
||||
if 'isPractice' in body:
|
||||
vals['is_practice'] = bool(body['isPractice'])
|
||||
|
||||
if stat_id:
|
||||
record = Stat.browse(int(stat_id))
|
||||
if record.exists():
|
||||
record.write(vals)
|
||||
return self._json_response(self._serialize_stat(record))
|
||||
return self._json_response(self._serialize(record))
|
||||
|
||||
vals['user_id'] = user.id
|
||||
record = Stat.create(vals)
|
||||
return self._json_response(self._serialize_stat(record), status=201)
|
||||
return self._json_response(self._serialize(record), status=201)
|
||||
except Exception:
|
||||
_logger.exception("Save stats error")
|
||||
return self._error_response('Internal server error', 500)
|
||||
@@ -65,7 +77,7 @@ class StatsController(EncoachMixin, http.Controller):
|
||||
if not stat.exists():
|
||||
return self._error_response('Stat not found', 404)
|
||||
|
||||
return self._json_response(self._serialize_stat(stat))
|
||||
return self._json_response(self._serialize(stat))
|
||||
except Exception:
|
||||
_logger.exception("Get stat error")
|
||||
return self._error_response('Internal server error', 500)
|
||||
@@ -130,7 +142,7 @@ class StatsController(EncoachMixin, http.Controller):
|
||||
'total': total,
|
||||
'averageScore': round(avg_score, 2),
|
||||
'moduleBreakdown': module_breakdown,
|
||||
'stats': [self._serialize_stat(s) for s in stats[:100]],
|
||||
'stats': [self._serialize(s) for s in stats[:100]],
|
||||
})
|
||||
except Exception:
|
||||
_logger.exception("Statistical query error")
|
||||
|
||||
Reference in New Issue
Block a user