def _to_python(self, value, state): options = SocialString(multivalued=True).to_python(value) options = [x for x in options if x] options = utils.uniqify(options) if not options: raise MissingParam('options', value, state) if len(options) < 2: raise MissingParam('2nd option', value, state) return options
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)
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 _getNotifications(self, request, count=15): authinfo = request.getSession(IAuthInfo) myId = authinfo.username myOrgId = authinfo.organization nextPageStart = None keysFromStore = [] # List of keys fetched notifyIds = [] # convIds for which we have notifications details_d = [] # Deferreds waiting of notification items toFetchTags = set() toFetchEntities = set() tags = {} entities = {} timestamps = {} notifyStrs = {} notifyClasses = {} notifyUsers = {} fetchStart = utils.getRequestArg(request, 'start') or '' if fetchStart: fetchStart = utils.decodeKey(fetchStart) fetchCount = count + 2 while len(notifyIds) < count: fetchedNotifyIds = [] results = yield db.get_slice(myId, "notifications", count=fetchCount, start=fetchStart, reverse=True) for col in results: value = col.column.value if value not in notifyIds: fetchedNotifyIds.append(value) keysFromStore.append(col.column.name) timestamps[value] = col.column.timestamp / 1e6 if not keysFromStore: break fetchStart = keysFromStore[-1] notifyIds.extend(fetchedNotifyIds) if len(results) < fetchCount: break if len(keysFromStore) > count: nextPageStart = utils.encodeKey(keysFromStore[count]) notifyIds = notifyIds[0:count] elif len(results) == fetchCount: nextPageStart = utils.encodeKey(keysFromStore[-1]) notifyIds = notifyIds[0:-1] # We don't have notifications on any conversations if not notifyIds: defer.returnValue({}) # We need the name of current user's organization toFetchEntities.add(myOrgId) # Fetch more data about the notifications notifyItems = yield db.get_slice(myId, "notificationItems", notifyIds, reverse=True) notifyValues = {} notifyParts = {} notifyPlugins = {} notifyPluginData = {} for notify in notifyItems: notifyId = notify.super_column.name updates = notify.super_column.columns updates.reverse() notifyValues[notifyId] = [] parts = notifyId.split(':') notifyType = parts[3] if parts[0] else parts[1] plugin = _notificationPlugins.get(notifyType, None) if not plugin: continue values = [update.value for update in updates] userIds, entityIds, pluginData = \ yield plugin.fetchAggregationData(myId, myOrgId, parts, values) notifyValues[notifyId] = utils.uniqify(values) notifyParts[notifyId] = parts notifyPlugins[notifyId] = plugin notifyPluginData[notifyId] = pluginData notifyUsers[notifyId] = utils.uniqify(userIds) toFetchEntities.update(entityIds) # Fetch the required entities entities = base.EntitySet(toFetchEntities) yield entities.fetchData() myOrg = entities.get(myOrgId) # Build strings notifyStrs = {} data = {'entities': entities, 'myId': myId, 'orgId': myOrgId} for notifyId in notifyIds: parts = notifyParts.get(notifyId, None) if not parts: continue plugin = notifyPlugins[notifyId] notifyStrs[notifyId] = plugin.aggregation(parts, notifyValues[notifyId], data, notifyPluginData[notifyId]) args = {"notifications": notifyIds, "notifyStr": notifyStrs, "notifyClasses": notifyClasses, "notifyUsers": notifyUsers, "entities": entities, "timestamps": timestamps, "nextPageStart": nextPageStart} defer.returnValue(args)