Repository: akvo/akvo-rsr

Issue:
Akvo Pages
Akvo Pages with keywords, but without 'only show projects of this partner', will show all updates and all organisations on the Akvo Page.



Discussion:

Resolving patch:
diff --git a/akvo/rsr/views/organisation.py b/akvo/rsr/views/organisation.py
--- a/akvo/rsr/views/organisation.py
+++ b/akvo/rsr/views/organisation.py
@@ -10,7 +10,7 @@
 from django.shortcuts import get_object_or_404, render
 
 from ..filters import remove_empty_querydict_items, OrganisationFilter
-from ..models import Organisation
+from ..models import Organisation, Project
 from ...utils import pagination, filter_query_string
 from .utils import apply_keywords, org_projects, show_filter_class
 
@@ -28,18 +28,20 @@ def _all_organisations():
     )
 
 
+def _all_projects():
+    """Return all active projects."""
+    return Project.objects.published().select_related('partners').order_by('-id')
+
+
 def _page_organisations(page):
     """Dig out the list or organisations to use."""
-    org = page.organisation
-    if page.partner_projects:
-        projects = apply_keywords(page, org_projects(org))
-        return projects.all_partners().select_related(
-            'locations',
-            'primary_location',
-            'published_projects',
-        )
-    else:
-        return _all_organisations()
+    projects = org_projects(page.organisation) if page.partner_projects else _all_projects()
+    keyword_projects = apply_keywords(page, projects)
+    return keyword_projects.all_partners().select_related(
+        'locations',
+        'primary_location',
+        'primary_location__country',
+    )
 
 
 def _organisation_directory_coll(request):
diff --git a/akvo/rsr/views/project.py b/akvo/rsr/views/project.py
--- a/akvo/rsr/views/project.py
+++ b/akvo/rsr/views/project.py
@@ -31,9 +31,6 @@
 
 def _all_projects():
     """Return all active projects."""
-    # return Project.objects.published().select_related().prefetch_related(
-    #     'partners').order_by('-id')
-
     return Project.objects.published().select_related(
         'publishingstatus__status',
         'sync_owner',
@@ -46,14 +43,14 @@ def _all_projects():
         'partners',
     ).order_by('-id')
 
+
 def _page_projects(page):
     """Dig out the list of projects to use.
 
     First get a list based on page settings (orgs or all projects). Then apply
     keywords filtering / exclusion.
     """
-    org = page.organisation
-    projects = org_projects(org) if page.partner_projects else _all_projects()
+    projects = org_projects(page.organisation) if page.partner_projects else _all_projects()
     return apply_keywords(page, projects)
 
 
diff --git a/akvo/rsr/views/project_update.py b/akvo/rsr/views/project_update.py
--- a/akvo/rsr/views/project_update.py
+++ b/akvo/rsr/views/project_update.py
@@ -25,14 +25,16 @@ def _all_updates():
     return ProjectUpdate.objects.select_related().order_by('-id')
 
 
+def _all_projects():
+    """Return all active projects."""
+    return Project.objects.published().select_related('project_updates').order_by('-id')
+
+
 def _page_updates(page):
     """Dig out the list or project updates to use."""
-    org = page.organisation
-    if page.partner_projects:
-        projects = apply_keywords(page, org_projects(org))
-        return projects.all_updates().order_by('-id')
-    else:
-        return _all_updates()
+    projects = org_projects(page.organisation) if page.partner_projects else _all_projects()
+    keyword_projects = apply_keywords(page, projects)
+    return keyword_projects.all_updates().select_related()
 
 
 def _update_directory_coll(request):


Test patch: