def joinData(cls, shifts, userId=None): from server.models.favorite import Favorite from server.models.comment import Comment if core._local: db = core.conect("user/%s" % core._local_id) else: db = core.connect("shiftspace/shared") single = False if type(shifts) != list: single = True shifts = [shifts] ids = [shift['_id'] for shift in shifts] favIds = [Favorite.makeId(userId, shiftId) for shiftId in ids] isFavorited = core.fetch(db, keys=favIds) favCounts = core.fetch(db, view=Favorite.count_by_shift, keys=ids) commentCounts = core.fetch(db, view=Comment.count_by_shift, keys=ids) userIds = [shift["createdBy"] for shift in shifts] users = core.fetch(keys=userIds) for i in range(len(shifts)): shifts[i]["favorite"] = (isFavorited[i] != None) shifts[i]["favoriteCount"] = favCounts[i] shifts[i]["commentCount"] = commentCounts[i] shifts[i]["gravatar"] = (users[i]["gravatar"] or "images/default.png") shifts[i]["userName"] = users[i]["userName"] shifts[i]["createdStr"] = utils.pretty_date(utils.futcstr(shifts[i]["created"])) shifts[i]["modifiedStr"] = utils.pretty_date(utils.futcstr(shifts[i]["modified"])) if single: return shifts[0] else: return shifts
def joinData(cls, messages, userId=None): single = False if type(messages) != list: single = True messages = [messages] ids = [message["_id"] for message in messages] userIds = [message["fromId"] for message in messages] users = core.fetch(keys=userIds) if userId: readStatuses = core.fetch(db=core.connect("shiftspace/shared"), keys=[Message.makeReadId(id, userId) for id in ids]) for i in range(len(messages)): if (userIds[i]): if (userIds[i] == 'shiftspace'): messages[i]["gravatar"] = "images/default.png" messages[i]["userName"] = '******' else: messages[i]["gravatar"] = (users[i]["gravatar"] or "images/default.png") messages[i]["userName"] = users[i]["userName"] messages[i]["modifiedStr"] = utils.pretty_date(utils.futcstr(messages[i]["modified"])) if userId: messages[i]["read"] = (readStatuses[i] != None) if single: return messages[0] else: return messages
def joinData(cls, comments): single = False if type(comments) != list: single = True comments = [comments] authorIds = [comment["shiftAuthor"] for comment in comments] shiftIds = [comment["shiftId"] for comment in comments] userIds = [comment["createdBy"] for comment in comments] users = core.fetch(keys=userIds) authors = core.fetch(keys=authorIds) shifts = core.fetch(core.connect("shiftspace/shared"), keys=shiftIds) commentCounts = core.fetch(core.connect("shiftspace/shared"), view=Comment.count_by_shift, keys=shiftIds) for i in range(len(comments)): if (authors[i]): comments[i]["authorName"] = authors[i]["userName"] comments[i]["userName"] = users[i]["userName"] comments[i]["gravatar"] = users[i]["gravatar"] comments[i]["createdStr"] = utils.pretty_date(utils.futcstr(comments[i]["created"])) comments[i]["commentCount"] = commentCounts[i] comments[i]["space"] = shifts[i]["space"] comments[i]["href"] = shifts[i]["href"] comments[i]["domain"] = shifts[i]["domain"] if single: return comments[0] else: return comments
def joinData(cls, shifts, userId=None): from server.models.favorite import Favorite from server.models.comment import Comment if core._local: db = core.conect("user/%s" % core._local_id) else: db = core.connect("shiftspace/shared") single = False if type(shifts) != list: single = True shifts = [shifts] ids = [shift['_id'] for shift in shifts] favIds = [Favorite.makeId(userId, shiftId) for shiftId in ids] isFavorited = core.fetch(db, keys=favIds) favCounts = core.fetch(db, view=Favorite.count_by_shift, keys=ids) commentCounts = core.fetch(db, view=Comment.count_by_shift, keys=ids) userIds = [shift["createdBy"] for shift in shifts] users = core.fetch(keys=userIds) for i in range(len(shifts)): shifts[i]["favorite"] = (isFavorited[i] != None) shifts[i]["favoriteCount"] = favCounts[i] shifts[i]["commentCount"] = commentCounts[i] shifts[i]["gravatar"] = (users[i]["gravatar"] or "images/default.png") shifts[i]["userName"] = users[i]["userName"] shifts[i]["createdStr"] = utils.pretty_date( utils.futcstr(shifts[i]["created"])) shifts[i]["modifiedStr"] = utils.pretty_date( utils.futcstr(shifts[i]["modified"])) if single: return shifts[0] else: return shifts