Repository: pypi/warehouse

Issue:
Add basic index view
No tests yet, I'll add them once we agree this is useful :)
![2015-04-14-155911_2265x1366_scrot](https://cloud.githubusercontent.com/assets/126339/7146129/59a16724-e2bf-11e4-8658-36268ab14be7.png)



Discussion:

Resolving patch:
diff --git a/warehouse/routes.py b/warehouse/routes.py
--- a/warehouse/routes.py
+++ b/warehouse/routes.py
@@ -12,6 +12,8 @@
 
 
 def includeme(config):
+    config.add_route("index", "/")
+
     # Accounts
     config.add_route(
         "accounts.profile",
diff --git a/warehouse/views.py b/warehouse/views.py
new file mode 100644
--- /dev/null
+++ b/warehouse/views.py
@@ -0,0 +1,37 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from pyramid.view import view_config
+
+from warehouse.packaging.models import Project, Release, File
+from warehouse.accounts.models import User
+
+
+@view_config(
+    route_name="index",
+    renderer="index.html",
+)
+def index(request):
+    latest_updated_releases = request.db.query(Release)\
+                                        .order_by(Release.created.desc())[:20]
+    num_projects = request.db.query(Project).count()
+    num_users = request.db.query(User).count()
+    num_files = request.db.query(File).count()
+    num_releases = request.db.query(Release).count()
+
+    return {
+        'latest_updated_releases': latest_updated_releases,
+        'num_projects': num_projects,
+        'num_users': num_users,
+        'num_releases': num_releases,
+        'num_files': num_files,
+    }


Test patch:
diff --git a/tests/legacy/api/test_simple.py b/tests/legacy/api/test_simple.py
--- a/tests/legacy/api/test_simple.py
+++ b/tests/legacy/api/test_simple.py
@@ -116,6 +116,8 @@ def test_with_files_no_serial(self, db_request):
             )
             for r in releases
         ]
+        # let's assert the result is ordered by string comparison of filename
+        files = sorted(files, key=lambda key: key.filename)
         db_request.matchdict["name"] = project.normalized_name
         user = UserFactory.create()
         JournalEntryFactory.create(submitted_by=user.username)
@@ -139,6 +141,8 @@ def test_with_files_with_seiral(self, db_request):
             )
             for r in releases
         ]
+        # let's assert the result is ordered by string comparison of filename
+        files = sorted(files, key=lambda key: key.filename)
         db_request.matchdict["name"] = project.normalized_name
         user = UserFactory.create()
         je = JournalEntryFactory.create(
diff --git a/tests/test_routes.py b/tests/test_routes.py
--- a/tests/test_routes.py
+++ b/tests/test_routes.py
@@ -37,6 +37,7 @@ def add_redirect(*args, **kwargs):
     includeme(config)
 
     assert config.add_route.calls == [
+        pretend.call('index', '/'),
         pretend.call(
             "accounts.profile",
             "/user/{username}/",
diff --git a/tests/test_views.py b/tests/test_views.py
new file mode 100644
--- /dev/null
+++ b/tests/test_views.py
@@ -0,0 +1,45 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import datetime
+
+from warehouse.views import index
+
+from .common.db.packaging import (
+    ProjectFactory, ReleaseFactory, FileFactory,
+)
+from .common.db.accounts import UserFactory
+
+
+class TestIndex:
+
+    def test_index(self, db_request):
+
+        project = ProjectFactory.create()
+        release1 = ReleaseFactory.create(project=project)
+        release1.created = datetime.date(2011, 1, 1)
+        release2 = ReleaseFactory.create(project=project)
+        release2.created = datetime.date(2012, 1, 1)
+        FileFactory.create(
+            release=release1,
+            filename="{}-{}.tar.gz".format(project.name, release1.version),
+            python_version="source",
+        )
+        UserFactory.create()
+
+        assert index(db_request) == {
+            # assert that ordering is correct
+            'latest_updated_releases': [release2, release1],
+            'num_projects': 1,
+            'num_users': 1,
+            'num_releases': 2,
+            'num_files': 1,
+        }