[ckan-changes] [okfn/ckan] a6275b: tracking_summary force sort order

GitHub noreply at github.com
Fri Apr 20 14:10:02 UTC 2012


  Branch: refs/heads/enhancement-2251-tracking
  Home:   https://github.com/okfn/ckan
  Commit: a6275b0ea191450168aa6e559ceb6b47b37327b1
      https://github.com/okfn/ckan/commit/a6275b0ea191450168aa6e559ceb6b47b37327b1
  Author: Toby <toby.junk at gmail.com>
  Date:   2012-04-20 (Fri, 20 Apr 2012)

  Changed paths:
    M ckan/model/tracking.py

  Log Message:
  -----------
  tracking_summary force sort order


diff --git a/ckan/model/tracking.py b/ckan/model/tracking.py
index 044b1b5..384f84b 100644
--- a/ckan/model/tracking.py
+++ b/ckan/model/tracking.py
@@ -15,9 +15,9 @@ class TrackingSummary(DomainObject):
 
     @classmethod
     def get_for_package(cls, package_id):
-        # FIXME should be ordered by date desc but didn't like order_by(date)
         obj = Session.query(cls).autoflush(False)
-        data = obj.filter_by(package_id=package_id).first()
+        obj = obj.filter_by(package_id=package_id)
+        data = obj.order_by('tracking_date desc').first()
         if data:
             return {'total' : data.running_total,
                     'recent': data.recent_views}
@@ -27,9 +27,8 @@ def get_for_package(cls, package_id):
 
     @classmethod
     def get_for_resource(cls, url):
-        # FIXME should be ordered by date desc but didn't like order_by(date)
         obj = Session.query(cls).autoflush(False)
-        data = obj.filter_by(url=url).first()
+        data = obj.filter_by(url=url).order_by('tracking_date desc').first()
         if data:
             return {'total' : data.running_total,
                     'recent': data.recent_views}


================================================================



More information about the ckan-changes mailing list