prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Exception in terminology management view
  When visiting https://mozilla.locamotion.org/eu/firefox/terminology/ the following exception is thrown:
  
  `'SortedRelatedManager' object does not support indexing`
  
  
  </issue>
  <code>
  [start of pootle/apps/pootle_terminology/views.py]
  1 # -*- coding: utf-8 -*-
  2 #
  3 # Copyright (C) Pootle contributors.
  4 #
  5 # This file is a part of the Pootle project. It is distributed under the GPL3
  6 # or later license. See the LICENSE file for a copy of the license and the
  7 # AUTHORS file for copyright and authorship information.
  8 
  9 from django.core.urlresolvers import reverse
  10 from django.shortcuts import render
  11 
  12 from pootle.core.decorators import get_path_obj, permission_required
  13 from pootle_app.views.admin import util
  14 from pootle_store.models import Store, Unit
  15 
  16 from .forms import term_unit_form_factory
  17 
  18 
  19 def get_terminology_filename(translation_project):
  20     try:
  21         # See if a terminology store already exists
  22         return translation_project.stores.live().filter(
  23             name__startswith='pootle-terminology.',
  24         ).values_list('name', flat=True)[0]
  25     except IndexError:
  26         pass
  27 
  28     return (
  29         'pootle-terminology.%s'
  30         % translation_project.project.filetypes[0].extension)
  31 
  32 
  33 def manage_store(request, ctx, language, term_store):
  34     TermUnitForm = term_unit_form_factory(term_store)
  35     template_name = 'translation_projects/terminology/manage.html'
  36     return util.edit(request, template_name, Unit, ctx,
  37                      None, None, queryset=term_store.units, can_delete=True,
  38                      form=TermUnitForm)
  39 
  40 
  41 @get_path_obj
  42 @permission_required('administrate')
  43 def manage(request, translation_project):
  44     ctx = {
  45         'page': 'admin-terminology',
  46 
  47         'browse_url': reverse('pootle-tp-browse', kwargs={
  48             'language_code': translation_project.language.code,
  49             'project_code': translation_project.project.code,
  50         }),
  51         'translate_url': reverse('pootle-tp-translate', kwargs={
  52             'language_code': translation_project.language.code,
  53             'project_code': translation_project.project.code,
  54         }),
  55 
  56         'translation_project': translation_project,
  57         'language': translation_project.language,
  58         'project': translation_project.project,
  59         'source_language': translation_project.project.source_language,
  60         'directory': translation_project.directory,
  61     }
  62 
  63     if translation_project.project.is_terminology:
  64         # Which file should we edit?
  65         stores = list(Store.objects.live().filter(
  66             translation_project=translation_project,
  67         ))
  68         if len(stores) == 1:
  69             # There is only one, and we're not going to offer file-level
  70             # activities, so let's just edit the one that is there.
  71             return manage_store(request, ctx, ctx['language'], stores[0])
  72         elif len(stores) > 1:
  73             for store in stores:
  74                 path_length = len(translation_project.pootle_path)
  75                 store.nice_name = store.pootle_path[path_length:]
  76 
  77             ctx['stores'] = stores
  78             return render(request,
  79                           "translation_projects/terminology/stores.html", ctx)
  80 
  81     try:
  82         terminology_filename = get_terminology_filename(translation_project)
  83         term_store = Store.objects.get(
  84             pootle_path=translation_project.pootle_path + terminology_filename,
  85         )
  86         return manage_store(request, ctx, ctx['language'], term_store)
  87     except Store.DoesNotExist:
  88         return render(request, "translation_projects/terminology/manage.html",
  89                       ctx)
  90
  [end of pootle/apps/pootle_terminology/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/pootle/apps/pootle_terminology/views.py b/pootle/apps/pootle_terminology/views.py
  --- a/pootle/apps/pootle_terminology/views.py
  +++ b/pootle/apps/pootle_terminology/views.py
  @@ -27,7 +27,7 @@
   
       return (
           'pootle-terminology.%s'
  -        % translation_project.project.filetypes[0].extension)
  +        % translation_project.project.filetypes.first().extension)
   
   
   def manage_store(request, ctx, language, term_store):
  
