From 7e200b74a7de9a2d582c73a079ba6ef4a26bcfaa Mon Sep 17 00:00:00 2001 From: mikaelGusse Date: Thu, 15 Aug 2024 14:45:13 +0300 Subject: [PATCH] Fix tooltip update on removal --- .../static/exercise/personalized_points_goal.js | 4 ++-- exercise/templates/exercise/_points_progress.html | 2 +- exercise/views.py | 13 ++++--------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/exercise/static/exercise/personalized_points_goal.js b/exercise/static/exercise/personalized_points_goal.js index fb338be80..4e44d5ae8 100644 --- a/exercise/static/exercise/personalized_points_goal.js +++ b/exercise/static/exercise/personalized_points_goal.js @@ -57,7 +57,7 @@ $(document).ready(function() { spanElement = doc.createElement('span'); spanElement.className = 'personalized-points-full-text text-nowrap'; doc.body.appendChild(spanElement); - spanElement.innerHTML = "
" + $pointsGoalForm.data('personalized-points-goal-tooltip-text') + ": " + response.personalized_points_goal_points; + spanElement.innerHTML = "
" + $pointsGoalForm.data('personalized-points-goal-tooltip-text') + ": " + "" + response.personalized_points_goal_points + ""; } else { spanElement.textContent = response.personalized_points_goal_points; @@ -127,7 +127,7 @@ $(document).ready(function() { // Update progress-bar style $progressDiv.find('.progress-bar').removeClass('progress-bar-primary'); - + $('#remove-success-alert').show(); setTimeout(function() { $('#remove-success-alert').hide(); diff --git a/exercise/templates/exercise/_points_progress.html b/exercise/templates/exercise/_points_progress.html index 154f7987e..eaf8a6378 100644 --- a/exercise/templates/exercise/_points_progress.html +++ b/exercise/templates/exercise/_points_progress.html @@ -9,7 +9,7 @@
JsonResponse: module_slug = self.kwargs['module_slug'] points_goal = request.POST.get('personalized_points_goal_input') delete = request.POST.get('delete') + student = UserProfile.objects.get(id=user_id) + module = CourseModule.objects.get(url=module_slug) + cached_points = CachedPoints(module.course_instance, student, True) + cached_module, _, _, _ = cached_points.find(module) if delete: - student = UserProfile.objects.get(id=user_id) - module = CourseModule.objects.get(url=module_slug) try: StudentModuleGoal.objects.get(student=user_id, module=module.id).delete() - cached_points = CachedPoints(module.course_instance, student, True) - cached_module, _, _, _ = cached_points.find(module) cached_points.invalidate(module.course_instance, student) return JsonResponse({"success": "deleted"}, status=200) except Exception as e: @@ -636,11 +636,6 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> JsonResponse: if not points_goal.replace('%', '').isdigit() and not points_goal.isdigit(): return JsonResponse({"error": "not_a_number"}, status=400) - # Get the StudentModuleGoal object for the student and module - student = UserProfile.objects.get(id=user_id) - module = CourseModule.objects.get(url=module_slug) - cached_points = CachedPoints(module.course_instance, student, True) - cached_module, _, _, _ = cached_points.find(module) # Points goal can either be an integer or percentage. If the the points goal is given as a percentage, # give it to the points goal directly. Otherwise calculate the points goal by taking the integer # and calculating how much that is of the module's max points