def search_workspace(): user_name = request.GET.get('userName') start = int(request.GET.get('start')) limit = int(request.GET.get('limit')) name_pattern = request.GET.get('namePattern') name_position = request.GET.get('namePosition') user_pattern = request.GET.get('userPattern') user_position = request.GET.get('userPosition') workspaces = repo.User(db_session).read(user_name).workspaces #filter owner workspaces = util.collection_filter(user_position, user_pattern, 'user_name', workspaces) #filter name workspaces = util.collection_filter(name_position, name_pattern, 'name', workspaces) #sort workspaces = sorted(workspaces, key=lambda l: l.name) total = len(workspaces) limit = start + limit o = map(lambda ws: vo.workspace(ws), workspaces[start:limit]) return vo.collection(o, total)
def get_by_owner(): user_name = request.GET.get('userName') start = int(request.GET.get('start')) limit = int(request.GET.get('limit')) workspaces = repo.Workspace(db_session).get_by_owner(user_name) #paging by code (discrete values) total = len(workspaces) limit = start + limit #order by date sort_ws = sorted(workspaces, key=lambda n: n.date, reverse=True) o = map(lambda ws: vo.workspace(ws), sort_ws[start:limit]) return vo.collection(o, total)
def read(id): ws = repo.Workspace(db_session).read(id) o = vo.workspace(ws) if ws else '' return o