def aggregation(self, parts, values, data=None, fetched=None): convId, convType, convOwnerId, notifyType = parts entities = data['entities'] userCount = len(values) templates = self._aggregation_EI if notifyType == "EI"\ else self._aggregation_EA templatePair = templates[3 if userCount > 4 else userCount - 1] vals = dict([('user'+str(idx), utils.userName(uid, entities[uid]))\ for idx, uid in enumerate(values[0:2])]) vals['count'] = userCount - 2 vals['itemType'] = utils.itemLink(convId, convType) if notifyType == "EI": if convOwnerId == values[0]: notifyStr = templatePair[0] % vals else: vals['owner'] = utils.userName(convOwnerId, entities[convOwnerId]) notifyStr = templatePair[1] % vals else: if convOwnerId == data['myId']: notifyStr = templatePair[0] % vals else: vals['owner'] = utils.userName(convOwnerId, entities[convOwnerId]) notifyStr = templatePair[1] % vals return notifyStr
def getReason(self, convId, requesters, userId): conv = yield db.get_slice(convId, "items", ["meta"]) conv = utils.supercolumnsToDict(conv) cols = yield db.multiget_slice(requesters, "entities", ["basic"]) entities = utils.multiSuperColumnsToDict(cols) foo = requesters[0] if conv["meta"]["subType"] == "connection": reasonStr = '%s accepted your friend request' \ %(utils.userName(foo, entities[foo])) elif conv["meta"]["subType"] == "pendingConnection": reasonStr = "%s sent a friend request." \ "Click <a href='/profile?id=%s'>here </a> to respond" \ %(utils.userName(foo, entities[foo]), foo) defer.returnValue(reasonStr)
def reason(self, convId, updates, data): myId = data['myId'] update = None for x in reversed(updates): if x[1] != myId and len(myId) > 4 and x[4]: update = x break if not update: return ('', []) tag = data.get('tags', {}).get(update[4], {}).get('title', '') if not tag: return ('', []) entities = data['entities'] meta = data['items'][convId]['meta'] ownerId = meta['owner'] uname = lambda x: utils.userName(x, entities[x], "conv-user-cause") vals = {'u0': uname(update[1]), 'owner':uname(ownerId), 'type':utils.itemLink(convId, meta['type']), 'tag': tag} template = self.templates[1] if ownerId != myId\ else self.templates[0] return (template % vals, [update[1]])
def aggregation(self, parts, values, data=None, fetched=None): values = utils.uniqify(values) noOfUsers = len(values) entities = data.get('entities', {}) if self.notificationType == "GI": vals = dict([('user' + str(idx), utils.userName(uid, entities[uid]))\ for idx, uid in enumerate(values[0:2])]) groupId = parts[2] vals['group0'] = utils.groupName(groupId, entities[groupId]) else: vals = dict([('group' + str(idx), utils.userName(uid, entities[uid]))\ for idx, uid in enumerate(values[0:2])]) vals.update({'count': noOfUsers - 2, 'brandName': brandName}) return self._aggregation[3 if noOfUsers > 4 else noOfUsers - 1] % vals
def reason(self, convId, updates, data): entities = data['entities'] meta = data['items'][convId]['meta'] ownerId = meta['owner'] myId = data['myId'] yesPeople = data['yesPeople'] uname = lambda x: utils.userName(x, entities[x], "conv-user-cause") if convId in yesPeople: users = yesPeople[convId] else: return ('', []) if ownerId in users: users.remove(ownerId) users = users[0:3] vals = dict([('u'+str(i), uname(x)) for i,x in enumerate(users)]) vals.update({'owner':uname(ownerId), 'type':utils.itemLink(convId, meta['type'])}) if not users: return ('', []) template = self.templates[len(users)-1][1] if ownerId != myId\ else self.templates[len(users)-1][0] return (template % vals, users)
def _likes(self, request, data=None): itemId, item = data['id'] entities, users = yield Item.likes(itemId, item) args = {"users": users, "entities": entities} if not users: raise errors.InvalidRequest(_("Currently, no one likes the item")) itemType = item['meta'].get('type', 'comment') ownerId = item["meta"]["owner"] args['title'] = _("People who like %s's %s") %\ (utils.userName(ownerId, entities[ownerId]), _(itemType)) t.renderScriptBlock(request, "item.mako", "userListDialog", False, "#likes-dlg-%s" % (itemId), "set", **args)
def aggregation(self, parts, values, data=None, fetched=None): userIds = utils.uniqify(values) noOfUsers = len(userIds) entities = data.get('entities', {}) vals = dict([('user' + str(idx), utils.userName(uid, entities[uid]))\ for idx, uid in enumerate(userIds[0:2])]) vals.update({'count': noOfUsers - 2, 'brandName': brandName}) if 'orgId' in data: orgId = data['orgId'] vals.update({'orgId': orgId, 'networkName': entities[orgId].basic['name']}) return self._aggregation[3 if noOfUsers > 4 else noOfUsers - 1] % vals
def aggregation(self, parts, values, data=None, fetched=None): userIds = utils.uniqify(values) noOfUsers = len(userIds) entities = data.get('entities', {}) keyword = parts[2] keyword = '<a class="ajax" href="/admin/keyword-matches?keyword=%s">%s</a>' % (keyword, keyword) vals = dict([('user' + str(idx), utils.userName(uid, entities[uid]))\ for idx, uid in enumerate(userIds[0:2])]) vals.update({'count': noOfUsers - 2, 'brandName': brandName, 'keyword': keyword}) return self._aggregation[3 if noOfUsers > 4 else noOfUsers - 1] % vals
def reason(self, convId, updates, data): entities = data['entities'] meta = data['items'][convId]['meta'] ownerId = meta['owner'] myId = data['myId'] uname = lambda x: utils.userName(x, entities[x], "conv-user-cause") users = utils.uniqify([x[1] for x in reversed(updates) if x[1] != myId]) vals = dict([('u'+str(i), uname(x)) for i,x in enumerate(users)]) vals.update({'owner':uname(ownerId), 'type':utils.itemLink(convId, meta['type'])}) template = self.templates[len(users)-1][1] if ownerId != myId\ else self.templates[len(users)-1][0] return (template % vals, users)