diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-01-03 07:41:53 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-01-03 07:41:53 +0000 |
commit | d7069b5a2e7859ab14c5a909d5e5fc6bc84b80cb (patch) | |
tree | d8027520fb22c176f54e860c0d2ebd000b1c457f /sca-cpp/trunk/hosting/server/dashboards.py | |
parent | 9e1b9e73145e00ea591bd1e0e9777625bad66dc9 (diff) |
Improve app hosting management app, restructure UI and refactor REST services and data model to use an SQL database.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1428193 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/hosting/server/dashboards.py | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/sca-cpp/trunk/hosting/server/dashboards.py b/sca-cpp/trunk/hosting/server/dashboards.py index d6281d0454..a87f1fa819 100644 --- a/sca-cpp/trunk/hosting/server/dashboards.py +++ b/sca-cpp/trunk/hosting/server/dashboards.py @@ -17,6 +17,7 @@ # Dashboards collection implementation from util import * +from atomutil import * from sys import debug # Convert a particular user id to a dashboard id @@ -27,7 +28,7 @@ def dashboardid(user): def getdashboard(id, cache): debug('dashboards.py::getdashboard::id', id) val = cache.get(id) - if isNil(val) or val is None: + if isNil(val): return () dashboard = cdddr(car(val)) if not isNil(dashboard) and isList(car(cadr(car(dashboard)))): @@ -47,36 +48,57 @@ def putdashboard(id, dashboard, cache): return cache.put(id, val) # Put an app into the user's dashboard -def put(id, app, user, cache, apps): +def put(id, app, user, cache, apps, ratings): debug('dashboards.py::put::id', id) debug('dashboards.py::put::app', app) def putapp(id, app, dashboard): if isNil(dashboard): return app - if car(id) == cadr(assoc("'id", car(dashboard))): + if car(id) == entryid(dashboard): return cons(car(app), cdr(dashboard)) return cons(car(dashboard), putapp(id, app, cdr(dashboard))) - appentry = (("'entry", assoc("'title", car(app)), ("'id", car(id)), ("'author", user.get(())), assoc("'updated", car(app)), assoc("'content", car(app))),) + appentry = mkentry(title(app), car(id), user.get(()), now(), content(app)) debug('dashboards.py::put::appentry', appentry) dashboard = putapp(id, appentry, getdashboard(dashboardid(user), cache)) return putdashboard(dashboardid(user), dashboard, cache) +# Merge app info and ratings into a list of apps +def mergeapps(entries, apps, ratings): + debug('store.py::mergeapps::entries', entries) + + def mergeapp(entry): + debug('store.py::mergeapp::entry', entry) + id = (entryid(entry),) + app = apps.get(id) + if isNil(app): + return ((),) + info = content(app) + rating = ratings.get(id) + rates = content(rating) + mergedentry = mkentry(title(app), car(id), author(app), updated(app), ("'info",) + (() if isNil(info) else cdr(info)) + (() if isNil(rates) else cdr(rates))) + return mergedentry + + mergedentries = tuple(filter(lambda e: not isNil(e), map(lambda e: car(mergeapp((e,))), entries))) + debug('store.py::mergeapps::mergedentries', mergedentries) + return mergedentries + # Get apps from the user's dashboard -def get(id, user, cache, apps): +def get(id, user, cache, apps, ratings): debug('dashboards.py::get::id', id) def findapp(id, dashboard): if isNil(dashboard): return None - if car(id) == cadr(assoc("'id", car(dashboard))): + if car(id) == entryid(dashboard): return (car(dashboard),) return findapp(id, cdr(dashboard)) if isNil(id): - dashboard = ((("'feed", ("'title", "Your Apps"), ("'id", user.get(()))) + getdashboard(dashboardid(user), cache)),) + dashboardapps = mergeapps(getdashboard(dashboardid(user), cache), apps, ratings) + dashboard = ((("'feed", ("'title", "Your Apps"), ("'id", user.get(()))) + dashboardapps),) debug('dashboards.py::get::dashboard', dashboard) return dashboard @@ -85,7 +107,7 @@ def get(id, user, cache, apps): return app # Delete apps from the user's dashboard -def delete(id, user, cache, apps): +def delete(id, user, cache, apps, ratings): debug('dashboards.py::delete::id', id) if isNil(id): return cache.delete(dashboardid(user)) @@ -93,7 +115,7 @@ def delete(id, user, cache, apps): def deleteapp(id, dashboard): if isNil(dashboard): return () - if car(id) == cadr(assoc("'id", car(dashboard))): + if car(id) == entryid(dashboard): return cdr(dashboard) return cons(car(dashboard), deleteapp(id, cdr(dashboard))) |