Repository: readthedocs/readthedocs.org

Issue:
Fix the count of total projects shown on the homepage
On the hompage (https://readthedocs.org/), we show the total count of the projects.

![Screenshot from 2019-07-15 14-23-42](https://user-images.githubusercontent.com/29149191/61207904-d6b64f00-a713-11e9-9388-8d7222a2a4d7.png)

This number also includes projects that are identified as spam.
It would be good if we exclude spam projects from it.


Discussion:
Can I work on it?
@Iamshankhadeep Go Ahead! :+1: 
@saadmk11 can you guide me from where can I start?

You can start from here and update the `project_count` queryset.
https://github.com/readthedocs/readthedocs.org/blob/e12f70dbc733389a62b08d7744062ebbe58ce6e6/readthedocs/core/views/__init__.py#L37-L46
@saadmk11 can you please point out where is the `count()` function which is needed for `project_count` querry set?
@Iamshankhadeep Can I work on this issue ?
@Iamshankhadeep 
You need to add a filter here -- https://github.com/readthedocs/readthedocs.org/blob/7be01d844b981635822d4df73f614ad2c3d71b8b/readthedocs/core/views/__init__.py#L45

@Iamshankhadeep @Abhi-khandelwal 
Any one can submit a PR. :smile: 

Resolving patch:
diff --git a/readthedocs/core/views/__init__.py b/readthedocs/core/views/__init__.py
--- a/readthedocs/core/views/__init__.py
+++ b/readthedocs/core/views/__init__.py
@@ -42,7 +42,7 @@ def get_context_data(self, **kwargs):
         """Add latest builds and featured projects."""
         context = super().get_context_data(**kwargs)
         context['featured_list'] = Project.objects.filter(featured=True)
-        context['projects_count'] = Project.objects.count()
+        context['projects_count'] = Project.objects.exclude(users__profile__banned=True).count()
         return context
 
 


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_views.py b/readthedocs/rtd_tests/tests/test_views.py
--- a/readthedocs/rtd_tests/tests/test_views.py
+++ b/readthedocs/rtd_tests/tests/test_views.py
@@ -10,6 +10,7 @@
 from readthedocs.builds.constants import LATEST, EXTERNAL
 from readthedocs.builds.models import Build, Version
 from readthedocs.core.permissions import AdminPermission
+from readthedocs.core.models import UserProfile
 from readthedocs.projects.forms import UpdateProjectForm
 from readthedocs.projects.models import HTMLFile, Project
 
@@ -293,6 +294,37 @@ def test_build_list_includes_external_versions(self):
         response = self.client.get(
             reverse('builds_project_list', args=[self.pip.slug]),
         )
-        self.assertEqual(response.status_code, 200)
-
+        self.assertEqual(response.status_code, 200)       
         self.assertIn(external_version_build, response.context['build_qs'])
+
+
+class HomepageViewTests(TestCase):
+
+    def setUp(self):
+        self.homepage_url = reverse('homepage')
+
+    def test_projects_count(self):
+        user_1 = get(User)
+        profile_1 = get(UserProfile, user=user_1, banned=True)
+
+        user_2 = get(User)
+        profile_2 = get(UserProfile, user=user_2, banned=True)
+
+        user_3 = get(User)
+        profile_3 = get(UserProfile, user=user_3, banned=False)
+
+        project_a = get(Project, users=[user_1])
+        project_b = get(Project, users=[user_2])
+        project_c = get(Project, users=[user_3])
+
+        spam_proj_count = Project.objects.filter(users__profile__banned=True).count()
+
+        self.assertEqual(spam_proj_count, 2)
+        self.assertEqual(User.objects.all().count(), 3)
+        self.assertEqual(User.objects.filter(profile__banned=True).count(), 2)
+
+        expected_count = Project.objects.all().count() - spam_proj_count
+        response = self.client.get(self.homepage_url)
+
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(expected_count, response.context['projects_count'])