We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Creating new organisations from the project editor fails


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `akvo/rest/views/organisation.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 # Akvo RSR is covered by the GNU Affero General Public License.
4 # See more details in the license.txt file located at the root folder of the Akvo RSR module.
5 # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
6 
7 from django.conf import settings
8 from django.db.models import Q
9 from django.utils import six
10 from rest_framework.decorators import api_view
11 from rest_framework.exceptions import ParseError
12 from rest_framework.parsers import JSONParser
13 from rest_framework.response import Response
14 from rest_framework_xml.parsers import XMLParser
15 from rest_framework_xml.compat import etree
16 
17 from akvo.rest.views.utils import int_or_none, get_qs_elements_for_page
18 from akvo.rsr.filters import location_choices, get_m49_filter
19 from akvo.rsr.models import Project, Organisation, Country
20 from akvo.rsr.views.utils import apply_keywords, org_projects
21 from ..serializers import OrganisationSerializer, OrganisationDirectorySerializer
22 from ..viewsets import BaseRSRViewSet
23 
24 
25 class AkvoOrganisationParser(XMLParser):
26     def parse(self, stream, media_type=None, parser_context=None):
27         assert etree, 'XMLParser requires defusedxml to be installed'
28 
29         parser_context = parser_context or {}
30         encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
31         parser = etree.DefusedXMLParser(encoding=encoding)
32         try:
33             tree = etree.parse(stream, parser=parser, forbid_dtd=True)
34         except (etree.ParseError, ValueError) as exc:
35             raise ParseError('XML parse error - %s' % six.text_type(exc))
36         return self.organisation_data_from_etree(tree.getroot())
37 
38     def organisation_data_from_etree(self, tree):
39         def find_text(tree, str):
40             element = tree.find(str)
41             if element is None:
42                 return ''
43             return element.text.strip() if element.text else ""
44 
45         def location_data(location_tree):
46             if location_tree is None:
47                 return []
48             iso_code = find_text(location_tree, 'iso_code').lower()
49             country, created = Country.objects.get_or_create(**Country.fields_from_iso_code(iso_code))
50             country = country.id
51             latitude = find_text(location_tree, 'latitude') or 0
52             longitude = find_text(location_tree, 'longitude') or 0
53             primary = True
54             return [dict(latitude=latitude, longitude=longitude, country=country, primary=primary)]
55 
56         long_name = find_text(tree, 'name')
57         name = long_name[:25]
58         description = find_text(tree, 'description')
59         url = find_text(tree, 'url')
60         iati_type = find_text(tree, 'iati_organisation_type')
61         new_organisation_type = int(iati_type) if iati_type else 22
62         organisation_type = Organisation.org_type_from_iati_type(new_organisation_type)
63         locations = location_data(tree.find('location/object'))
64         return dict(
65             name=name, long_name=long_name, description=description, url=url,
66             organisation_type=organisation_type, new_organisation_type=new_organisation_type,
67             locations=locations
68         )
69 
70 
71 class OrganisationViewSet(BaseRSRViewSet):
72     """
73     API endpoint that allows organisations to be viewed or edited.
74     """
75     queryset = Organisation.objects.all()
76     serializer_class = OrganisationSerializer
77     parser_classes = (AkvoOrganisationParser, JSONParser,)
78 
79 
80 @api_view(['GET'])
81 def organisation_directory(request):
82     """REST view for the update directory."""
83 
84     page = request.rsr_page
85     all_organisations = Organisation.objects.all() if not page else _page_organisations(page)
86 
87     # Filter updates based on query parameters
88     filter_, text_filter = _create_filters_query(request)
89     organisations = (
90         all_organisations.filter(filter_).distinct() if filter_ is not None else all_organisations
91     )
92     organisations_text_filtered = (
93         organisations.filter(text_filter) if text_filter is not None else organisations
94     )
95     if organisations_text_filtered.exists():
96         organisations = organisations_text_filtered
97 
98     # Get the relevant data for typeaheads based on filtered organisations (minus
99     # text filtering, if no organisations were found)
100     locations = [
101         {'id': choice[0], 'name': choice[1]}
102         for choice in location_choices(organisations)
103     ]
104 
105     display_organisations = get_qs_elements_for_page(organisations_text_filtered, request)
106 
107     # Get related objects of page at once
108     response = {
109         'project_count': organisations_text_filtered.count(),
110         'projects': OrganisationDirectorySerializer(display_organisations, many=True).data,
111         'location': locations,
112         'page_size_default': settings.PROJECT_DIRECTORY_PAGE_SIZES[0],
113     }
114     return Response(response)
115 
116 
117 def _public_projects():
118     """Return all public projects."""
119     return Project.objects.public().published().select_related('partners')
120 
121 
122 def _page_organisations(page):
123     """Dig out the list or organisations to use."""
124     projects = org_projects(page.organisation) if page.partner_projects else _public_projects()
125     keyword_projects = apply_keywords(page, projects)
126     return keyword_projects.all_partners()
127 
128 
129 def _create_filters_query(request):
130     """Returns a Q object expression based on query parameters."""
131     location_param = int_or_none(request.GET.get('location'))
132     title_or_subtitle_param = request.GET.get('title_or_subtitle')
133 
134     location_filter = (
135         get_m49_filter(location_param, use_recipient_country=False) if location_param else None
136     )
137     title_filter = (
138         Q(name__icontains=title_or_subtitle_param) |
139         Q(long_name__icontains=title_or_subtitle_param)
140     ) if title_or_subtitle_param else None
141     all_filters = [
142         location_filter,
143     ]
144     filters = filter(None, all_filters)
145     return reduce(lambda x, y: x & y, filters) if filters else None, title_filter
146
```
--- 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/akvo/rest/views/organisation.py b/akvo/rest/views/organisation.py
--- a/akvo/rest/views/organisation.py
+++ b/akvo/rest/views/organisation.py
@@ -9,8 +9,8 @@
 from django.utils import six
 from rest_framework.decorators import api_view
 from rest_framework.exceptions import ParseError
