Repository: akvo/akvo-rsr

Issue:
urgent: projects missing iggwater.akvoapp.org
Created via Reamaze:

Link: https://rsrsupport.reamaze.com/admin/conversations/urgent-projects-missing-iggwater-dot-akvoapp-dot-org
Assignee: Anthony Gonzalez

Message:
Hi RSR-team,

Just wanted to visit iggwater.akvoapp.org, but somehow all projects that were previously shown there are gone and the page is now empty. Can you look into this?

Cheers,
Annabelle Poelert
Project Officer

Akvo • 's-Gravenhekje 1A • 1011 TG • Amsterdam (NL)
T +31 20 8200 175 • S Annabelle.akvo • T @annabellepoel I www.akvo.org &lt;http://www.akvo.org/&gt;



Discussion:

Resolving patch:
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
@@ -40,7 +40,7 @@ def _project_directory_coll(request):
     """Dig out and pass correct projects to the view."""
     page = request.rsr_page
     return (
-        page.organisation.published_projects() if page is not None
+        page.projects() if page is not None
         else Project.objects.public().published()
     )
 


Test patch:
diff --git a/akvo/rsr/tests/views/test_project.py b/akvo/rsr/tests/views/test_project.py
--- a/akvo/rsr/tests/views/test_project.py
+++ b/akvo/rsr/tests/views/test_project.py
@@ -15,7 +15,7 @@
 from django.conf import settings
 from django.test import Client, TestCase
 
-from akvo.rsr.models import Organisation
+from akvo.rsr.models import Keyword, Organisation, PartnerSite, Partnership, Project
 
 
 @skip('Needs Django >= 1.8')
@@ -84,3 +84,95 @@ def test_should_replace_page_size_limit_parameter(self):
         self.assertIn(page_limit_1, response.content)
         self.assertIn(page_limit_2, response.content)
         self.assertIn(page_limit_3, response.content)
+
+    def test_should_show_keyword_projects_in_partner_site(self):
+        # Given
+        hostname = 'akvo'
+        partner_projects = False
+        org = Organisation.objects.create(name=hostname)
+        keyword = Keyword.objects.create(label=hostname)
+        partner_site = PartnerSite.objects.create(
+            hostname=hostname,
+            partner_projects=partner_projects,
+            organisation=org,
+            piwik_id=10,
+        )
+        partner_site.keywords.add(keyword)
+        project_title = '{} awesome project'.format(hostname)
+        project = Project.objects.create(title=project_title)
+        project.keywords.add(keyword)
+        project.publishingstatus.status = 'published'
+        project.publishingstatus.save()
+        url = '/en/projects/'
+        self.c = Client(HTTP_HOST='{}.{}'.format(hostname, settings.AKVOAPP_DOMAIN))
+
+        # When
+        response = self.c.get(url, follow=True)
+
+        # Then
+        self.assertIn(project_title, response.content)
+
+    def test_should_show_all_partner_projects(self):
+        # Given
+        hostname = 'akvo'
+        partner_projects = True
+        org = Organisation.objects.create(name=hostname)
+        PartnerSite.objects.create(
+            hostname=hostname,
+            partner_projects=partner_projects,
+            organisation=org,
+            piwik_id=10,
+        )
+        project_title1 = '{} awesome project {}'.format(hostname, 1)
+        project1 = Project.objects.create(title=project_title1)
+        project1.publishingstatus.status = 'published'
+        project1.publishingstatus.save()
+        Partnership.objects.create(organisation=org, project=project1)
+        project_title2 = '{} awesome project {}'.format(hostname, 2)
+        project2 = Project.objects.create(title=project_title2)
+        project2.publishingstatus.status = 'published'
+        project2.publishingstatus.save()
+        Partnership.objects.create(organisation=org, project=project2)
+        url = '/en/projects/'
+        self.c = Client(HTTP_HOST='{}.{}'.format(hostname, settings.AKVOAPP_DOMAIN))
+
+        # When
+        response = self.c.get(url, follow=True)
+
+        # Then
+        self.assertIn(project_title1, response.content)
+        self.assertIn(project_title2, response.content)
+
+    def test_should_show_partner_projects_with_keyword(self):
+        # Given
+        hostname = 'akvo'
+        partner_projects = True
+        org = Organisation.objects.create(name=hostname)
+        keyword = Keyword.objects.create(label=hostname)
+        partner_site = PartnerSite.objects.create(
+            hostname=hostname,
+            partner_projects=partner_projects,
+            organisation=org,
+            piwik_id=10,
+        )
+        partner_site.keywords.add(keyword)
+        project_title1 = '{} awesome project {}'.format(hostname, 1)
+        project1 = Project.objects.create(title=project_title1)
+        project1.keywords.add(keyword)
+        project1.publishingstatus.status = 'published'
+        project1.publishingstatus.save()
+        Partnership.objects.create(organisation=org, project=project1)
+        project_title2 = '{} awesome project {}'.format(hostname, 2)
+        project2 = Project.objects.create(title=project_title2)
+        project2.publishingstatus.status = 'published'
+        project2.publishingstatus.save()
+        Partnership.objects.create(organisation=org, project=project2)
+        url = '/en/projects/'
+        self.c = Client(HTTP_HOST='{}.{}'.format(hostname, settings.AKVOAPP_DOMAIN))
+
+        # When
+        response = self.c.get(url, follow=True)
+
+        # Then
+        self.assertIn(project_title1, response.content)
+        self.assertNotIn(project_title2, response.content)