prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Abstract jQuery.ajax calls
  Lots of jQuery.ajax calls in JavaScript code, that repeat same structure and part of the same request arguments.
  
  </issue>
  <code>
  [start of src/tcms/comments/views.py]
  1 # -*- coding: utf-8 -*-
  2 
  3 import logging
  4 
  5 from django.conf import settings
  6 from django.contrib.auth.mixins import PermissionRequiredMixin
  7 from django.http import JsonResponse
  8 from django.shortcuts import render
  9 from django.views import generic
  10 from django.views.decorators.http import require_POST
  11 
  12 import django_comments.signals
  13 from django_comments.views.moderation import perform_delete
  14 
  15 from tcms.comments.models import post_comment
  16 from tcms.comments.exceptions import InvalidCommentPostRequest
  17 from tcms.core.responses import JsonResponseBadRequest
  18 
  19 log = logging.getLogger(__name__)
  20 
  21 
  22 @require_POST
  23 def post(request, template_name='comments/comments.html'):
  24     """Post a comment"""
  25     data = request.POST.copy()
  26     try:
  27         target, _ = post_comment(
  28             data, request.user, request.META.get('REMOTE_ADDR'))
  29     except InvalidCommentPostRequest as e:
  30         target = e.target
  31     return render(request, template_name, context={'object': target})
  32 
  33 
  34 class DeleteCommentView(PermissionRequiredMixin, generic.View):
  35     """Delete comment from given objects"""
  36 
  37     permission_required = 'django_comments.can_moderate'
  38 
  39     def post(self, request):
  40         comments = django_comments.get_model().objects.filter(
  41             pk__in=request.POST.getlist('comment_id'),
  42             site__pk=settings.SITE_ID,
  43             is_removed=False,
  44             user_id=request.user.id
  45         )
  46 
  47         if not comments:
  48             return JsonResponseBadRequest({
  49                 'message': 'No incoming comment id exists.'
  50             })
  51 
  52         # Flag the comment as deleted instead of actually deleting it.
  53         for comment in comments:
  54             perform_delete(request, comment)
  55 
  56         return JsonResponse({})
  57
  [end of src/tcms/comments/views.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/src/tcms/comments/views.py b/src/tcms/comments/views.py
  --- a/src/tcms/comments/views.py
  +++ b/src/tcms/comments/views.py
  @@ -5,7 +5,6 @@
   from django.conf import settings
   from django.contrib.auth.mixins import PermissionRequiredMixin
   from django.http import JsonResponse
  -from django.shortcuts import render
   from django.views import generic
   from django.views.decorators.http import require_POST
   
  @@ -27,8 +26,10 @@
           target, _ = post_comment(
               data, request.user, request.META.get('REMOTE_ADDR'))
       except InvalidCommentPostRequest as e:
  -        target = e.target
  -    return render(request, template_name, context={'object': target})
  +        msg = f'Fail to add comment to object {e.target}'
  +        log.exception(msg)
  +        return JsonResponseBadRequest({'message': msg})
  +    return JsonResponse({})
   
   
   class DeleteCommentView(PermissionRequiredMixin, generic.View):
  
verification_info: {"golden_diff": "diff --git a/src/tcms/comments/views.py b/src/tcms/comments/views.py\n--- a/src/tcms/comments/views.py\n+++ b/src/tcms/comments/views.py\n@@ -5,7 +5,6 @@\n from django.conf import settings\n from django.contrib.auth.mixins import PermissionRequiredMixin\n from django.http import JsonResponse\n-from django.shortcuts import render\n from django.views import generic\n from django.views.decorators.http import require_POST\n \n@@ -27,8 +26,10 @@\n         target, _ = post_comment(\n             data, request.user, request.META.get('REMOTE_ADDR'))\n     except InvalidCommentPostRequest as e:\n-        target = e.target\n-    return render(request, template_name, context={'object': target})\n+        msg = f'Fail to add comment to object {e.target}'\n+        log.exception(msg)\n+        return JsonResponseBadRequest({'message': msg})\n+    return JsonResponse({})\n \n \n class DeleteCommentView(PermissionRequiredMixin, generic.View):\n", "issue": "Abstract jQuery.ajax calls\nLots of jQuery.ajax calls in JavaScript code, that repeat same structure and part of the same request arguments.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport logging\n\nfrom django.conf import settings\nfrom django.contrib.auth.mixins import PermissionRequiredMixin\nfrom django.http import JsonResponse\nfrom django.shortcuts import render\nfrom django.views import generic\nfrom django.views.decorators.http import require_POST\n\nimport django_comments.signals\nfrom django_comments.views.moderation import perform_delete\n\nfrom tcms.comments.models import post_comment\nfrom tcms.comments.exceptions import InvalidCommentPostRequest\nfrom tcms.core.responses import JsonResponseBadRequest\n\nlog = logging.getLogger(__name__)\n\n\n@require_POST\ndef post(request, template_name='comments/comments.html'):\n    \"\"\"Post a comment\"\"\"\n    data = request.POST.copy()\n    try:\n        target, _ = post_comment(\n            data, request.user, request.META.get('REMOTE_ADDR'))\n    except InvalidCommentPostRequest as e:\n        target = e.target\n    return render(request, template_name, context={'object': target})\n\n\nclass DeleteCommentView(PermissionRequiredMixin, generic.View):\n    \"\"\"Delete comment from given objects\"\"\"\n\n    permission_required = 'django_comments.can_moderate'\n\n    def post(self, request):\n        comments = django_comments.get_model().objects.filter(\n            pk__in=request.POST.getlist('comment_id'),\n            site__pk=settings.SITE_ID,\n            is_removed=False,\n            user_id=request.user.id\n        )\n\n        if not comments:\n            return JsonResponseBadRequest({\n                'message': 'No incoming comment id exists.'\n            })\n\n        # Flag the comment as deleted instead of actually deleting it.\n        for comment in comments:\n            perform_delete(request, comment)\n\n        return JsonResponse({})\n", "path": "src/tcms/comments/views.py"}]}