prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Translation Memory Maintenance - Delete Entries
  It would be good to be able to maintain the TM in one way or the other.
  
  Perhaps 
  - [ ] Search & Replace in TM
  - [ ] Search & Delete entries in TM
  
  Or perhpas, as a "simple" (?) starting point, giving the translator the option to delete single entries from the TM when they see the result list in **Automatic Suggestions**. Like perhaps:
  
  - [ ] Delete single entry in **Automatic Suggestions** view:
  ![image](https://user-images.githubusercontent.com/26718215/130028004-4e00f2f1-0d30-4ddb-a904-d351711ee610.png)
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `weblate/memory/machine.py`
  Content:
  ```
  1 #
  2 # Copyright © 2012–2022 Michal Čihař <michal@cihar.com>
  3 #
  4 # This file is part of Weblate <https://weblate.org/>
  5 #
  6 # This program is free software: you can redistribute it and/or modify
  7 # it under the terms of the GNU General Public License as published by
  8 # the Free Software Foundation, either version 3 of the License, or
  9 # (at your option) any later version.
  10 #
  11 # This program is distributed in the hope that it will be useful,
  12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 # GNU General Public License for more details.
  15 #
  16 # You should have received a copy of the GNU General Public License
  17 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  18 #
  19 
  20 from weblate.machinery.base import MachineTranslation, get_machinery_language
  21 from weblate.memory.models import Memory
  22 
  23 
  24 class WeblateMemory(MachineTranslation):
  25     """Translation service using strings already translated in Weblate."""
  26 
  27     name = "Weblate Translation Memory"
  28     rank_boost = 2
  29     cache_translations = False
  30     same_languages = True
  31     accounting_key = "internal"
  32     do_cleanup = False
  33 
  34     def convert_language(self, language):
  35         """No conversion of language object."""
  36         return get_machinery_language(language)
  37 
  38     def is_supported(self, source, language):
  39         """Any language is supported."""
  40         return True
  41 
  42     def is_rate_limited(self):
  43         """This service has no rate limiting."""
  44         return False
  45 
  46     def download_translations(
  47         self,
  48         source,
  49         language,
  50         text: str,
  51         unit,
  52         user,
  53         search: bool,
  54         threshold: int = 75,
  55     ):
  56         """Download list of possible translations from a service."""
  57         for result in Memory.objects.lookup(
  58             source,
  59             language,
  60             text,
  61             user,
  62             unit.translation.component.project,
  63             unit.translation.component.project.use_shared_tm,
  64         ).iterator():
  65             quality = self.comparer.similarity(text, result.source)
  66             if quality < 10 or (quality < threshold and not search):
  67                 continue
  68             yield {
  69                 "text": result.target,
  70                 "quality": quality,
  71                 "service": self.name,
  72                 "origin": result.get_origin_display(),
  73                 "source": result.source,
  74                 "show_quality": True,
  75             }
  76
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/weblate/memory/machine.py b/weblate/memory/machine.py
  --- a/weblate/memory/machine.py
  +++ b/weblate/memory/machine.py
  @@ -17,6 +17,8 @@
   # along with this program.  If not, see <https://www.gnu.org/licenses/>.
   #
   
  +from django.urls import reverse
  +
   from weblate.machinery.base import MachineTranslation, get_machinery_language
   from weblate.memory.models import Memory
   
  @@ -72,4 +74,7 @@
                   "origin": result.get_origin_display(),
                   "source": result.source,
                   "show_quality": True,
  +                "delete_url": reverse("api:memory-detail", kwargs={"pk": result.id})
  +                if user is not None and user.has_perm("memory.delete", result)
  +                else None,
               }
  
verification_info: {"golden_diff": "diff --git a/weblate/memory/machine.py b/weblate/memory/machine.py\n--- a/weblate/memory/machine.py\n+++ b/weblate/memory/machine.py\n@@ -17,6 +17,8 @@\n # along with this program.  If not, see <https://www.gnu.org/licenses/>.\n #\n \n+from django.urls import reverse\n+\n from weblate.machinery.base import MachineTranslation, get_machinery_language\n from weblate.memory.models import Memory\n \n@@ -72,4 +74,7 @@\n                 \"origin\": result.get_origin_display(),\n                 \"source\": result.source,\n                 \"show_quality\": True,\n+                \"delete_url\": reverse(\"api:memory-detail\", kwargs={\"pk\": result.id})\n+                if user is not None and user.has_perm(\"memory.delete\", result)\n+                else None,\n             }\n", "issue": "Translation Memory Maintenance - Delete Entries\nIt would be good to be able to maintain the TM in one way or the other.\r\n\r\nPerhaps \r\n- [ ] Search & Replace in TM\r\n- [ ] Search & Delete entries in TM\r\n\r\nOr perhpas, as a \"simple\" (?) starting point, giving the translator the option to delete single entries from the TM when they see the result list in **Automatic Suggestions**. Like perhaps:\r\n\r\n- [ ] Delete single entry in **Automatic Suggestions** view:\r\n![image](https://user-images.githubusercontent.com/26718215/130028004-4e00f2f1-0d30-4ddb-a904-d351711ee610.png)\r\n\r\n\n", "before_files": [{"content": "#\n# Copyright \u00a9 2012\u20132022 Michal \u010ciha\u0159 <michal@cihar.com>\n#\n# This file is part of Weblate <https://weblate.org/>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program.  If not, see <https://www.gnu.org/licenses/>.\n#\n\nfrom weblate.machinery.base import MachineTranslation, get_machinery_language\nfrom weblate.memory.models import Memory\n\n\nclass WeblateMemory(MachineTranslation):\n    \"\"\"Translation service using strings already translated in Weblate.\"\"\"\n\n    name = \"Weblate Translation Memory\"\n    rank_boost = 2\n    cache_translations = False\n    same_languages = True\n    accounting_key = \"internal\"\n    do_cleanup = False\n\n    def convert_language(self, language):\n        \"\"\"No conversion of language object.\"\"\"\n        return get_machinery_language(language)\n\n    def is_supported(self, source, language):\n        \"\"\"Any language is supported.\"\"\"\n        return True\n\n    def is_rate_limited(self):\n        \"\"\"This service has no rate limiting.\"\"\"\n        return False\n\n    def download_translations(\n        self,\n        source,\n        language,\n        text: str,\n        unit,\n        user,\n        search: bool,\n        threshold: int = 75,\n    ):\n        \"\"\"Download list of possible translations from a service.\"\"\"\n        for result in Memory.objects.lookup(\n            source,\n            language,\n            text,\n            user,\n            unit.translation.component.project,\n            unit.translation.component.project.use_shared_tm,\n        ).iterator():\n            quality = self.comparer.similarity(text, result.source)\n            if quality < 10 or (quality < threshold and not search):\n                continue\n            yield {\n                \"text\": result.target,\n                \"quality\": quality,\n                \"service\": self.name,\n                \"origin\": result.get_origin_display(),\n                \"source\": result.source,\n                \"show_quality\": True,\n            }\n", "path": "weblate/memory/machine.py"}], "after_files": [{"content": "#\n# Copyright \u00a9 2012\u20132022 Michal \u010ciha\u0159 <michal@cihar.com>\n#\n# This file is part of Weblate <https://weblate.org/>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program.  If not, see <https://www.gnu.org/licenses/>.\n#\n\nfrom django.urls import reverse\n\nfrom weblate.machinery.base import MachineTranslation, get_machinery_language\nfrom weblate.memory.models import Memory\n\n\nclass WeblateMemory(MachineTranslation):\n    \"\"\"Translation service using strings already translated in Weblate.\"\"\"\n\n    name = \"Weblate Translation Memory\"\n    rank_boost = 2\n    cache_translations = False\n    same_languages = True\n    accounting_key = \"internal\"\n    do_cleanup = False\n\n    def convert_language(self, language):\n        \"\"\"No conversion of language object.\"\"\"\n        return get_machinery_language(language)\n\n    def is_supported(self, source, language):\n        \"\"\"Any language is supported.\"\"\"\n        return True\n\n    def is_rate_limited(self):\n        \"\"\"This service has no rate limiting.\"\"\"\n        return False\n\n    def download_translations(\n        self,\n        source,\n        language,\n        text: str,\n        unit,\n        user,\n        search: bool,\n        threshold: int = 75,\n    ):\n        \"\"\"Download list of possible translations from a service.\"\"\"\n        for result in Memory.objects.lookup(\n            source,\n            language,\n            text,\n            user,\n            unit.translation.component.project,\n            unit.translation.component.project.use_shared_tm,\n        ).iterator():\n            quality = self.comparer.similarity(text, result.source)\n            if quality < 10 or (quality < threshold and not search):\n                continue\n            yield {\n                \"text\": result.target,\n                \"quality\": quality,\n                \"service\": self.name,\n                \"origin\": result.get_origin_display(),\n                \"source\": result.source,\n                \"show_quality\": True,\n                \"delete_url\": reverse(\"api:memory-detail\", kwargs={\"pk\": result.id})\n                if user is not None and user.has_perm(\"memory.delete\", result)\n                else None,\n            }\n", "path": "weblate/memory/machine.py"}]}