We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Project list widget throws an internal server error
## Test plan

GIVEN the 'Grab a widget' page

WHEN a project has no partners
THEN the project list and project map options should not be available

WHEN a project has partners
THEN all widgets should be available and not display an error
## Issue description

The project list widget gives an internal server error. And the map widget as well: http://sentry.support.akvo-ops.org/rsr/live/group/727/. This is due to the fact that they don't have a reporting organisation and the map and project listing widgets expect an organisation as an input.

The reporting organisation here should be changed to the project's primary organisation, and we should create a 404 exception when the project has no partners at all, just in case.


--- 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/rsr/views/widgets.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """Akvo RSR is covered by the GNU Affero General Public License.
3 
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 
8 from __future__ import absolute_import
9 
10 import random
11 
12 from django.shortcuts import get_object_or_404
13 from django.views.generic import TemplateView
14 from akvo.rsr.models import Organisation, Project
15 
16 
17 __all__ = [
18     'ProjectMapView',
19     'CobrandedBannerView',
20     'ProjectNarrowView',
21 ]
22 
23 
24 class BaseWidgetView(TemplateView):
25 
26     """Setup a common base widget."""
27 
28     def get_context_data(self, **kwargs):
29         context = super(BaseWidgetView, self).get_context_data(**kwargs)
30         context['style'] = 'darkBG'
31         if self.request.GET.get('style') == 'light':
32             context['style'] = 'lightBG'
33         return context
34 
35 
36 class ProjectBaseWidgetView(BaseWidgetView):
37 
38     """Extends the base widget with a project from url."""
39 
40     def get_context_data(self, **kwargs):
41         context = super(ProjectBaseWidgetView, self).get_context_data(**kwargs)
42         context['project'] = get_object_or_404(
43             Project, pk=int(self.kwargs['project_id']))
44         return context
45 
46 
47 class RandomBaseWidgetView(BaseWidgetView):
48 
49     """Extends the base widget with random project."""
50 
51     def get_context_data(self, **kwargs):
52         context = super(RandomBaseWidgetView, self).get_context_data(**kwargs)
53         org_id = self.request.GET.get('organisation_id', '0')
54         organisation = get_object_or_404(Organisation, pk=org_id)
55         context['project'] = random.choice(organisation.active_projects())
56         return context
57 
58 
59 class CobrandedBannerView(ProjectBaseWidgetView):
60     template_name = 'widgets/cobranded_banner.html'
61 
62 
63 class RandomCobrandedBannerView(RandomBaseWidgetView):
64     template_name = 'widgets/cobranded_banner.html'
65 
66 
67 class ProjectNarrowView(ProjectBaseWidgetView):
68     template_name = 'widgets/project_narrow.html'
69 
70 
71 class RandomProjectNarrowView(RandomBaseWidgetView):
72     template_name = 'widgets/project_narrow.html'
73 
74 
75 class ProjectSmallView(ProjectBaseWidgetView):
76     template_name = 'widgets/project_small.html'
77 
78 
79 class RandomProjectSmallView(RandomBaseWidgetView):
80     template_name = 'widgets/project_small.html'
81 
82 
83 class ProjectListView(BaseWidgetView):
84     template_name = 'widgets/project_list.html'
85 
86     def get_context_data(self, **kwargs):
87         context = super(ProjectListView, self).get_context_data(**kwargs)
88         order_by = self.request.GET.get('order_by', 'title')
89         org_id = self.request.GET.get('organisation_id', '0')
90         organisation = get_object_or_404(Organisation, pk=org_id)
91         projects = Project.objects.select_related(
92             'publishingstatus__status',
93             'primary_location',
94             'primary_location__country'
95         ).prefetch_related(
96             'last_update'
97         ).filter(
98             partnerships__organisation__id=org_id,
99             publishingstatus__status__exact='published'
100         ).order_by('-id').distinct()
101 
102         if order_by == 'status':
103             projects = projects.order_by('status', 'title')
104         elif order_by == 'last_update':
105             projects = projects.order_by('-last_update', 'title')
106         elif order_by in ['budget', 'funds_needed']:
107             projects = projects.extra(order_by=['-%s' % order_by, 'title'])
108         else:
109             projects = projects.order_by('title')  # default to project title
110 
111         context['organisation'] = organisation
112         context['projects_count'] = projects.count()  # Limit to 100 projects
113         context['projects'] = projects[:100]  # Limit to 100 projects
114         return context
115 
116 
117 class ProjectMapView(BaseWidgetView):
118     template_name = 'widgets/projects_map.html'
119 
120     def get_context_data(self, **kwargs):
121         context = super(ProjectMapView, self).get_context_data(**kwargs)
122         context['height'] = self.request.GET.get('height', '300')
123         context['heightpx'] = str(int(context['height']) - 30) + 'px'
124         context['width'] = self.request.GET.get('width', '600')
125         context['widthpx'] = str(context['width']) + 'px'
126         context['style'] = self.request.GET.get('style', 'dark')
127         context['state'] = self.request.GET.get('state', 'dynamic')
128         org_id = self.request.GET.get('organisation_id', '0')
129         org = get_object_or_404(Organisation, pk=org_id)
130         context['projects'] = org.published_projects()
131         return context
132
```
--- 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/rsr/views/widgets.py b/akvo/rsr/views/widgets.py
--- a/akvo/rsr/views/widgets.py
+++ b/akvo/rsr/views/widgets.py
@@ -86,7 +86,7 @@
     def get_context_data(self, **kwargs):
         context = super(ProjectListView, self).get_context_data(**kwargs)
         order_by = self.request.GET.get('order_by', 'title')
-        org_id = self.request.GET.get('organisation_id', '0')
+        org_id = self.request.GET.get('organisation_id')
         organisation = get_object_or_404(Organisation, pk=org_id)
         projects = Project.objects.select_related(
             'publishingstatus__status',
@@ -125,7 +125,7 @@
         context['widthpx'] = str(context['width']) + 'px'
         context['style'] = self.request.GET.get('style', 'dark')
         context['state'] = self.request.GET.get('state', 'dynamic')
-        org_id = self.request.GET.get('organisation_id', '0')
+        org_id = self.request.GET.get('organisation_id')
         org = get_object_or_404(Organisation, pk=org_id)
         context['projects'] = org.published_projects()
         return context

{"golden_diff": "diff --git a/akvo/rsr/views/widgets.py b/akvo/rsr/views/widgets.py\n--- a/akvo/rsr/views/widgets.py\n+++ b/akvo/rsr/views/widgets.py\n@@ -86,7 +86,7 @@\n     def get_context_data(self, **kwargs):\n         context = super(ProjectListView, self).get_context_data(**kwargs)\n         order_by = self.request.GET.get('order_by', 'title')\n-        org_id = self.request.GET.get('organisation_id', '0')\n+        org_id = self.request.GET.get('organisation_id')\n         organisation = get_object_or_404(Organisation, pk=org_id)\n         projects = Project.objects.select_related(\n             'publishingstatus__status',\n@@ -125,7 +125,7 @@\n         context['widthpx'] = str(context['width']) + 'px'\n         context['style'] = self.request.GET.get('style', 'dark')\n         context['state'] = self.request.GET.get('state', 'dynamic')\n-        org_id = self.request.GET.get('organisation_id', '0')\n+        org_id = self.request.GET.get('organisation_id')\n         org = get_object_or_404(Organisation, pk=org_id)\n         context['projects'] = org.published_projects()\n         return context\n", "issue": "Project list widget throws an internal server error\n## Test plan\n\nGIVEN the 'Grab a widget' page\n\nWHEN a project has no partners\nTHEN the project list and project map options should not be available\n\nWHEN a project has partners\nTHEN all widgets should be available and not display an error\n## Issue description\n\nThe project list widget gives an internal server error. And the map widget as well: http://sentry.support.akvo-ops.org/rsr/live/group/727/. This is due to the fact that they don't have a reporting organisation and the map and project listing widgets expect an organisation as an input.\n\nThe reporting organisation here should be changed to the project's primary organisation, and we should create a 404 exception when the project has no partners at all, just in case.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Akvo RSR is covered by the GNU Affero General Public License.\n\nSee more details in the license.txt file located at the root folder of the Akvo RSR module.\nFor additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom __future__ import absolute_import\n\nimport random\n\nfrom django.shortcuts import get_object_or_404\nfrom django.views.generic import TemplateView\nfrom akvo.rsr.models import Organisation, Project\n\n\n__all__ = [\n    'ProjectMapView',\n    'CobrandedBannerView',\n    'ProjectNarrowView',\n]\n\n\nclass BaseWidgetView(TemplateView):\n\n    \"\"\"Setup a common base widget.\"\"\"\n\n    def get_context_data(self, **kwargs):\n        context = super(BaseWidgetView, self).get_context_data(**kwargs)\n        context['style'] = 'darkBG'\n        if self.request.GET.get('style') == 'light':\n            context['style'] = 'lightBG'\n        return context\n\n\nclass ProjectBaseWidgetView(BaseWidgetView):\n\n    \"\"\"Extends the base widget with a project from url.\"\"\"\n\n    def get_context_data(self, **kwargs):\n        context = super(ProjectBaseWidgetView, self).get_context_data(**kwargs)\n        context['project'] = get_object_or_404(\n            Project, pk=int(self.kwargs['project_id']))\n        return context\n\n\nclass RandomBaseWidgetView(BaseWidgetView):\n\n    \"\"\"Extends the base widget with random project.\"\"\"\n\n    def get_context_data(self, **kwargs):\n        context = super(RandomBaseWidgetView, self).get_context_data(**kwargs)\n        org_id = self.request.GET.get('organisation_id', '0')\n        organisation = get_object_or_404(Organisation, pk=org_id)\n        context['project'] = random.choice(organisation.active_projects())\n        return context\n\n\nclass CobrandedBannerView(ProjectBaseWidgetView):\n    template_name = 'widgets/cobranded_banner.html'\n\n\nclass RandomCobrandedBannerView(RandomBaseWidgetView):\n    template_name = 'widgets/cobranded_banner.html'\n\n\nclass ProjectNarrowView(ProjectBaseWidgetView):\n    template_name = 'widgets/project_narrow.html'\n\n\nclass RandomProjectNarrowView(RandomBaseWidgetView):\n    template_name = 'widgets/project_narrow.html'\n\n\nclass ProjectSmallView(ProjectBaseWidgetView):\n    template_name = 'widgets/project_small.html'\n\n\nclass RandomProjectSmallView(RandomBaseWidgetView):\n    template_name = 'widgets/project_small.html'\n\n\nclass ProjectListView(BaseWidgetView):\n    template_name = 'widgets/project_list.html'\n\n    def get_context_data(self, **kwargs):\n        context = super(ProjectListView, self).get_context_data(**kwargs)\n        order_by = self.request.GET.get('order_by', 'title')\n        org_id = self.request.GET.get('organisation_id', '0')\n        organisation = get_object_or_404(Organisation, pk=org_id)\n        projects = Project.objects.select_related(\n            'publishingstatus__status',\n            'primary_location',\n            'primary_location__country'\n        ).prefetch_related(\n            'last_update'\n        ).filter(\n            partnerships__organisation__id=org_id,\n            publishingstatus__status__exact='published'\n        ).order_by('-id').distinct()\n\n        if order_by == 'status':\n            projects = projects.order_by('status', 'title')\n        elif order_by == 'last_update':\n            projects = projects.order_by('-last_update', 'title')\n        elif order_by in ['budget', 'funds_needed']:\n            projects = projects.extra(order_by=['-%s' % order_by, 'title'])\n        else:\n            projects = projects.order_by('title')  # default to project title\n\n        context['organisation'] = organisation\n        context['projects_count'] = projects.count()  # Limit to 100 projects\n        context['projects'] = projects[:100]  # Limit to 100 projects\n        return context\n\n\nclass ProjectMapView(BaseWidgetView):\n    template_name = 'widgets/projects_map.html'\n\n    def get_context_data(self, **kwargs):\n        context = super(ProjectMapView, self).get_context_data(**kwargs)\n        context['height'] = self.request.GET.get('height', '300')\n        context['heightpx'] = str(int(context['height']) - 30) + 'px'\n        context['width'] = self.request.GET.get('width', '600')\n        context['widthpx'] = str(context['width']) + 'px'\n        context['style'] = self.request.GET.get('style', 'dark')\n        context['state'] = self.request.GET.get('state', 'dynamic')\n        org_id = self.request.GET.get('organisation_id', '0')\n        org = get_object_or_404(Organisation, pk=org_id)\n        context['projects'] = org.published_projects()\n        return context\n", "path": "akvo/rsr/views/widgets.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Akvo RSR is covered by the GNU Affero General Public License.\n\nSee more details in the license.txt file located at the root folder of the Akvo RSR module.\nFor additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom __future__ import absolute_import\n\nimport random\n\nfrom django.shortcuts import get_object_or_404\nfrom django.views.generic import TemplateView\nfrom akvo.rsr.models import Organisation, Project\n\n\n__all__ = [\n    'ProjectMapView',\n    'CobrandedBannerView',\n    'ProjectNarrowView',\n]\n\n\nclass BaseWidgetView(TemplateView):\n\n    \"\"\"Setup a common base widget.\"\"\"\n\n    def get_context_data(self, **kwargs):\n        context = super(BaseWidgetView, self).get_context_data(**kwargs)\n        context['style'] = 'darkBG'\n        if self.request.GET.get('style') == 'light':\n            context['style'] = 'lightBG'\n        return context\n\n\nclass ProjectBaseWidgetView(BaseWidgetView):\n\n    \"\"\"Extends the base widget with a project from url.\"\"\"\n\n    def get_context_data(self, **kwargs):\n        context = super(ProjectBaseWidgetView, self).get_context_data(**kwargs)\n        context['project'] = get_object_or_404(\n            Project, pk=int(self.kwargs['project_id']))\n        return context\n\n\nclass RandomBaseWidgetView(BaseWidgetView):\n\n    \"\"\"Extends the base widget with random project.\"\"\"\n\n    def get_context_data(self, **kwargs):\n        context = super(RandomBaseWidgetView, self).get_context_data(**kwargs)\n        org_id = self.request.GET.get('organisation_id', '0')\n        organisation = get_object_or_404(Organisation, pk=org_id)\n        context['project'] = random.choice(organisation.active_projects())\n        return context\n\n\nclass CobrandedBannerView(ProjectBaseWidgetView):\n    template_name = 'widgets/cobranded_banner.html'\n\n\nclass RandomCobrandedBannerView(RandomBaseWidgetView):\n    template_name = 'widgets/cobranded_banner.html'\n\n\nclass ProjectNarrowView(ProjectBaseWidgetView):\n    template_name = 'widgets/project_narrow.html'\n\n\nclass RandomProjectNarrowView(RandomBaseWidgetView):\n    template_name = 'widgets/project_narrow.html'\n\n\nclass ProjectSmallView(ProjectBaseWidgetView):\n    template_name = 'widgets/project_small.html'\n\n\nclass RandomProjectSmallView(RandomBaseWidgetView):\n    template_name = 'widgets/project_small.html'\n\n\nclass ProjectListView(BaseWidgetView):\n    template_name = 'widgets/project_list.html'\n\n    def get_context_data(self, **kwargs):\n        context = super(ProjectListView, self).get_context_data(**kwargs)\n        order_by = self.request.GET.get('order_by', 'title')\n        org_id = self.request.GET.get('organisation_id')\n        organisation = get_object_or_404(Organisation, pk=org_id)\n        projects = Project.objects.select_related(\n            'publishingstatus__status',\n            'primary_location',\n            'primary_location__country'\n        ).prefetch_related(\n            'last_update'\n        ).filter(\n            partnerships__organisation__id=org_id,\n            publishingstatus__status__exact='published'\n        ).order_by('-id').distinct()\n\n        if order_by == 'status':\n            projects = projects.order_by('status', 'title')\n        elif order_by == 'last_update':\n            projects = projects.order_by('-last_update', 'title')\n        elif order_by in ['budget', 'funds_needed']:\n            projects = projects.extra(order_by=['-%s' % order_by, 'title'])\n        else:\n            projects = projects.order_by('title')  # default to project title\n\n        context['organisation'] = organisation\n        context['projects_count'] = projects.count()  # Limit to 100 projects\n        context['projects'] = projects[:100]  # Limit to 100 projects\n        return context\n\n\nclass ProjectMapView(BaseWidgetView):\n    template_name = 'widgets/projects_map.html'\n\n    def get_context_data(self, **kwargs):\n        context = super(ProjectMapView, self).get_context_data(**kwargs)\n        context['height'] = self.request.GET.get('height', '300')\n        context['heightpx'] = str(int(context['height']) - 30) + 'px'\n        context['width'] = self.request.GET.get('width', '600')\n        context['widthpx'] = str(context['width']) + 'px'\n        context['style'] = self.request.GET.get('style', 'dark')\n        context['state'] = self.request.GET.get('state', 'dynamic')\n        org_id = self.request.GET.get('organisation_id')\n        org = get_object_or_404(Organisation, pk=org_id)\n        context['projects'] = org.published_projects()\n        return context\n", "path": "akvo/rsr/views/widgets.py"}]}