-from rest_framework.parsers import JSONParser
 from rest_framework.response import Response
+from rest_framework.settings import api_settings
 from rest_framework_xml.parsers import XMLParser
 from rest_framework_xml.compat import etree
 
@@ -74,7 +74,7 @@
     """
     queryset = Organisation.objects.all()
     serializer_class = OrganisationSerializer
-    parser_classes = (AkvoOrganisationParser, JSONParser,)
+    parser_classes = [AkvoOrganisationParser] + api_settings.DEFAULT_PARSER_CLASSES
 
 
 @api_view(['GET'])

{"golden_diff": "diff --git a/akvo/rest/views/organisation.py b/akvo/rest/views/organisation.py\n--- a/akvo/rest/views/organisation.py\n+++ b/akvo/rest/views/organisation.py\n@@ -9,8 +9,8 @@\n from django.utils import six\n from rest_framework.decorators import api_view\n from rest_framework.exceptions import ParseError\n-from rest_framework.parsers import JSONParser\n from rest_framework.response import Response\n+from rest_framework.settings import api_settings\n from rest_framework_xml.parsers import XMLParser\n from rest_framework_xml.compat import etree\n \n@@ -74,7 +74,7 @@\n     \"\"\"\n     queryset = Organisation.objects.all()\n     serializer_class = OrganisationSerializer\n-    parser_classes = (AkvoOrganisationParser, JSONParser,)\n+    parser_classes = [AkvoOrganisationParser] + api_settings.DEFAULT_PARSER_CLASSES\n \n \n @api_view(['GET'])\n", "issue": "Creating new organisations from the project editor fails\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Akvo RSR is covered by the GNU Affero General Public License.\n# See more details in the license.txt file located at the root folder of the Akvo RSR module.\n# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\nfrom django.conf import settings\nfrom django.db.models import Q\nfrom django.utils import six\nfrom rest_framework.decorators import api_view\nfrom rest_framework.exceptions import ParseError\nfrom rest_framework.parsers import JSONParser\nfrom rest_framework.response import Response\nfrom rest_framework_xml.parsers import XMLParser\nfrom rest_framework_xml.compat import etree\n\nfrom akvo.rest.views.utils import int_or_none, get_qs_elements_for_page\nfrom akvo.rsr.filters import location_choices, get_m49_filter\nfrom akvo.rsr.models import Project, Organisation, Country\nfrom akvo.rsr.views.utils import apply_keywords, org_projects\nfrom ..serializers import OrganisationSerializer, OrganisationDirectorySerializer\nfrom ..viewsets import BaseRSRViewSet\n\n\nclass AkvoOrganisationParser(XMLParser):\n    def parse(self, stream, media_type=None, parser_context=None):\n        assert etree, 'XMLParser requires defusedxml to be installed'\n\n        parser_context = parser_context or {}\n        encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)\n        parser = etree.DefusedXMLParser(encoding=encoding)\n        try:\n            tree = etree.parse(stream, parser=parser, forbid_dtd=True)\n        except (etree.ParseError, ValueError) as exc:\n            raise ParseError('XML parse error - %s' % six.text_type(exc))\n        return self.organisation_data_from_etree(tree.getroot())\n\n    def organisation_data_from_etree(self, tree):\n        def find_text(tree, str):\n            element = tree.find(str)\n            if element is None:\n                return ''\n            return element.text.strip() if element.text else \"\"\n\n        def location_data(location_tree):\n            if location_tree is None:\n                return []\n            iso_code = find_text(location_tree, 'iso_code').lower()\n            country, created = Country.objects.get_or_create(**Country.fields_from_iso_code(iso_code))\n            country = country.id\n            latitude = find_text(location_tree, 'latitude') or 0\n            longitude = find_text(location_tree, 'longitude') or 0\n            primary = True\n            return [dict(latitude=latitude, longitude=longitude, country=country, primary=primary)]\n\n        long_name = find_text(tree, 'name')\n        name = long_name[:25]\n        description = find_text(tree, 'description')\n        url = find_text(tree, 'url')\n        iati_type = find_text(tree, 'iati_organisation_type')\n        new_organisation_type = int(iati_type) if iati_type else 22\n        organisation_type = Organisation.org_type_from_iati_type(new_organisation_type)\n        locations = location_data(tree.find('location/object'))\n        return dict(\n            name=name, long_name=long_name, description=description, url=url,\n            organisation_type=organisation_type, new_organisation_type=new_organisation_type,\n            locations=locations\n        )\n\n\nclass OrganisationViewSet(BaseRSRViewSet):\n    \"\"\"\n    API endpoint that allows organisations to be viewed or edited.\n    \"\"\"\n    queryset = Organisation.objects.all()\n    serializer_class = OrganisationSerializer\n    parser_classes = (AkvoOrganisationParser, JSONParser,)\n\n\n@api_view(['GET'])\ndef organisation_directory(request):\n    \"\"\"REST view for the update directory.\"\"\"\n\n    page = request.rsr_page\n    all_organisations = Organisation.objects.all() if not page else _page_organisations(page)\n\n    # Filter updates based on query parameters\n    filter_, text_filter = _create_filters_query(request)\n    organisations = (\n        all_organisations.filter(filter_).distinct() if filter_ is not None else all_organisations\n    )\n    organisations_text_filtered = (\n        organisations.filter(text_filter) if text_filter is not None else organisations\n    )\n    if organisations_text_filtered.exists():\n        organisations = organisations_text_filtered\n\n    # Get the relevant data for typeaheads based on filtered organisations (minus\n    # text filtering, if no organisations were found)\n    locations = [\n        {'id': choice[0], 'name': choice[1]}\n        for choice in location_choices(organisations)\n    ]\n\n    display_organisations = get_qs_elements_for_page(organisations_text_filtered, request)\n\n    # Get related objects of page at once\n    response = {\n        'project_count': organisations_text_filtered.count(),\n        'projects': OrganisationDirectorySerializer(display_organisations, many=True).data,\n        'location': locations,\n        'page_size_default': settings.PROJECT_DIRECTORY_PAGE_SIZES[0],\n    }\n    return Response(response)\n\n\ndef _public_projects():\n    \"\"\"Return all public projects.\"\"\"\n    return Project.objects.public().published().select_related('partners')\n\n\ndef _page_organisations(page):\n    \"\"\"Dig out the list or organisations to use.\"\"\"\n    projects = org_projects(page.organisation) if page.partner_projects else _public_projects()\n    keyword_projects = apply_keywords(page, projects)\n    return keyword_projects.all_partners()\n\n\ndef _create_filters_query(request):\n    \"\"\"Returns a Q object expression based on query parameters.\"\"\"\n    location_param = int_or_none(request.GET.get('location'))\n    title_or_subtitle_param = request.GET.get('title_or_subtitle')\n\n    location_filter = (\n        get_m49_filter(location_param, use_recipient_country=False) if location_param else None\n    )\n    title_filter = (\n        Q(name__icontains=title_or_subtitle_param) |\n        Q(long_name__icontains=title_or_subtitle_param)\n    ) if title_or_subtitle_param else None\n    all_filters = [\n        location_filter,\n    ]\n    filters = filter(None, all_filters)\n    return reduce(lambda x, y: x & y, filters) if filters else None, title_filter\n", "path": "akvo/rest/views/organisation.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Akvo RSR is covered by the GNU Affero General Public License.\n# See more details in the license.txt file located at the root folder of the Akvo RSR module.\n# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\nfrom django.conf import settings\nfrom django.db.models import Q\nfrom django.utils import six\nfrom rest_framework.decorators import api_view\nfrom rest_framework.exceptions import ParseError\nfrom rest_framework.response import Response\nfrom rest_framework.settings import api_settings\nfrom rest_framework_xml.parsers import XMLParser\nfrom rest_framework_xml.compat import etree\n\nfrom akvo.rest.views.utils import int_or_none, get_qs_elements_for_page\nfrom akvo.rsr.filters import location_choices, get_m49_filter\nfrom akvo.rsr.models import Project, Organisation, Country\nfrom akvo.rsr.views.utils import apply_keywords, org_projects\nfrom ..serializers import OrganisationSerializer, OrganisationDirectorySerializer\nfrom ..viewsets import BaseRSRViewSet\n\n\nclass AkvoOrganisationParser(XMLParser):\n    def parse(self, stream, media_type=None, parser_context=None):\n        assert etree, 'XMLParser requires defusedxml to be installed'\n\n        parser_context = parser_context or {}\n        encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)\n        parser = etree.DefusedXMLParser(encoding=encoding)\n        try:\n            tree = etree.parse(stream, parser=parser, forbid_dtd=True)\n        except (etree.ParseError, ValueError) as exc:\n            raise ParseError('XML parse error - %s' % six.text_type(exc))\n        return self.organisation_data_from_etree(tree.getroot())\n\n    def organisation_data_from_etree(self, tree):\n        def find_text(tree, str):\n            element = tree.find(str)\n            if element is None:\n                return ''\n            return element.text.strip() if element.text else \"\"\n\n        def location_data(location_tree):\n            if location_tree is None:\n                return []\n            iso_code = find_text(location_tree, 'iso_code').lower()\n            country, created = Country.objects.get_or_create(**Country.fields_from_iso_code(iso_code))\n            country = country.id\n            latitude = find_text(location_tree, 'latitude') or 0\n            longitude = find_text(location_tree, 'longitude') or 0\n            primary = True\n            return [dict(latitude=latitude, longitude=longitude, country=country, primary=primary)]\n\n        long_name = find_text(tree, 'name')\n        name = long_name[:25]\n        description = find_text(tree, 'description')\n        url = find_text(tree, 'url')\n        iati_type = find_text(tree, 'iati_organisation_type')\n        new_organisation_type = int(iati_type) if iati_type else 22\n        organisation_type = Organisation.org_type_from_iati_type(new_organisation_type)\n        locations = location_data(tree.find('location/object'))\n        return dict(\n            name=name, long_name=long_name, description=description, url=url,\n            organisation_type=organisation_type, new_organisation_type=new_organisation_type,\n            locations=locations\n        )\n\n\nclass OrganisationViewSet(BaseRSRViewSet):\n    \"\"\"\n    API endpoint that allows organisations to be viewed or edited.\n    \"\"\"\n    queryset = Organisation.objects.all()\n    serializer_class = OrganisationSerializer\n    parser_classes = [AkvoOrganisationParser] + api_settings.DEFAULT_PARSER_CLASSES\n\n\n@api_view(['GET'])\ndef organisation_directory(request):\n    \"\"\"REST view for the update directory.\"\"\"\n\n    page = request.rsr_page\n    all_organisations = Organisation.objects.all() if not page else _page_organisations(page)\n\n    # Filter updates based on query parameters\n    filter_, text_filter = _create_filters_query(request)\n    organisations = (\n        all_organisations.filter(filter_).distinct() if filter_ is not None else all_organisations\n    )\n    organisations_text_filtered = (\n        organisations.filter(text_filter) if text_filter is not None else organisations\n    )\n    if organisations_text_filtered.exists():\n        organisations = organisations_text_filtered\n\n    # Get the relevant data for typeaheads based on filtered organisations (minus\n    # text filtering, if no organisations were found)\n    locations = [\n        {'id': choice[0], 'name': choice[1]}\n        for choice in location_choices(organisations)\n    ]\n\n    display_organisations = get_qs_elements_for_page(organisations_text_filtered, request)\n\n    # Get related objects of page at once\n    response = {\n        'project_count': organisations_text_filtered.count(),\n        'projects': OrganisationDirectorySerializer(display_organisations, many=True).data,\n        'location': locations,\n        'page_size_default': settings.PROJECT_DIRECTORY_PAGE_SIZES[0],\n    }\n    return Response(response)\n\n\ndef _public_projects():\n    \"\"\"Return all public projects.\"\"\"\n    return Project.objects.public().published().select_related('partners')\n\n\ndef _page_organisations(page):\n    \"\"\"Dig out the list or organisations to use.\"\"\"\n    projects = org_projects(page.organisation) if page.partner_projects else _public_projects()\n    keyword_projects = apply_keywords(page, projects)\n    return keyword_projects.all_partners()\n\n\ndef _create_filters_query(request):\n    \"\"\"Returns a Q object expression based on query parameters.\"\"\"\n    location_param = int_or_none(request.GET.get('location'))\n    title_or_subtitle_param = request.GET.get('title_or_subtitle')\n\n    location_filter = (\n        get_m49_filter(location_param, use_recipient_country=False) if location_param else None\n    )\n    title_filter = (\n        Q(name__icontains=title_or_subtitle_param) |\n        Q(long_name__icontains=title_or_subtitle_param)\n    ) if title_or_subtitle_param else None\n    all_filters = [\n        location_filter,\n    ]\n    filters = filter(None, all_filters)\n    return reduce(lambda x, y: x & y, filters) if filters else None, title_filter\n", "path": "akvo/rest/views/organisation.py"}]}