We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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`


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pootle/apps/pootle_terminology/views.py`
Content:
```
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 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()

```

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):

{"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"}], "after_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.first().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"}]}