prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Show project's locations in EUTF Syria custom project report.
  
  
  --- 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/py_reports/results_indicators_with_map_pdf_reports.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 
  3 """Akvo RSR is covered by the GNU Affero General Public License.
  4 
  5 See more details in the license.txt file located at the root folder of the
  6 Akvo RSR module. For additional details on the GNU license please
  7 see < http://www.gnu.org/licenses/agpl.html >.
  8 """
  9 
  10 from akvo.rsr.models import Project, Country, Organisation, IndicatorPeriod
  11 from akvo.rsr.staticmap import get_staticmap_url, Coordinate, Size
  12 from datetime import datetime
  13 from django.contrib.auth.decorators import login_required
  14 from django.db.models import Q
  15 from django.http import HttpResponse, HttpResponseBadRequest
  16 from django.shortcuts import get_object_or_404
  17 from django.template.loader import render_to_string
  18 
  19 from . import utils
  20 
  21 
  22 @login_required
  23 def render_organisation_projects_results_indicators_map_overview(request, org_id):
  24     country = request.GET.get('country', '').strip()
  25     if not country:
  26         return HttpResponseBadRequest('Please provide the country code!')
  27 
  28     show_comment = True if request.GET.get('comment', '').strip() == 'true' else False
  29     start_date = utils.parse_date(request.GET.get('start_date', '').strip(), datetime(1900, 1, 1))
  30     end_date = utils.parse_date(request.GET.get('end_date', '').strip(), datetime(2999, 12, 31))
  31 
  32     country = get_object_or_404(Country, iso_code=country)
  33     organisation = get_object_or_404(
  34         Organisation.objects.prefetch_related(
  35             'projects',
  36             'projects__results',
  37             'projects__results__indicators',
  38             'projects__results__indicators__periods'
  39         ),
  40         pk=org_id
  41     )
  42     projects = organisation.all_projects().filter(primary_location__country=country)
  43     coordinates = [
  44         Coordinate(p.primary_location.latitude, p.primary_location.longitude)
  45         for p
  46         in projects
  47         if p.primary_location
  48     ]
  49 
  50     now = datetime.today()
  51 
  52     html = render_to_string(
  53         'reports/organisation-projects-results-indicators-map-overview.html',
  54         context={
  55             'title': 'Results and indicators overview for projects in {}'.format(country.name),
  56             'staticmap': get_staticmap_url(coordinates, Size(900, 600)),
  57             'projects': [build_view_object(p, start_date, end_date) for p in projects],
  58             'show_comment': show_comment,
  59             'today': now.strftime('%d-%b-%Y'),
  60         }
  61     )
  62 
  63     if request.GET.get('show-html', ''):
  64         return HttpResponse(html)
  65 
  66     filename = '{}-{}-{}-projects-results-indicators-overview.pdf'.format(
  67         now.strftime('%Y%b%d'), organisation.id, country.iso_code
  68     )
  69 
  70     return utils.make_pdf_response(html, filename)
  71 
  72 
  73 @login_required
  74 def render_project_results_indicators_map_overview(request, project_id):
  75     return _render_project_report(request, project_id, with_map=True)
  76 
  77 
  78 @login_required
  79 def render_project_results_indicators_overview(request, project_id):
  80     return _render_project_report(request, project_id, with_disaggregation=True)
  81 
  82 
  83 def build_view_object(project, start_date=None, end_date=None):
  84     results = {}
  85     periods = IndicatorPeriod.objects\
  86         .select_related('indicator', 'indicator__result')\
  87         .prefetch_related('disaggregations')\
  88         .filter(indicator__result__project=project)
  89     if start_date and end_date:
  90         periods = periods.filter(
  91             Q(period_start__isnull=True) | Q(period_start__gte=start_date),
  92             Q(period_end__isnull=True) | Q(period_end__lte=end_date)
  93         )
  94     for period in periods:
  95         indicator = period.indicator
  96         result = indicator.result
  97         if result.id not in results:
  98             results[result.id] = {'item': result, 'indicators': {}}
  99         if indicator.id not in results[result.id]['indicators']:
  100             results[result.id]['indicators'][indicator.id] = {'item': indicator, 'periods': []}
  101         results[result.id]['indicators'][indicator.id]['periods'].append(period)
  102     return utils.ProjectProxy(project, results)
  103 
  104 
  105 def _render_project_report(request, project_id, with_map=False, with_disaggregation=False):
  106     show_comment = True if request.GET.get('comment', '').strip() == 'true' else False
  107     start_date = utils.parse_date(request.GET.get('start_date', '').strip(), datetime(1900, 1, 1))
  108     end_date = utils.parse_date(request.GET.get('end_date', '').strip(), datetime(2999, 12, 31))
  109 
  110     project = get_object_or_404(
  111         Project.objects.prefetch_related(
  112             'partners',
  113             'related_projects',
  114             'related_to_projects',
  115             'results',
  116             'results__indicators',
  117             'results__indicators__periods',
  118             'results__indicators__periods__disaggregations'
  119         ),
  120         pk=project_id
  121     )
  122     project_location = project.primary_location
  123     locations = [project_location]
  124     if project.parents().count():
  125         locations.append(project.parents().first().primary_location)
  126     if project.children().count():
  127         for child in project.children_all().published():
  128             locations.append(child.primary_location)
  129 
  130     if with_map:
  131         coordinates = [Coordinate(loc.latitude, loc.longitude) for loc in locations if loc]
  132 
  133     now = datetime.today()
  134 
  135     html = render_to_string(
  136         'reports/project-results-indicators-map-overview.html',
  137         context={
  138             'project': build_view_object(project, start_date, end_date),
  139             'location': ", ".join([
  140                 _f
  141                 for _f
  142                 in [project_location.city, getattr(project_location.country, 'name', None)]
  143                 if _f
  144             ]) if project_location else "",
  145             'staticmap': get_staticmap_url(coordinates, Size(900, 600)) if with_map else None,
  146             'show_comment': show_comment,
  147             'show_disaggregations': with_disaggregation,
  148             'today': now.strftime('%d-%b-%Y'),
  149         }
  150     )
  151 
  152     if request.GET.get('show-html', ''):
  153         return HttpResponse(html)
  154 
  155     filename = '{}-{}-results-indicators{}-overview.pdf'.format(
  156         now.strftime('%Y%b%d'), project.id, '-map' if with_map else '')
  157 
  158     return utils.make_pdf_response(html, filename)
  159
  ```
  --- 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/akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py b/akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py
  --- a/akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py
  +++ b/akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py
  @@ -109,6 +109,7 @@
   
       project = get_object_or_404(
           Project.objects.prefetch_related(
  +            'locations',
               'partners',
               'related_projects',
               'related_to_projects',
  @@ -120,14 +121,10 @@
           pk=project_id
       )
       project_location = project.primary_location
  -    locations = [project_location]
  -    if project.parents().count():
  -        locations.append(project.parents().first().primary_location)
  -    if project.children().count():
  -        for child in project.children_all().published():
  -            locations.append(child.primary_location)
  +    coordinates = None
   
       if with_map:
  +        locations = project.locations.all()
           coordinates = [Coordinate(loc.latitude, loc.longitude) for loc in locations if loc]
   
       now = datetime.today()
  
verification_info: {"golden_diff": "diff --git a/akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py b/akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py\n--- a/akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py\n+++ b/akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py\n@@ -109,6 +109,7 @@\n \n     project = get_object_or_404(\n         Project.objects.prefetch_related(\n+            'locations',\n             'partners',\n             'related_projects',\n             'related_to_projects',\n@@ -120,14 +121,10 @@\n         pk=project_id\n     )\n     project_location = project.primary_location\n-    locations = [project_location]\n-    if project.parents().count():\n-        locations.append(project.parents().first().primary_location)\n-    if project.children().count():\n-        for child in project.children_all().published():\n-            locations.append(child.primary_location)\n+    coordinates = None\n \n     if with_map:\n+        locations = project.locations.all()\n         coordinates = [Coordinate(loc.latitude, loc.longitude) for loc in locations if loc]\n \n     now = datetime.today()\n", "issue": "Show project's locations in EUTF Syria custom project report.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\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\nAkvo RSR module. For additional details on the GNU license please\nsee < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom akvo.rsr.models import Project, Country, Organisation, IndicatorPeriod\nfrom akvo.rsr.staticmap import get_staticmap_url, Coordinate, Size\nfrom datetime import datetime\nfrom django.contrib.auth.decorators import login_required\nfrom django.db.models import Q\nfrom django.http import HttpResponse, HttpResponseBadRequest\nfrom django.shortcuts import get_object_or_404\nfrom django.template.loader import render_to_string\n\nfrom . import utils\n\n\n@login_required\ndef render_organisation_projects_results_indicators_map_overview(request, org_id):\n    country = request.GET.get('country', '').strip()\n    if not country:\n        return HttpResponseBadRequest('Please provide the country code!')\n\n    show_comment = True if request.GET.get('comment', '').strip() == 'true' else False\n    start_date = utils.parse_date(request.GET.get('start_date', '').strip(), datetime(1900, 1, 1))\n    end_date = utils.parse_date(request.GET.get('end_date', '').strip(), datetime(2999, 12, 31))\n\n    country = get_object_or_404(Country, iso_code=country)\n    organisation = get_object_or_404(\n        Organisation.objects.prefetch_related(\n            'projects',\n            'projects__results',\n            'projects__results__indicators',\n            'projects__results__indicators__periods'\n        ),\n        pk=org_id\n    )\n    projects = organisation.all_projects().filter(primary_location__country=country)\n    coordinates = [\n        Coordinate(p.primary_location.latitude, p.primary_location.longitude)\n        for p\n        in projects\n        if p.primary_location\n    ]\n\n    now = datetime.today()\n\n    html = render_to_string(\n        'reports/organisation-projects-results-indicators-map-overview.html',\n        context={\n            'title': 'Results and indicators overview for projects in {}'.format(country.name),\n            'staticmap': get_staticmap_url(coordinates, Size(900, 600)),\n            'projects': [build_view_object(p, start_date, end_date) for p in projects],\n            'show_comment': show_comment,\n            'today': now.strftime('%d-%b-%Y'),\n        }\n    )\n\n    if request.GET.get('show-html', ''):\n        return HttpResponse(html)\n\n    filename = '{}-{}-{}-projects-results-indicators-overview.pdf'.format(\n        now.strftime('%Y%b%d'), organisation.id, country.iso_code\n    )\n\n    return utils.make_pdf_response(html, filename)\n\n\n@login_required\ndef render_project_results_indicators_map_overview(request, project_id):\n    return _render_project_report(request, project_id, with_map=True)\n\n\n@login_required\ndef render_project_results_indicators_overview(request, project_id):\n    return _render_project_report(request, project_id, with_disaggregation=True)\n\n\ndef build_view_object(project, start_date=None, end_date=None):\n    results = {}\n    periods = IndicatorPeriod.objects\\\n        .select_related('indicator', 'indicator__result')\\\n        .prefetch_related('disaggregations')\\\n        .filter(indicator__result__project=project)\n    if start_date and end_date:\n        periods = periods.filter(\n            Q(period_start__isnull=True) | Q(period_start__gte=start_date),\n            Q(period_end__isnull=True) | Q(period_end__lte=end_date)\n        )\n    for period in periods:\n        indicator = period.indicator\n        result = indicator.result\n        if result.id not in results:\n            results[result.id] = {'item': result, 'indicators': {}}\n        if indicator.id not in results[result.id]['indicators']:\n            results[result.id]['indicators'][indicator.id] = {'item': indicator, 'periods': []}\n        results[result.id]['indicators'][indicator.id]['periods'].append(period)\n    return utils.ProjectProxy(project, results)\n\n\ndef _render_project_report(request, project_id, with_map=False, with_disaggregation=False):\n    show_comment = True if request.GET.get('comment', '').strip() == 'true' else False\n    start_date = utils.parse_date(request.GET.get('start_date', '').strip(), datetime(1900, 1, 1))\n    end_date = utils.parse_date(request.GET.get('end_date', '').strip(), datetime(2999, 12, 31))\n\n    project = get_object_or_404(\n        Project.objects.prefetch_related(\n            'partners',\n            'related_projects',\n            'related_to_projects',\n            'results',\n            'results__indicators',\n            'results__indicators__periods',\n            'results__indicators__periods__disaggregations'\n        ),\n        pk=project_id\n    )\n    project_location = project.primary_location\n    locations = [project_location]\n    if project.parents().count():\n        locations.append(project.parents().first().primary_location)\n    if project.children().count():\n        for child in project.children_all().published():\n            locations.append(child.primary_location)\n\n    if with_map:\n        coordinates = [Coordinate(loc.latitude, loc.longitude) for loc in locations if loc]\n\n    now = datetime.today()\n\n    html = render_to_string(\n        'reports/project-results-indicators-map-overview.html',\n        context={\n            'project': build_view_object(project, start_date, end_date),\n            'location': \", \".join([\n                _f\n                for _f\n                in [project_location.city, getattr(project_location.country, 'name', None)]\n                if _f\n            ]) if project_location else \"\",\n            'staticmap': get_staticmap_url(coordinates, Size(900, 600)) if with_map else None,\n            'show_comment': show_comment,\n            'show_disaggregations': with_disaggregation,\n            'today': now.strftime('%d-%b-%Y'),\n        }\n    )\n\n    if request.GET.get('show-html', ''):\n        return HttpResponse(html)\n\n    filename = '{}-{}-results-indicators{}-overview.pdf'.format(\n        now.strftime('%Y%b%d'), project.id, '-map' if with_map else '')\n\n    return utils.make_pdf_response(html, filename)\n", "path": "akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\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\nAkvo RSR module. For additional details on the GNU license please\nsee < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom akvo.rsr.models import Project, Country, Organisation, IndicatorPeriod\nfrom akvo.rsr.staticmap import get_staticmap_url, Coordinate, Size\nfrom datetime import datetime\nfrom django.contrib.auth.decorators import login_required\nfrom django.db.models import Q\nfrom django.http import HttpResponse, HttpResponseBadRequest\nfrom django.shortcuts import get_object_or_404\nfrom django.template.loader import render_to_string\n\nfrom . import utils\n\n\n@login_required\ndef render_organisation_projects_results_indicators_map_overview(request, org_id):\n    country = request.GET.get('country', '').strip()\n    if not country:\n        return HttpResponseBadRequest('Please provide the country code!')\n\n    show_comment = True if request.GET.get('comment', '').strip() == 'true' else False\n    start_date = utils.parse_date(request.GET.get('start_date', '').strip(), datetime(1900, 1, 1))\n    end_date = utils.parse_date(request.GET.get('end_date', '').strip(), datetime(2999, 12, 31))\n\n    country = get_object_or_404(Country, iso_code=country)\n    organisation = get_object_or_404(\n        Organisation.objects.prefetch_related(\n            'projects',\n            'projects__results',\n            'projects__results__indicators',\n            'projects__results__indicators__periods'\n        ),\n        pk=org_id\n    )\n    projects = organisation.all_projects().filter(primary_location__country=country)\n    coordinates = [\n        Coordinate(p.primary_location.latitude, p.primary_location.longitude)\n        for p\n        in projects\n        if p.primary_location\n    ]\n\n    now = datetime.today()\n\n    html = render_to_string(\n        'reports/organisation-projects-results-indicators-map-overview.html',\n        context={\n            'title': 'Results and indicators overview for projects in {}'.format(country.name),\n            'staticmap': get_staticmap_url(coordinates, Size(900, 600)),\n            'projects': [build_view_object(p, start_date, end_date) for p in projects],\n            'show_comment': show_comment,\n            'today': now.strftime('%d-%b-%Y'),\n        }\n    )\n\n    if request.GET.get('show-html', ''):\n        return HttpResponse(html)\n\n    filename = '{}-{}-{}-projects-results-indicators-overview.pdf'.format(\n        now.strftime('%Y%b%d'), organisation.id, country.iso_code\n    )\n\n    return utils.make_pdf_response(html, filename)\n\n\n@login_required\ndef render_project_results_indicators_map_overview(request, project_id):\n    return _render_project_report(request, project_id, with_map=True)\n\n\n@login_required\ndef render_project_results_indicators_overview(request, project_id):\n    return _render_project_report(request, project_id, with_disaggregation=True)\n\n\ndef build_view_object(project, start_date=None, end_date=None):\n    results = {}\n    periods = IndicatorPeriod.objects\\\n        .select_related('indicator', 'indicator__result')\\\n        .prefetch_related('disaggregations')\\\n        .filter(indicator__result__project=project)\n    if start_date and end_date:\n        periods = periods.filter(\n            Q(period_start__isnull=True) | Q(period_start__gte=start_date),\n            Q(period_end__isnull=True) | Q(period_end__lte=end_date)\n        )\n    for period in periods:\n        indicator = period.indicator\n        result = indicator.result\n        if result.id not in results:\n            results[result.id] = {'item': result, 'indicators': {}}\n        if indicator.id not in results[result.id]['indicators']:\n            results[result.id]['indicators'][indicator.id] = {'item': indicator, 'periods': []}\n        results[result.id]['indicators'][indicator.id]['periods'].append(period)\n    return utils.ProjectProxy(project, results)\n\n\ndef _render_project_report(request, project_id, with_map=False, with_disaggregation=False):\n    show_comment = True if request.GET.get('comment', '').strip() == 'true' else False\n    start_date = utils.parse_date(request.GET.get('start_date', '').strip(), datetime(1900, 1, 1))\n    end_date = utils.parse_date(request.GET.get('end_date', '').strip(), datetime(2999, 12, 31))\n\n    project = get_object_or_404(\n        Project.objects.prefetch_related(\n            'locations',\n            'partners',\n            'related_projects',\n            'related_to_projects',\n            'results',\n            'results__indicators',\n            'results__indicators__periods',\n            'results__indicators__periods__disaggregations'\n        ),\n        pk=project_id\n    )\n    project_location = project.primary_location\n    coordinates = None\n\n    if with_map:\n        locations = project.locations.all()\n        coordinates = [Coordinate(loc.latitude, loc.longitude) for loc in locations if loc]\n\n    now = datetime.today()\n\n    html = render_to_string(\n        'reports/project-results-indicators-map-overview.html',\n        context={\n            'project': build_view_object(project, start_date, end_date),\n            'location': \", \".join([\n                _f\n                for _f\n                in [project_location.city, getattr(project_location.country, 'name', None)]\n                if _f\n            ]) if project_location else \"\",\n            'staticmap': get_staticmap_url(coordinates, Size(900, 600)) if with_map else None,\n            'show_comment': show_comment,\n            'show_disaggregations': with_disaggregation,\n            'today': now.strftime('%d-%b-%Y'),\n        }\n    )\n\n    if request.GET.get('show-html', ''):\n        return HttpResponse(html)\n\n    filename = '{}-{}-results-indicators{}-overview.pdf'.format(\n        now.strftime('%Y%b%d'), project.id, '-map' if with_map else '')\n\n    return utils.make_pdf_response(html, filename)\n", "path": "akvo/rsr/views/py_reports/results_indicators_with_map_pdf_reports.py"}]}