verification_info: {"golden_diff": "diff --git a/pootle/apps/pootle_terminology/views.py b/pootle/apps/pootle_terminology/views.py\n--- a/pootle/apps/pootle_terminology/views.py\n+++ b/pootle/apps/pootle_terminology/views.py\n@@ -27,7 +27,7 @@\n \n     return (\n         'pootle-terminology.%s'\n-        % translation_project.project.filetypes[0].extension)\n+        % translation_project.project.filetypes.first().extension)\n \n \n def manage_store(request, ctx, language, term_store):\n", "issue": "Exception in terminology management view\nWhen visiting https://mozilla.locamotion.org/eu/firefox/terminology/ the following exception is thrown:\n\n`'SortedRelatedManager' object does not support indexing`\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nfrom django.core.urlresolvers import reverse\nfrom django.shortcuts import render\n\nfrom pootle.core.decorators import get_path_obj, permission_required\nfrom pootle_app.views.admin import util\nfrom pootle_store.models import Store, Unit\n\nfrom .forms import term_unit_form_factory\n\n\ndef get_terminology_filename(translation_project):\n    try:\n        # See if a terminology store already exists\n        return translation_project.stores.live().filter(\n            name__startswith='pootle-terminology.',\n        ).values_list('name', flat=True)[0]\n    except IndexError:\n        pass\n\n    return (\n        'pootle-terminology.%s'\n        % translation_project.project.filetypes[0].extension)\n\n\ndef manage_store(request, ctx, language, term_store):\n    TermUnitForm = term_unit_form_factory(term_store)\n    template_name = 'translation_projects/terminology/manage.html'\n    return util.edit(request, template_name, Unit, ctx,\n                     None, None, queryset=term_store.units, can_delete=True,\n                     form=TermUnitForm)\n\n\n@get_path_obj\n@permission_required('administrate')\ndef manage(request, translation_project):\n    ctx = {\n        'page': 'admin-terminology',\n\n        'browse_url': reverse('pootle-tp-browse', kwargs={\n            'language_code': translation_project.language.code,\n            'project_code': translation_project.project.code,\n        }),\n        'translate_url': reverse('pootle-tp-translate', kwargs={\n            'language_code': translation_project.language.code,\n            'project_code': translation_project.project.code,\n        }),\n\n        'translation_project': translation_project,\n        'language': translation_project.language,\n        'project': translation_project.project,\n        'source_language': translation_project.project.source_language,\n        'directory': translation_project.directory,\n    }\n\n    if translation_project.project.is_terminology:\n        # Which file should we edit?\n        stores = list(Store.objects.live().filter(\n            translation_project=translation_project,\n        ))\n        if len(stores) == 1:\n            # There is only one, and we're not going to offer file-level\n            # activities, so let's just edit the one that is there.\n            return manage_store(request, ctx, ctx['language'], stores[0])\n        elif len(stores) > 1:\n            for store in stores:\n                path_length = len(translation_project.pootle_path)\n                store.nice_name = store.pootle_path[path_length:]\n\n            ctx['stores'] = stores\n            return render(request,\n                          \"translation_projects/terminology/stores.html\", ctx)\n\n    try:\n        terminology_filename = get_terminology_filename(translation_project)\n        term_store = Store.objects.get(\n            pootle_path=translation_project.pootle_path + terminology_filename,\n        )\n        return manage_store(request, ctx, ctx['language'], term_store)\n    except Store.DoesNotExist:\n        return render(request, \"translation_projects/terminology/manage.html\",\n                      ctx)\n", "path": "pootle/apps/pootle_terminology/views.py"}]}