prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  A user can't download the terminology files from a Terminology project
  I know we switched off download of `pootle-terminology.po` files as they cause a number of problem mostly because there is no associated file.  But this seems to have extended to also include the 'Terminology' project.
  
  I can't recall if at the time we decided it was an OK compromise.  But now with @phlax's work which means we can have non-existent files we should likely be able to bring this back. At the very least we shouldn't be disabling download of files within Terminology ad only restrict `pootle-terminology.po`
  
  
  --- 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_translationproject/views.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 #
  4 # Copyright (C) Pootle contributors.
  5 #
  6 # This file is a part of the Pootle project. It is distributed under the GPL3
  7 # or later license. See the LICENSE file for a copy of the license and the
  8 # AUTHORS file for copyright and authorship information.
  9 
  10 from django.conf import settings
  11 from django.shortcuts import render
  12 
  13 from import_export.views import handle_upload_form
  14 from pootle.core.browser import (get_children, get_table_headings, get_parent,
  15                                  get_vfolders)
  16 from pootle.core.decorators import (get_path_obj, get_resource,
  17                                     permission_required)
  18 from pootle.core.helpers import (get_export_view_context, get_browser_context,
  19                                  get_sidebar_announcements_context,
  20                                  get_translation_context, SIDEBAR_COOKIE_NAME)
  21 from pootle.core.utils.json import jsonify
  22 from pootle_app.models.permissions import check_permission
  23 from pootle_app.views.admin.permissions import admin_permissions as admin_perms
  24 
  25 
  26 @get_path_obj
  27 @permission_required('administrate')
  28 def admin_permissions(request, translation_project):
  29     language = translation_project.language
  30     project = translation_project.project
  31 
  32     ctx = {
  33         'page': 'admin-permissions',
  34 
  35         'translation_project': translation_project,
  36         'project': project,
  37         'language': language,
  38         'directory': translation_project.directory,
  39     }
  40 
  41     return admin_perms(request, translation_project.directory,
  42                        'translation_projects/admin/permissions.html', ctx)
  43 
  44 
  45 @get_path_obj
  46 @permission_required('view')
  47 @get_resource
  48 def browse(request, translation_project, dir_path, filename=None):
  49     project = translation_project.project
  50     language = translation_project.language
  51 
  52     directory = request.directory
  53     store = request.store
  54     is_admin = check_permission('administrate', request)
  55 
  56     ctx, cookie_data = get_sidebar_announcements_context(
  57         request,
  58         (project, language, translation_project, ),
  59     )
  60 
  61     ctx.update(get_browser_context(request))
  62 
  63     # TODO improve plugin logic
  64     if "import_export" in settings.INSTALLED_APPS:
  65         if not translation_project.is_terminology_project:
  66             if request.user.is_authenticated():
  67                 if check_permission('translate', request):
  68                     ctx.update(handle_upload_form(request, project))
  69                 ctx.update({'display_download': True,
  70                             'has_sidebar': True})
  71 
  72     stats = request.resource_obj.get_stats()
  73 
  74     if store is None:
  75         table_fields = ['name', 'progress', 'total', 'need-translation',
  76                         'suggestions', 'critical', 'last-updated', 'activity']
  77         ctx.update({
  78             'table': {
  79                 'id': 'tp',
  80                 'fields': table_fields,
  81                 'headings': get_table_headings(table_fields),
  82                 'items': get_children(directory),
  83             }
  84         })
  85 
  86         if 'virtualfolder' in settings.INSTALLED_APPS:
  87             vfolders = get_vfolders(directory, all_vfolders=is_admin)
  88             if len(vfolders) > 0:
  89                 table_fields = ['name', 'priority', 'progress', 'total',
  90                                 'need-translation', 'suggestions', 'critical',
  91                                 'last-updated', 'activity']
  92                 ctx.update({
  93                     'vfolders': {
  94                         'id': 'vfolders',
  95                         'fields': table_fields,
  96                         'headings': get_table_headings(table_fields),
  97                         'items': vfolders,
  98                     },
  99                 })
  100 
  101                 # FIXME: set vfolders stats in the resource, don't inject them
  102                 # here.
  103                 stats['vfolders'] = {}
  104 
  105                 for vfolder_treeitem in directory.vf_treeitems.iterator():
  106                     if request.user.is_superuser or vfolder_treeitem.is_visible:
  107                         stats['vfolders'][vfolder_treeitem.code] = \
  108                             vfolder_treeitem.get_stats(include_children=False)
  109 
  110     ctx.update({
  111         'parent': get_parent(directory if store is None else store),
  112         'translation_project': translation_project,
  113         'project': project,
  114         'language': language,
  115         'stats': jsonify(stats),
  116         'is_admin': is_admin,
  117         'is_store': store is not None,
  118 
  119         'browser_extends': 'translation_projects/base.html',
  120     })
  121 
  122     response = render(request, 'browser/index.html', ctx)
  123 
  124     if cookie_data:
  125         response.set_cookie(SIDEBAR_COOKIE_NAME, cookie_data)
  126 
  127     return response
  128 
  129 
  130 @get_path_obj
  131 @permission_required('view')
  132 @get_resource
  133 def translate(request, translation_project, dir_path, filename):
  134     project = translation_project.project
  135 
  136     ctx = get_translation_context(request)
  137 
  138     ctx.update({
  139         'language': translation_project.language,
  140         'project': project,
  141         'translation_project': translation_project,
  142 
  143         'editor_extends': 'translation_projects/base.html',
  144     })
  145 
  146     return render(request, "editor/main.html", ctx)
  147 
  148 
  149 @get_path_obj
  150 @permission_required('view')
  151 @get_resource
  152 def export_view(request, translation_project, dir_path, filename=None):
  153     """Displays a list of units with filters applied."""
  154     ctx = get_export_view_context(request)
  155     ctx.update({
  156         'source_language': translation_project.project.source_language,
  157         'language': translation_project.language,
  158         'project': translation_project.project,
  159     })
  160 
  161     return render(request, 'editor/export_view.html', ctx)
  162
  ```
  --- 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/pootle/apps/pootle_translationproject/views.py b/pootle/apps/pootle_translationproject/views.py
  --- a/pootle/apps/pootle_translationproject/views.py
  +++ b/pootle/apps/pootle_translationproject/views.py
  @@ -62,12 +62,11 @@
   
       # TODO improve plugin logic
       if "import_export" in settings.INSTALLED_APPS:
  -        if not translation_project.is_terminology_project:
  -            if request.user.is_authenticated():
  -                if check_permission('translate', request):
  -                    ctx.update(handle_upload_form(request, project))
  -                ctx.update({'display_download': True,
  -                            'has_sidebar': True})
  +        if request.user.is_authenticated():
  +            if check_permission('translate', request):
  +                ctx.update(handle_upload_form(request, project))
  +            ctx.update({'display_download': True,
  +                        'has_sidebar': True})
   
       stats = request.resource_obj.get_stats()
  
verification_info: {"golden_diff": "diff --git a/pootle/apps/pootle_translationproject/views.py b/pootle/apps/pootle_translationproject/views.py\n--- a/pootle/apps/pootle_translationproject/views.py\n+++ b/pootle/apps/pootle_translationproject/views.py\n@@ -62,12 +62,11 @@\n \n     # TODO improve plugin logic\n     if \"import_export\" in settings.INSTALLED_APPS:\n-        if not translation_project.is_terminology_project:\n-            if request.user.is_authenticated():\n-                if check_permission('translate', request):\n-                    ctx.update(handle_upload_form(request, project))\n-                ctx.update({'display_download': True,\n-                            'has_sidebar': True})\n+        if request.user.is_authenticated():\n+            if check_permission('translate', request):\n+                ctx.update(handle_upload_form(request, project))\n+            ctx.update({'display_download': True,\n+                        'has_sidebar': True})\n \n     stats = request.resource_obj.get_stats()\n", "issue": "A user can't download the terminology files from a Terminology project\nI know we switched off download of `pootle-terminology.po` files as they cause a number of problem mostly because there is no associated file.  But this seems to have extended to also include the 'Terminology' project.\n\nI can't recall if at the time we decided it was an OK compromise.  But now with @phlax's work which means we can have non-existent files we should likely be able to bring this back. At the very least we shouldn't be disabling download of files within Terminology ad only restrict `pootle-terminology.po`\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- 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.conf import settings\nfrom django.shortcuts import render\n\nfrom import_export.views import handle_upload_form\nfrom pootle.core.browser import (get_children, get_table_headings, get_parent,\n                                 get_vfolders)\nfrom pootle.core.decorators import (get_path_obj, get_resource,\n                                    permission_required)\nfrom pootle.core.helpers import (get_export_view_context, get_browser_context,\n                                 get_sidebar_announcements_context,\n                                 get_translation_context, SIDEBAR_COOKIE_NAME)\nfrom pootle.core.utils.json import jsonify\nfrom pootle_app.models.permissions import check_permission\nfrom pootle_app.views.admin.permissions import admin_permissions as admin_perms\n\n\n@get_path_obj\n@permission_required('administrate')\ndef admin_permissions(request, translation_project):\n    language = translation_project.language\n    project = translation_project.project\n\n    ctx = {\n        'page': 'admin-permissions',\n\n        'translation_project': translation_project,\n        'project': project,\n        'language': language,\n        'directory': translation_project.directory,\n    }\n\n    return admin_perms(request, translation_project.directory,\n                       'translation_projects/admin/permissions.html', ctx)\n\n\n@get_path_obj\n@permission_required('view')\n@get_resource\ndef browse(request, translation_project, dir_path, filename=None):\n    project = translation_project.project\n    language = translation_project.language\n\n    directory = request.directory\n    store = request.store\n    is_admin = check_permission('administrate', request)\n\n    ctx, cookie_data = get_sidebar_announcements_context(\n        request,\n        (project, language, translation_project, ),\n    )\n\n    ctx.update(get_browser_context(request))\n\n    # TODO improve plugin logic\n    if \"import_export\" in settings.INSTALLED_APPS:\n        if not translation_project.is_terminology_project:\n            if request.user.is_authenticated():\n                if check_permission('translate', request):\n                    ctx.update(handle_upload_form(request, project))\n                ctx.update({'display_download': True,\n                            'has_sidebar': True})\n\n    stats = request.resource_obj.get_stats()\n\n    if store is None:\n        table_fields = ['name', 'progress', 'total', 'need-translation',\n                        'suggestions', 'critical', 'last-updated', 'activity']\n        ctx.update({\n            'table': {\n                'id': 'tp',\n                'fields': table_fields,\n                'headings': get_table_headings(table_fields),\n                'items': get_children(directory),\n            }\n        })\n\n        if 'virtualfolder' in settings.INSTALLED_APPS:\n            vfolders = get_vfolders(directory, all_vfolders=is_admin)\n            if len(vfolders) > 0:\n                table_fields = ['name', 'priority', 'progress', 'total',\n                                'need-translation', 'suggestions', 'critical',\n                                'last-updated', 'activity']\n                ctx.update({\n                    'vfolders': {\n                        'id': 'vfolders',\n                        'fields': table_fields,\n                        'headings': get_table_headings(table_fields),\n                        'items': vfolders,\n                    },\n                })\n\n                # FIXME: set vfolders stats in the resource, don't inject them\n                # here.\n                stats['vfolders'] = {}\n\n                for vfolder_treeitem in directory.vf_treeitems.iterator():\n                    if request.user.is_superuser or vfolder_treeitem.is_visible:\n                        stats['vfolders'][vfolder_treeitem.code] = \\\n                            vfolder_treeitem.get_stats(include_children=False)\n\n    ctx.update({\n        'parent': get_parent(directory if store is None else store),\n        'translation_project': translation_project,\n        'project': project,\n        'language': language,\n        'stats': jsonify(stats),\n        'is_admin': is_admin,\n        'is_store': store is not None,\n\n        'browser_extends': 'translation_projects/base.html',\n    })\n\n    response = render(request, 'browser/index.html', ctx)\n\n    if cookie_data:\n        response.set_cookie(SIDEBAR_COOKIE_NAME, cookie_data)\n\n    return response\n\n\n@get_path_obj\n@permission_required('view')\n@get_resource\ndef translate(request, translation_project, dir_path, filename):\n    project = translation_project.project\n\n    ctx = get_translation_context(request)\n\n    ctx.update({\n        'language': translation_project.language,\n        'project': project,\n        'translation_project': translation_project,\n\n        'editor_extends': 'translation_projects/base.html',\n    })\n\n    return render(request, \"editor/main.html\", ctx)\n\n\n@get_path_obj\n@permission_required('view')\n@get_resource\ndef export_view(request, translation_project, dir_path, filename=None):\n    \"\"\"Displays a list of units with filters applied.\"\"\"\n    ctx = get_export_view_context(request)\n    ctx.update({\n        'source_language': translation_project.project.source_language,\n        'language': translation_project.language,\n        'project': translation_project.project,\n    })\n\n    return render(request, 'editor/export_view.html', ctx)\n", "path": "pootle/apps/pootle_translationproject/views.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- 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.conf import settings\nfrom django.shortcuts import render\n\nfrom import_export.views import handle_upload_form\nfrom pootle.core.browser import (get_children, get_table_headings, get_parent,\n                                 get_vfolders)\nfrom pootle.core.decorators import (get_path_obj, get_resource,\n                                    permission_required)\nfrom pootle.core.helpers import (get_export_view_context, get_browser_context,\n                                 get_sidebar_announcements_context,\n                                 get_translation_context, SIDEBAR_COOKIE_NAME)\nfrom pootle.core.utils.json import jsonify\nfrom pootle_app.models.permissions import check_permission\nfrom pootle_app.views.admin.permissions import admin_permissions as admin_perms\n\n\n@get_path_obj\n@permission_required('administrate')\ndef admin_permissions(request, translation_project):\n    language = translation_project.language\n    project = translation_project.project\n\n    ctx = {\n        'page': 'admin-permissions',\n\n        'translation_project': translation_project,\n        'project': project,\n        'language': language,\n        'directory': translation_project.directory,\n    }\n\n    return admin_perms(request, translation_project.directory,\n                       'translation_projects/admin/permissions.html', ctx)\n\n\n@get_path_obj\n@permission_required('view')\n@get_resource\ndef browse(request, translation_project, dir_path, filename=None):\n    project = translation_project.project\n    language = translation_project.language\n\n    directory = request.directory\n    store = request.store\n    is_admin = check_permission('administrate', request)\n\n    ctx, cookie_data = get_sidebar_announcements_context(\n        request,\n        (project, language, translation_project, ),\n    )\n\n    ctx.update(get_browser_context(request))\n\n    # TODO improve plugin logic\n    if \"import_export\" in settings.INSTALLED_APPS:\n        if request.user.is_authenticated():\n            if check_permission('translate', request):\n                ctx.update(handle_upload_form(request, project))\n            ctx.update({'display_download': True,\n                        'has_sidebar': True})\n\n    stats = request.resource_obj.get_stats()\n\n    if store is None:\n        table_fields = ['name', 'progress', 'total', 'need-translation',\n                        'suggestions', 'critical', 'last-updated', 'activity']\n        ctx.update({\n            'table': {\n                'id': 'tp',\n                'fields': table_fields,\n                'headings': get_table_headings(table_fields),\n                'items': get_children(directory),\n            }\n        })\n\n        if 'virtualfolder' in settings.INSTALLED_APPS:\n            vfolders = get_vfolders(directory, all_vfolders=is_admin)\n            if len(vfolders) > 0:\n                table_fields = ['name', 'priority', 'progress', 'total',\n                                'need-translation', 'suggestions', 'critical',\n                                'last-updated', 'activity']\n                ctx.update({\n                    'vfolders': {\n                        'id': 'vfolders',\n                        'fields': table_fields,\n                        'headings': get_table_headings(table_fields),\n                        'items': vfolders,\n                    },\n                })\n\n                # FIXME: set vfolders stats in the resource, don't inject them\n                # here.\n                stats['vfolders'] = {}\n\n                for vfolder_treeitem in directory.vf_treeitems.iterator():\n                    if request.user.is_superuser or vfolder_treeitem.is_visible:\n                        stats['vfolders'][vfolder_treeitem.code] = \\\n                            vfolder_treeitem.get_stats(include_children=False)\n\n    ctx.update({\n        'parent': get_parent(directory if store is None else store),\n        'translation_project': translation_project,\n        'project': project,\n        'language': language,\n        'stats': jsonify(stats),\n        'is_admin': is_admin,\n        'is_store': store is not None,\n\n        'browser_extends': 'translation_projects/base.html',\n    })\n\n    response = render(request, 'browser/index.html', ctx)\n\n    if cookie_data:\n        response.set_cookie(SIDEBAR_COOKIE_NAME, cookie_data)\n\n    return response\n\n\n@get_path_obj\n@permission_required('view')\n@get_resource\ndef translate(request, translation_project, dir_path, filename):\n    project = translation_project.project\n\n    ctx = get_translation_context(request)\n\n    ctx.update({\n        'language': translation_project.language,\n        'project': project,\n        'translation_project': translation_project,\n\n        'editor_extends': 'translation_projects/base.html',\n    })\n\n    return render(request, \"editor/main.html\", ctx)\n\n\n@get_path_obj\n@permission_required('view')\n@get_resource\ndef export_view(request, translation_project, dir_path, filename=None):\n    \"\"\"Displays a list of units with filters applied.\"\"\"\n    ctx = get_export_view_context(request)\n    ctx.update({\n        'source_language': translation_project.project.source_language,\n        'language': translation_project.language,\n        'project': translation_project.project,\n    })\n\n    return render(request, 'editor/export_view.html', ctx)\n", "path": "pootle/apps/pootle_translationproject/views.py"}]}