prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Admin: Search doesn't work well with categories
  Admin > Search > Search for a category
  Why does it say "Products" when it's clearly showing categories?
  Deleted categories are also visible in search. 
  
  ![screenshot from 2018-09-28 22-12-03](https://user-images.githubusercontent.com/40273438/46231259-8aa84280-c36b-11e8-9211-f8e3b0e55697.png)
  
  
  </issue>
  <code>
  [start of shuup/admin/modules/categories/__init__.py]
  1 # -*- coding: utf-8 -*-
  2 # This file is part of Shuup.
  3 #
  4 # Copyright (c) 2012-2018, Shuup Inc. All rights reserved.
  5 #
  6 # This source code is licensed under the OSL-3.0 license found in the
  7 # LICENSE file in the root directory of this source tree.
  8 import six
  9 from django.db.models import Q
  10 from django.utils.translation import ugettext_lazy as _
  11 from filer.models import File
  12 
  13 from shuup.admin.base import AdminModule, MenuEntry, SearchResult
  14 from shuup.admin.menu import PRODUCTS_MENU_CATEGORY
  15 from shuup.admin.utils.permissions import get_default_model_permissions
  16 from shuup.admin.utils.urls import (
  17     admin_url, derive_model_url, get_edit_and_list_urls, get_model_url
  18 )
  19 from shuup.admin.views.home import HelpBlockCategory, SimpleHelpBlock
  20 from shuup.core.models import Category
  21 
  22 
  23 class CategoryModule(AdminModule):
  24     name = _("Categories")
  25     category = _("Products")
  26     breadcrumbs_menu_entry = MenuEntry(text=name, url="shuup_admin:category.list", category=PRODUCTS_MENU_CATEGORY)
  27 
  28     def get_urls(self):
  29         return [
  30             admin_url(
  31                 "^categories/(?P<pk>\d+)/copy-visibility/$",
  32                 "shuup.admin.modules.categories.views.CategoryCopyVisibilityView",
  33                 name="category.copy_visibility",
  34                 permissions=get_default_model_permissions(Category)
  35             ),
  36             admin_url(
  37                 "^categories/(?P<pk>\d+)/delete/$",
  38                 "shuup.admin.modules.categories.views.CategoryDeleteView",
  39                 name="category.delete",
  40                 permissions=get_default_model_permissions(Category)
  41             ),
  42             admin_url(
  43                 "^categories/organize/$",
  44                 "shuup.admin.modules.categories.views.CategoryOrganizeView",
  45                 name="category.organize",
  46                 permissions=get_default_model_permissions(Category)
  47             )
  48         ] + get_edit_and_list_urls(
  49             url_prefix="^categories",
  50             view_template="shuup.admin.modules.categories.views.Category%sView",
  51             name_template="category.%s",
  52             permissions=get_default_model_permissions(Category),
  53         )
  54 
  55     def get_menu_entries(self, request):
  56         return [
  57             MenuEntry(
  58                 text=_("Categories"), icon="fa fa-sitemap",
  59                 url="shuup_admin:category.list", category=PRODUCTS_MENU_CATEGORY, ordering=2
  60             )
  61         ]
  62 
  63     def get_search_results(self, request, query):
  64         minimum_query_length = 3
  65         if len(query) >= minimum_query_length:
  66             categories = Category.objects.filter(
  67                 Q(translations__name__icontains=query) |
  68                 Q(identifier__icontains=query)
  69             ).distinct().order_by("tree_id", "lft")
  70             for i, category in enumerate(categories[:10]):
  71                 relevance = 100 - i
  72                 yield SearchResult(
  73                     text=six.text_type(category),
  74                     url=get_model_url(category),
  75                     category=self.category,
  76                     relevance=relevance
  77                 )
  78 
  79     def get_help_blocks(self, request, kind):
  80         yield SimpleHelpBlock(
  81             text=_("Add a product category to organize your products"),
  82             actions=[{
  83                 "text": _("New category"),
  84                 "url": get_model_url(Category, "new")
  85             }],
  86             icon_url="shuup_admin/img/category.png",
  87             category=HelpBlockCategory.PRODUCTS,
  88             priority=1,
  89             done=Category.objects.filter(shops=request.shop).exists() if kind == "setup" else False
  90         )
  91 
  92     def get_required_permissions(self):
  93         return get_default_model_permissions(Category) | get_default_model_permissions(File)
  94 
  95     def get_model_url(self, object, kind, shop=None):
  96         return derive_model_url(Category, "shuup_admin:category", object, kind)
  97
  [end of shuup/admin/modules/categories/__init__.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/shuup/admin/modules/categories/__init__.py b/shuup/admin/modules/categories/__init__.py
  --- a/shuup/admin/modules/categories/__init__.py
  +++ b/shuup/admin/modules/categories/__init__.py
  @@ -12,6 +12,7 @@
   
   from shuup.admin.base import AdminModule, MenuEntry, SearchResult
   from shuup.admin.menu import PRODUCTS_MENU_CATEGORY
  +from shuup.admin.shop_provider import get_shop
   from shuup.admin.utils.permissions import get_default_model_permissions
   from shuup.admin.utils.urls import (
       admin_url, derive_model_url, get_edit_and_list_urls, get_model_url
  @@ -22,7 +23,7 @@
   
   class CategoryModule(AdminModule):
       name = _("Categories")
  -    category = _("Products")
  +    category = _("Categories")
       breadcrumbs_menu_entry = MenuEntry(text=name, url="shuup_admin:category.list", category=PRODUCTS_MENU_CATEGORY)
   
       def get_urls(self):
  @@ -56,8 +57,10 @@
   
       def get_search_results(self, request, query):
           minimum_query_length = 3
  +
           if len(query) >= minimum_query_length:
  -            categories = Category.objects.filter(
  +            shop = get_shop(request)
  +            categories = Category.objects.all_except_deleted(shop=shop).filter(
                   Q(translations__name__icontains=query) |
                   Q(identifier__icontains=query)
               ).distinct().order_by("tree_id", "lft")
  
verification_info: {"golden_diff": "diff --git a/shuup/admin/modules/categories/__init__.py b/shuup/admin/modules/categories/__init__.py\n--- a/shuup/admin/modules/categories/__init__.py\n+++ b/shuup/admin/modules/categories/__init__.py\n@@ -12,6 +12,7 @@\n \n from shuup.admin.base import AdminModule, MenuEntry, SearchResult\n from shuup.admin.menu import PRODUCTS_MENU_CATEGORY\n+from shuup.admin.shop_provider import get_shop\n from shuup.admin.utils.permissions import get_default_model_permissions\n from shuup.admin.utils.urls import (\n     admin_url, derive_model_url, get_edit_and_list_urls, get_model_url\n@@ -22,7 +23,7 @@\n \n class CategoryModule(AdminModule):\n     name = _(\"Categories\")\n-    category = _(\"Products\")\n+    category = _(\"Categories\")\n     breadcrumbs_menu_entry = MenuEntry(text=name, url=\"shuup_admin:category.list\", category=PRODUCTS_MENU_CATEGORY)\n \n     def get_urls(self):\n@@ -56,8 +57,10 @@\n \n     def get_search_results(self, request, query):\n         minimum_query_length = 3\n+\n         if len(query) >= minimum_query_length:\n-            categories = Category.objects.filter(\n+            shop = get_shop(request)\n+            categories = Category.objects.all_except_deleted(shop=shop).filter(\n                 Q(translations__name__icontains=query) |\n                 Q(identifier__icontains=query)\n             ).distinct().order_by(\"tree_id\", \"lft\")\n", "issue": "Admin: Search doesn't work well with categories\nAdmin > Search > Search for a category\r\nWhy does it say \"Products\" when it's clearly showing categories?\r\nDeleted categories are also visible in search. \r\n\r\n![screenshot from 2018-09-28 22-12-03](https://user-images.githubusercontent.com/40273438/46231259-8aa84280-c36b-11e8-9211-f8e3b0e55697.png)\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# This file is part of Shuup.\n#\n# Copyright (c) 2012-2018, Shuup Inc. All rights reserved.\n#\n# This source code is licensed under the OSL-3.0 license found in the\n# LICENSE file in the root directory of this source tree.\nimport six\nfrom django.db.models import Q\nfrom django.utils.translation import ugettext_lazy as _\nfrom filer.models import File\n\nfrom shuup.admin.base import AdminModule, MenuEntry, SearchResult\nfrom shuup.admin.menu import PRODUCTS_MENU_CATEGORY\nfrom shuup.admin.utils.permissions import get_default_model_permissions\nfrom shuup.admin.utils.urls import (\n    admin_url, derive_model_url, get_edit_and_list_urls, get_model_url\n)\nfrom shuup.admin.views.home import HelpBlockCategory, SimpleHelpBlock\nfrom shuup.core.models import Category\n\n\nclass CategoryModule(AdminModule):\n    name = _(\"Categories\")\n    category = _(\"Products\")\n    breadcrumbs_menu_entry = MenuEntry(text=name, url=\"shuup_admin:category.list\", category=PRODUCTS_MENU_CATEGORY)\n\n    def get_urls(self):\n        return [\n            admin_url(\n                \"^categories/(?P<pk>\\d+)/copy-visibility/$\",\n                \"shuup.admin.modules.categories.views.CategoryCopyVisibilityView\",\n                name=\"category.copy_visibility\",\n                permissions=get_default_model_permissions(Category)\n            ),\n            admin_url(\n                \"^categories/(?P<pk>\\d+)/delete/$\",\n                \"shuup.admin.modules.categories.views.CategoryDeleteView\",\n                name=\"category.delete\",\n                permissions=get_default_model_permissions(Category)\n            ),\n            admin_url(\n                \"^categories/organize/$\",\n                \"shuup.admin.modules.categories.views.CategoryOrganizeView\",\n                name=\"category.organize\",\n                permissions=get_default_model_permissions(Category)\n            )\n        ] + get_edit_and_list_urls(\n            url_prefix=\"^categories\",\n            view_template=\"shuup.admin.modules.categories.views.Category%sView\",\n            name_template=\"category.%s\",\n            permissions=get_default_model_permissions(Category),\n        )\n\n    def get_menu_entries(self, request):\n        return [\n            MenuEntry(\n                text=_(\"Categories\"), icon=\"fa fa-sitemap\",\n                url=\"shuup_admin:category.list\", category=PRODUCTS_MENU_CATEGORY, ordering=2\n            )\n        ]\n\n    def get_search_results(self, request, query):\n        minimum_query_length = 3\n        if len(query) >= minimum_query_length:\n            categories = Category.objects.filter(\n                Q(translations__name__icontains=query) |\n                Q(identifier__icontains=query)\n            ).distinct().order_by(\"tree_id\", \"lft\")\n            for i, category in enumerate(categories[:10]):\n                relevance = 100 - i\n                yield SearchResult(\n                    text=six.text_type(category),\n                    url=get_model_url(category),\n                    category=self.category,\n                    relevance=relevance\n                )\n\n    def get_help_blocks(self, request, kind):\n        yield SimpleHelpBlock(\n            text=_(\"Add a product category to organize your products\"),\n            actions=[{\n                \"text\": _(\"New category\"),\n                \"url\": get_model_url(Category, \"new\")\n            }],\n            icon_url=\"shuup_admin/img/category.png\",\n            category=HelpBlockCategory.PRODUCTS,\n            priority=1,\n            done=Category.objects.filter(shops=request.shop).exists() if kind == \"setup\" else False\n        )\n\n    def get_required_permissions(self):\n        return get_default_model_permissions(Category) | get_default_model_permissions(File)\n\n    def get_model_url(self, object, kind, shop=None):\n        return derive_model_url(Category, \"shuup_admin:category\", object, kind)\n", "path": "shuup/admin/modules/categories/__init__.py"}]}