prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Removing category redirects to category update view 
  Confirmation modal contains "update" button that redirects to update view, instead of sending a POST request to remove the category.
  
  
  </issue>
  <code>
  [start of saleor/dashboard/category/views.py]
  1 from django.contrib import messages
  2 from django.shortcuts import get_object_or_404, redirect
  3 from django.template.response import TemplateResponse
  4 from django.utils.translation import ugettext_lazy as _
  5 
  6 from ...product.models import Category
  7 from ..views import staff_member_required
  8 from .forms import CategoryForm
  9 
  10 
  11 @staff_member_required
  12 def category_list(request, root_pk=None):
  13     root = None
  14     path = None
  15     categories = Category.tree.root_nodes()
  16     if root_pk:
  17         root = get_object_or_404(Category, pk=root_pk)
  18         path = root.get_ancestors(include_self=True) if root else []
  19         categories = root.get_children()
  20     ctx = {'categories': categories, 'path': path, 'root': root}
  21     return TemplateResponse(request, 'dashboard/category/list.html', ctx)
  22 
  23 
  24 @staff_member_required
  25 def category_create(request, root_pk=None):
  26     category = Category()
  27     form = CategoryForm(request.POST or None, parent_pk=root_pk)
  28     if form.is_valid():
  29         category = form.save()
  30         messages.success(request, _('Added category %s') % category)
  31         if root_pk:
  32             return redirect('dashboard:category-list', root_pk=root_pk)
  33         else:
  34             return redirect('dashboard:category-list')
  35     ctx = {'category': category, 'form': form}
  36     return TemplateResponse(request, 'dashboard/category/detail.html', ctx)
  37 
  38 
  39 @staff_member_required
  40 def category_edit(request, root_pk=None):
  41     category = get_object_or_404(Category, pk=root_pk)
  42     form = CategoryForm(request.POST or None, instance=category,
  43                         parent_pk=category.parent_id)
  44     status = 200
  45     if form.is_valid():
  46         category = form.save()
  47         messages.success(request, _('Added category %s') % category)
  48         if root_pk:
  49             return redirect('dashboard:category-list', root_pk=root_pk)
  50         else:
  51             return redirect('dashboard:category-list')
  52     elif form.errors:
  53         status = 400
  54     ctx = {'category': category, 'form': form, 'status': status}
  55     template = 'dashboard/category/modal_edit.html'
  56     return TemplateResponse(request, template, ctx, status=status)
  57 
  58 
  59 @staff_member_required
  60 def category_delete(request, pk):
  61     category = get_object_or_404(Category, pk=pk)
  62     if request.method == 'POST':
  63         category.delete()
  64         messages.success(request, _('Deleted category %s') % category)
  65         root_pk = None
  66         if category.parent:
  67             root_pk = category.parent.pk
  68         if root_pk:
  69             return redirect('dashboard:category-list', root_pk=root_pk)
  70         else:
  71             return redirect('dashboard:category-list')
  72     ctx = {'category': category,
  73            'descendants': list(category.get_descendants()),
  74            'products_count': len(category.products.all())}
  75     return TemplateResponse(request,
  76                             'dashboard/category/modal_category_confirm_delete.html',
  77                             ctx)
  78
  [end of saleor/dashboard/category/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/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
  --- a/saleor/dashboard/category/views.py
  +++ b/saleor/dashboard/category/views.py
  @@ -1,4 +1,6 @@
   from django.contrib import messages
  +from django.core.urlresolvers import reverse
  +from django.http import JsonResponse
   from django.shortcuts import get_object_or_404, redirect
   from django.template.response import TemplateResponse
   from django.utils.translation import ugettext_lazy as _
  @@ -66,12 +68,19 @@
           if category.parent:
               root_pk = category.parent.pk
           if root_pk:
  +            if request.is_ajax():
  +                response = {'redirectUrl': reverse(
  +                    'dashboard:category-list', kwargs={'root_pk': root_pk})}
  +                return JsonResponse(response)
               return redirect('dashboard:category-list', root_pk=root_pk)
           else:
  +            if request.is_ajax():
  +                response = {'redirectUrl': reverse('dashboard:category-list')}
  +                return JsonResponse(response)
               return redirect('dashboard:category-list')
       ctx = {'category': category,
              'descendants': list(category.get_descendants()),
              'products_count': len(category.products.all())}
       return TemplateResponse(request,
  -                            'dashboard/category/modal_category_confirm_delete.html',
  +                            'dashboard/category/modal_delete.html',
                               ctx)
  
verification_info: {"golden_diff": "diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py\n--- a/saleor/dashboard/category/views.py\n+++ b/saleor/dashboard/category/views.py\n@@ -1,4 +1,6 @@\n from django.contrib import messages\n+from django.core.urlresolvers import reverse\n+from django.http import JsonResponse\n from django.shortcuts import get_object_or_404, redirect\n from django.template.response import TemplateResponse\n from django.utils.translation import ugettext_lazy as _\n@@ -66,12 +68,19 @@\n         if category.parent:\n             root_pk = category.parent.pk\n         if root_pk:\n+            if request.is_ajax():\n+                response = {'redirectUrl': reverse(\n+                    'dashboard:category-list', kwargs={'root_pk': root_pk})}\n+                return JsonResponse(response)\n             return redirect('dashboard:category-list', root_pk=root_pk)\n         else:\n+            if request.is_ajax():\n+                response = {'redirectUrl': reverse('dashboard:category-list')}\n+                return JsonResponse(response)\n             return redirect('dashboard:category-list')\n     ctx = {'category': category,\n            'descendants': list(category.get_descendants()),\n            'products_count': len(category.products.all())}\n     return TemplateResponse(request,\n-                            'dashboard/category/modal_category_confirm_delete.html',\n+                            'dashboard/category/modal_delete.html',\n                             ctx)\n", "issue": "Removing category redirects to category update view \nConfirmation modal contains \"update\" button that redirects to update view, instead of sending a POST request to remove the category.\n\n", "before_files": [{"content": "from django.contrib import messages\nfrom django.shortcuts import get_object_or_404, redirect\nfrom django.template.response import TemplateResponse\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom ...product.models import Category\nfrom ..views import staff_member_required\nfrom .forms import CategoryForm\n\n\n@staff_member_required\ndef category_list(request, root_pk=None):\n    root = None\n    path = None\n    categories = Category.tree.root_nodes()\n    if root_pk:\n        root = get_object_or_404(Category, pk=root_pk)\n        path = root.get_ancestors(include_self=True) if root else []\n        categories = root.get_children()\n    ctx = {'categories': categories, 'path': path, 'root': root}\n    return TemplateResponse(request, 'dashboard/category/list.html', ctx)\n\n\n@staff_member_required\ndef category_create(request, root_pk=None):\n    category = Category()\n    form = CategoryForm(request.POST or None, parent_pk=root_pk)\n    if form.is_valid():\n        category = form.save()\n        messages.success(request, _('Added category %s') % category)\n        if root_pk:\n            return redirect('dashboard:category-list', root_pk=root_pk)\n        else:\n            return redirect('dashboard:category-list')\n    ctx = {'category': category, 'form': form}\n    return TemplateResponse(request, 'dashboard/category/detail.html', ctx)\n\n\n@staff_member_required\ndef category_edit(request, root_pk=None):\n    category = get_object_or_404(Category, pk=root_pk)\n    form = CategoryForm(request.POST or None, instance=category,\n                        parent_pk=category.parent_id)\n    status = 200\n    if form.is_valid():\n        category = form.save()\n        messages.success(request, _('Added category %s') % category)\n        if root_pk:\n            return redirect('dashboard:category-list', root_pk=root_pk)\n        else:\n            return redirect('dashboard:category-list')\n    elif form.errors:\n        status = 400\n    ctx = {'category': category, 'form': form, 'status': status}\n    template = 'dashboard/category/modal_edit.html'\n    return TemplateResponse(request, template, ctx, status=status)\n\n\n@staff_member_required\ndef category_delete(request, pk):\n    category = get_object_or_404(Category, pk=pk)\n    if request.method == 'POST':\n        category.delete()\n        messages.success(request, _('Deleted category %s') % category)\n        root_pk = None\n        if category.parent:\n            root_pk = category.parent.pk\n        if root_pk:\n            return redirect('dashboard:category-list', root_pk=root_pk)\n        else:\n            return redirect('dashboard:category-list')\n    ctx = {'category': category,\n           'descendants': list(category.get_descendants()),\n           'products_count': len(category.products.all())}\n    return TemplateResponse(request,\n                            'dashboard/category/modal_category_confirm_delete.html',\n                            ctx)\n", "path": "saleor/dashboard/category/views.py"}]}