incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [8/9] git commit: [#4595] ticket:421 Filter projects by date range
Date Wed, 04 Sep 2013 13:20:28 GMT
[#4595] ticket:421 Filter projects by date range


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/f865ddfd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/f865ddfd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/f865ddfd

Branch: refs/heads/master
Commit: f865ddfdc5390753cfb268a67d9835b34a439add
Parents: 01194e0
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Sep 2 12:26:09 2013 +0300
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Wed Sep 4 13:19:55 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py           |  8 +++++---
 Allura/allura/tests/functional/test_site_admin.py | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f865ddfd/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index be8415b..818016f 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -192,14 +192,16 @@ class SiteAdminController(object):
             end_dt = datetime.strptime(end_dt, '%Y/%m/%d %H:%M:%S')
         except ValueError:
             end_dt = None
+        start_dt = datetime.now() if not start_dt else start_dt
+        end_dt = start_dt - timedelta(days=15) if not end_dt else end_dt
+        start = bson.ObjectId.from_datetime(start_dt)
+        end = bson.ObjectId.from_datetime(end_dt)
         nb = M.Neighborhood.query.get(name='Users')
         projects = (M.Project.query.find({
                 'neighborhood_id': {'$ne': nb._id},
                 'deleted': False,
+                '_id': {'$lt': start, '$gt': end},
             }).sort('_id', -1))
-        #projects = projects.skip(start).limit(limit)
-        start_dt = datetime.now() if not start_dt else start_dt
-        end_dt = start_dt - timedelta(days=15) if not end_dt else end_dt
         return {
             'projects': projects,
             'window_start': start_dt,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f865ddfd/Allura/allura/tests/functional/test_site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_site_admin.py b/Allura/allura/tests/functional/test_site_admin.py
index e339ff7..e0ba8fd 100644
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -16,6 +16,7 @@
 #       under the License.
 
 import json
+from datetime import timedelta
 
 from nose.tools import assert_equal
 from ming.odm import ThreadLocalORMSession
@@ -78,6 +79,19 @@ class TestSiteAdmin(TestController):
                 username='root'))
         assert_equal(len(r.html.find('table').findAll('tr')), count - 1)
 
+    def test_new_projects_daterange_filtering(self):
+        r = self.app.get('/nf/admin/new_projects', extra_environ=dict(
+                username='root'))
+        count = len(r.html.find('table').findAll('tr'))
+        assert_equal(count, 7)
+
+        filtr = r.forms[0]
+        filtr['start-dt'] = '2000/01/01 10:10:10'
+        filtr['end-dt'] = '2000/01/01 09:09:09'
+        r = filtr.submit()
+        count = len(r.html.find('table').findAll('tr'))
+        assert_equal(count, 1)  # only row with headers - no results
+
     def test_reclone_repo_access(self):
         r = self.app.get('/nf/admin/reclone_repo', extra_environ=dict(
             username='*anonymous'), status=302).follow()


Mime
View raw message