Repository: kartoza/prj.app

Issue:
Sponsors for a release need to be filtered for the project and the date
There is a serious bug with the sponsors whereby if you set the release date for a release in one project, it will show on the release page sponsors from any other project.

<img width="1387" alt="screen shot 2016-03-31 at 13 36 43" src="https://cloud.githubusercontent.com/assets/178003/14167536/1eff7c90-f746-11e5-9a2e-ed648c9d22d6.png">

Note that you need to have a date for the version otherwise it does not replicate:

<img width="1210" alt="screen shot 2016-03-31 at 13 37 21" src="https://cloud.githubusercontent.com/assets/178003/14167565/50e68c58-f746-11e5-96b6-e59970bf6c14.png">



Discussion:

Resolving patch:
diff --git a/django_project/changes/models/version.py b/django_project/changes/models/version.py
--- a/django_project/changes/models/version.py
+++ b/django_project/changes/models/version.py
@@ -188,8 +188,9 @@ def categories(self):
     def sponsors(self):
         """Return a list of sponsors current at time of this version release.
 
-        :returns: A list of SponsorPeriod objects whose release date coincides
-            with the version release date. Only approved sponsors are returned.
+        :returns: A list of SponsorPeriod objects for current project
+            whose release date coincides with the version release date.
+            Only approved sponsors are returned.
             Returns None if the release date (which is optional) is not set.
         :rtype: Queryset, None
         """
@@ -197,7 +198,8 @@ def sponsors(self):
             return None
         sponsors = SponsorshipPeriod.approved_objects.filter(
                 end_date__gte=self.release_date).filter(
-                start_date__lte=self.release_date).order_by(
+                start_date__lte=self.release_date).filter(
+                project=self.project).order_by(
             'start_date').order_by(
             '-sponsorship_level__value')
         return sponsors


Test patch:
diff --git a/django_project/changes/tests/test_models.py b/django_project/changes/tests/test_models.py
--- a/django_project/changes/tests/test_models.py
+++ b/django_project/changes/tests/test_models.py
@@ -211,20 +211,22 @@ def setUp(self):
         """
         pass
 
-    def test_sponsors(self):
+    def test_Version_Sponsors(self):
         """
         Tests version sponsors
         """
         project = ProjectF.create()
+
+        sponsorship_period = SponsorshipPeriodF.create()
         data = {
-            'name': u'New Project Name',
-            'description': u'New description',
+            'start_date': u'2016-01-01',
+            'end_date': u'2016-02-01',
             'approved': True,
             'private': False,
-            'slug': u'new-project-slug'
+            'project_id': project.pk,
         }
-        project.__dict__.update(data)
-        project.save()
+        sponsorship_period.__dict__.update(data)
+        sponsorship_period.save()
 
         version_model = VersionF.create()
         data = {
@@ -232,31 +234,12 @@ def test_sponsors(self):
             'description': u'New description',
             'approved': True,
             'release_date': u'2016-01-10',
-            'project': project
+            'project_id': project.pk,
         }
         version_model.__dict__.update(data)
         version_model.save()
 
-        sponsor = SponsorF.create()
-        data = {
-            'name': u'Foo Sponsor',
-            'project': project
-        }
-        sponsor.__dict__.update(data)
-        sponsor.save()
-
-        sponsorship_period = SponsorshipPeriodF.create()
-        data = {
-            'start_date': u'2016-01-01',
-            'end_date': u'2016-02-01',
-            'approved': True,
-            'private': False,
-            'project': project,
-            'sponsor': sponsor
-        }
-        sponsorship_period.__dict__.update(data)
-        sponsorship_period.save()
-
+        version_model.refresh_from_db()
         sponsors = version_model.sponsors()
         self.assertEqual(sponsors.count(), 1)