def permissionForUser(userId, streamId): """ Returns the permission for a particular stream. Parameters: userId - a user id. streamId - a stream id. Returns: A permission document. """ return core.single(schema.permissionByUserAndStream, [userId, streamId])
def byUniqueName(uniqueName): """ Return the stream with a unique name. Used mainly when using streams to support tagging. Parameters: uniqueName - the unique name for that stream. Returns: A stream id (string). """ return core.single(schema.streamByUniqueName, uniqueName)
def commentStream(id): """ Return the comment stream id for the specified shift. Parameters: id - a shift id. """ stream = core.single(schema.commentStreams, id) if stream: return stream["_id"] else: return None
def readFull(userName, deleteType=True): """ Return the full data for a user. Parameters: userName - the user name. deleteType - delete the type field from the dictionary to be returned. Returns: a dictionary containing all the data for a user. """ theUser = core.single(schema.userByName, userName) if theUser and deleteType: del theUser["type"] return theUser
def shifts(byHref, userId=None, byFollowing=False, byGroups=False, start=0, perPage=25): """ Returns a list of shifts based on whether 1. href 3. By public streams specified user is following. 4. By groups streams specified user is following. Parameters: byHref - a url byDomain - a url string byFollowing - a user id byGroups - a user id Returns: A list of shifts that match the specifications. """ db = core.connect() # NOTE: to prevent errors on a newly created DB - David 9/11/09 if core.single(schema.statsCount, "shift") == None: return [] lucene = core.lucene() # TODO: validate byHref - David queryString = "(href:\"%s\" AND draft:false AND private:false)" % byHref if userId: queryString = queryString + " OR createdBy:%s" % userId streams = "" if byFollowing: following = user.followStreams(userId) streams = streams + " ".join(following) if byGroups: groups = user.groupStreams(userId) streams = streams + " ".join(groups) # TODO: make sure streams cannot be manipulated from client - David queryString = queryString + ((" OR (draft:false%s)" % ((len(streams) > 0 and (" AND streams:%s" % streams)) or ""))) rows = lucene.search("shifts", q=queryString, sort="\modified", skip=start, limit=perPage) shifts = [db[row["id"]] for row in rows] return shifts
def byShortName(shortName): return core.single(schema.groupByShortName, shortName)
def favoriteCount(id): return core.single(schema.favoritesByShift, id) or 0