Commits

Michael Tharp committed baf49f8 Draft

Add URL for latest up-to-date version of app

Comments (0)

Files changed (2)

ubersync/web/main.py

     config.add_route('game_list', '/apps/')
     config.add_route('game_single', '/apps/{app_id}/')
     config.add_route('version_list', '/apps/{app_id}/versions/')
+    config.add_route('version_current', '/apps/{app_id}/versions/up_to_date/')
     config.add_route('version_single', '/apps/{app_id}/versions/{ver_short}/')
     config.add_view('pyramid.view.append_slash_notfound_view',
             context='pyramid.httpexceptions.HTTPNotFound')

ubersync/web/views.py

     out = game.to_dict()
     out['all_versions'] = request.route_url('version_list',
             app_id=game.app_id)
+    out['current_versions'] = request.route_url('version_current',
+            app_id=game.app_id)
     out['latest_mirrored'] = request.route_url('version_single',
             app_id=game.app_id, ver_short='latest')
     return out
     return out
 
 
-@view_config(route_name='version_list', renderer='json', http_cache=60)
-def version_list(request):
+def _version_list(request, query):
     out = {}
     modified = datetime.fromtimestamp(0, UTC)
-    for ver in request.db.query(Version
-            ).options(joinedload(Version.depots)
-            ).filter_by(app_id=request.matchdict['app_id']):
+    for ver in query:
         url = request.route_url('version_single',
                 app_id=ver.app_id, ver_short=ver.ver_short)
         out[url] = _stuff_version(request, ver)
     return out
 
 
+@view_config(route_name='version_list', renderer='json', http_cache=60)
+def version_list(request):
+    query = request.db.query(Version
+            ).options(joinedload(Version.depots)
+            ).filter_by(app_id=request.matchdict['app_id'])
+    return _version_list(request, query)
+
+
+@view_config(route_name='version_current', renderer='json', http_cache=60)
+def version_current(request):
+    query = request.db.query(Version
+            ).options(joinedload(Version.depots)
+            ).filter_by(app_id=request.matchdict['app_id'],
+                    up_to_date=True,
+                    )
+    return _version_list(request, query)
+
+
 @view_config(route_name='version_single', renderer='json', http_cache=60)
 def version_single(request):
     ver_short = request.matchdict['ver_short']