Repository: kartoza/prj.app

Issue:
We need a view that shows a world map for sponsors
Requested by @aneumann



Discussion:
See https://twitter.com/search?q=timlinux%20inasafe%20downloads&src=typd for an example of what we might produce


Resolving patch:
diff --git a/django_project/changes/urls.py b/django_project/changes/urls.py
--- a/django_project/changes/urls.py
+++ b/django_project/changes/urls.py
@@ -43,6 +43,7 @@
     SponsorDeleteView,
     SponsorCreateView,
     SponsorListView,
+    SponsorWorldMapView,
     JSONSponsorListView,
     SponsorUpdateView,
     PendingSponsorListView,
@@ -204,6 +205,9 @@
     url(regex='^(?P<project_slug>[\w-]+)/sponsor/list/$',
         view=SponsorListView.as_view(),
         name='sponsor-list'),
+    url(regex='^(?P<project_slug>[\w-]+)/sponsor/world-map/$',
+        view=SponsorWorldMapView.as_view(),
+        name='sponsor-world-map'),
     url(regex='^(?P<project_slug>[\w-]+)/sponsor/(?P<slug>[\w-]+)/$',
         view=SponsorDetailView.as_view(),
         name='sponsor-detail'),
diff --git a/django_project/changes/views/sponsor.py b/django_project/changes/views/sponsor.py
--- a/django_project/changes/views/sponsor.py
+++ b/django_project/changes/views/sponsor.py
@@ -158,6 +158,32 @@ def get_queryset(self, queryset=None):
         return self.queryset
 
 
+class SponsorWorldMapView(SponsorMixin, ListView):
+    """World map view for Sponsors."""
+    context_object_name = 'sponsors'
+    template_name = 'sponsor/world-map.html'
+
+    def get_queryset(self, queryset=None):
+        """Get the queryset for this view.
+
+        :param queryset: A query set
+        :type queryset: QuerySet
+
+        :returns: Sponsor Queryset which is filtered by project
+        :rtype: QuerySet
+        :raises: Http404
+        """
+        if self.queryset is None:
+            project_slug = self.kwargs.get('project_slug', None)
+            if project_slug:
+                project = Project.objects.get(slug=project_slug)
+                queryset = SponsorshipPeriod.objects.filter(project=project)
+                return queryset
+            else:
+                raise Http404('Sorry! We could not find your Sponsor!')
+        return self.queryset
+
+
 class SponsorDetailView(SponsorMixin, DetailView):
     """Detail view for Sponsor."""
     context_object_name = 'sponsor'


Test patch:
diff --git a/django_project/changes/tests/test_views.py b/django_project/changes/tests/test_views.py
--- a/django_project/changes/tests/test_views.py
+++ b/django_project/changes/tests/test_views.py
@@ -790,6 +790,18 @@ def test_SponsorListView(self):
         }))
         self.assertEqual(response.status_code, 200)
 
+    def test_SponsorListView(self):
+
+        response = self.client.get(reverse('sponsor-world-map', kwargs={
+            'project_slug': self.project.slug
+        }))
+        self.assertEqual(response.status_code, 200)
+        expected_templates = [
+            'sponsor/world-map.html',
+            u'changes/sponsorshipperiod_list.html'
+        ]
+        self.assertEqual(expected_templates, response.template_name)
+
     def test_SponsorCreateView_with_login(self):
 
         self.client.login(username='timlinux', password='password')