本文整理汇总了Python中social.db.get_slice函数的典型用法代码示例。如果您正苦于以下问题:Python get_slice函数的具体用法?Python get_slice怎么用?Python get_slice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_slice函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _listPresetTags
def _listPresetTags(self, request):
(appchange, script, args, myId) = yield self._getBasicArgs(request)
orgId = args["orgId"]
landing = not self._ajax
args['title'] = 'Preset Tags'
args['menuId'] = 'tags'
args["viewType"] = "tags"
if script and landing:
t.render(request, "admin.mako", **args)
if script and appchange:
t.renderScriptBlock(request, "admin.mako", "layout",
landing, "#mainbar", "set", **args)
presetTags = yield db.get_slice(orgId, "orgPresetTags", count=100)
presetTags = utils.columnsToDict(presetTags, ordered=True).values()
if presetTags:
tags_ = yield db.get_slice(orgId, "orgTags", presetTags)
tags_ = utils.supercolumnsToDict(tags_)
else:
tags_ = {}
args['tagsList'] = presetTags
args['tags'] = tags_
if script:
t.renderScriptBlock(request, "admin.mako", "list_tags",
landing, "#content", "set", **args)
if not script:
t.render(request, "admin.mako", **args)
示例2: getLatestCounts
def getLatestCounts(request, asJSON=True):
authinfo = yield defer.maybeDeferred(request.getSession, IAuthInfo)
myId = authinfo.username
myOrgId = authinfo.organization
latest = yield db.get_slice(myId, "latest")
latest = supercolumnsToDict(latest)
counts = dict([(key, len(latest[key])) for key in latest])
# Default keys for which counts should be set
defaultKeys = ["notifications", "messages", "groups", "tags"]
for key in defaultKeys:
counts[key] = counts[key] if key in counts else 0
groups = yield db.get_slice(myId, "entities", ["adminOfGroups"])
groups = supercolumnsToDict(groups).get("adminOfGroups", {}).keys()
if groups:
counts.setdefault("groups", 0)
cols = yield db.multiget_slice(groups, "latest")
cols = multiSuperColumnsToDict(cols)
for groupId in cols:
for key in cols[groupId]:
counts["groups"] += len(cols[groupId][key])
if asJSON:
defer.returnValue(json.dumps(counts))
else:
defer.returnValue(counts)
示例3: _addPresetTag
def _addPresetTag(self, request):
orgId = request.getSession(IAuthInfo).organization
tagNames = utils.getRequestArg(request, 'tag')
if not tagNames:
return
invalidTags = []
tagNames = [x.strip().decode('utf-8', 'replace') for x in tagNames.split(',')]
for tagName in tagNames:
if len(tagName) < 50 and regex.match('^[\w-]*$', tagName):
yield tags.ensureTag(request, tagName, orgId, True)
else:
invalidTags.append(tagName)
presetTags = yield db.get_slice(orgId, "orgPresetTags")
presetTags = utils.columnsToDict(presetTags, ordered=True).values()
tags_ = yield db.get_slice(orgId, "orgTags", presetTags)
tags_ = utils.supercolumnsToDict(tags_)
args = {'tags': tags_, 'tagsList': presetTags}
handlers = {}
if invalidTags:
if len(invalidTags) == 1:
message = " %s is invalid tag." % (invalidTags[0])
else:
message = " %s are invalid tags. " % (",".join(invalidTags))
errorMsg = "%s <br/>Tag can contain alpha-numeric characters or hyphen only. It cannot be more than 50 characters" % (message)
handlers = {'onload': "$$.alerts.error('%s')" % (errorMsg)}
t.renderScriptBlock(request, "admin.mako", "list_tags",
False, "#content", "set", True,
handlers=handlers, **args)
示例4: deleteFileInfo
def deleteFileInfo(myId, orgId, itemId, item, conv=None):
if 'parent' in item['meta']:
if not conv:
conv = yield db.get_slice(item['meta']['parent'], 'items', ['meta'])
conv = utils.supercolumnsToDict(conv)
convId = item['meta']['parent']
else:
conv = item
convId = itemId
acl = pickle.loads(conv['meta']['acl'])
allowedGroups = acl.get('accept', {}).get('groups', [])
deniedGroups = acl.get('deny', {}).get('groups', [])
groups = [x for x in allowedGroups if x not in deniedGroups]
allowedOrgs = acl.get('accept', {}).get('orgs', [])
ownerId = conv['meta']['owner']
entityIds = [myId]
entityIds.extend(groups)
entityIds.extend(allowedOrgs)
entityIds_ = yield utils.expandAcl(myId, orgId, conv['meta']['acl'], convId, ownerId, True)
entityIds.extend(entityIds_)
deferreds = []
for attachmentId in item.get('attachments', {}):
col = yield db.get_slice(attachmentId, 'attachmentVersions', count=1)
tuuid = col[0].column.name
deferreds.append(db.remove(myId, "user_files", tuuid))
#TODO: use batch remove/batch mutate
for entityId in entityIds:
deferreds.append(db.remove(entityId, "entityFeed_files", tuuid))
if deferreds:
yield defer.DeferredList(deferreds)
示例5: _deletePresetTag
def _deletePresetTag(self, request):
orgId = request.getSession(IAuthInfo).organization
tagId = utils.getRequestArg(request, 'id')
if not tagId:
return
try:
tag = yield db.get(orgId, 'orgTags', super_column=tagId)
tag = utils.supercolumnsToDict([tag])
tagName = tag[tagId]['title']
if 'isPreset' in tag[tagId]:
yield db.remove(orgId, "orgTags", 'isPreset', tagId)
yield db.remove(orgId, 'orgPresetTags', tagName)
presetTags = yield db.get_slice(orgId, "orgPresetTags")
presetTags = utils.columnsToDict(presetTags, ordered=True).values()
if presetTags:
tags_ = yield db.get_slice(orgId, "orgTags", presetTags)
tags_ = utils.supercolumnsToDict(tags)
else:
tags_ = {}
args = {'tagsList': presetTags, 'tags': tags_}
request.write('$("#tag-%s").remove()' % (tagId))
except ttypes.NotFoundException:
return
示例6: pushfileinfo
def pushfileinfo(myId, orgId, itemId, item, conv=None):
if 'parent' in item['meta']:
if not conv:
conv = yield db.get_slice(item['meta']['parent'], "items", ["meta"])
conv = utils.supercolumnsToDict(conv)
convId = item['meta']['parent']
else:
convId = itemId
conv = item
acl = pickle.loads(conv['meta']['acl'])
allowedGroups = acl.get('accept', {}).get('groups', [])
deniedGroups = acl.get('deny', {}).get('groups', [])
groups = [x for x in allowedGroups if x not in deniedGroups]
allowedOrgs = acl.get('accept', {}).get('orgs', [])
ownerId = conv['meta']['owner']
entityIds = [myId]
entityIds.extend(groups)
entityIds.extend(allowedOrgs)
entityIds_ = yield utils.expandAcl(myId, orgId, conv['meta']['acl'], convId, ownerId, True)
entityIds.extend(entityIds_)
for attachmentId in item.get('attachments', {}):
name, size, ftype = item['attachments'][attachmentId].split(':')
cols = yield db.get_slice(attachmentId, "attachmentVersions", count=1)
tuuid = cols[0].column.name
value = '%s:%s:%s:%s' % (attachmentId, name, itemId, ownerId)
#TODO: use batch remove/batch mutate
yield db.insert(myId, "user_files", value, tuuid)
for entityId in entityIds:
yield db.insert(entityId, "entityFeed_files", value, tuuid)
示例7: getPendingRequests
def getPendingRequests(group, me, start='', count=PEOPLE_PER_PAGE):
"""get the list of users who want to join the group.
Only admin can view pending group requests.
Keyword params:
@me:
@group: group object
@start: start fetching from @start
@count: no.of pending requests to fetch.
"""
toFetchCount = count + 1
nextPageStart = None
prevPageStart = None
if me.id not in group.admins:
raise errors.PermissionDenied('Access Denied')
cols = yield db.get_slice(group.id, "pendingConnections",
start=start, count=toFetchCount)
userIds = [x.column.name.split(':')[1] for x in cols if len(x.column.name.split(':')) == 2]
if len(userIds) == toFetchCount:
nextPageStart = userIds[-1]
userIds = userIds[0:count]
entities = base.EntitySet(userIds)
yield entities.fetchData()
if start:
cols = yield db.get_slice(group.id, "pendingConnections",
start=start, count=toFetchCount,
reverse=True)
if len(cols) > 1:
prevPageStart = cols[-1].column.name
data = {'userIds': userIds, "entities": entities,
"prevPageStart": prevPageStart, "nextPageStart": nextPageStart}
defer.returnValue(data)
示例8: _getPresence
def _getPresence(self, request):
authInfo = request.getSession(IAuthInfo)
orgId = authInfo.organization
myId = authInfo.username
data = []
cols = yield db.get_slice(orgId, "presence")
cols = utils.supercolumnsToDict(cols)
if myId not in cols:
myPresence = yield db.get_slice(orgId, "presence", super_column=myId)
cols[myId] = utils.columnsToDict(myPresence)
presence = {}
for userId in cols:
presence[userId] = getMostAvailablePresence(cols[userId].values())
if presence[myId] == PresenceStates.OFFLINE:
request.write(json.dumps(data))
return
userIds = cols.keys()
entities = base.EntitySet(userIds)
yield entities.fetchData()
for entityId in entities.keys():
entity = entities[entityId]
_data = {"userId": entityId, "name": entity.basic['name'],
"status": presence.get(entityId, PresenceStates.OFFLINE),
"title": entity.basic["jobTitle"],
"avatar": utils.userAvatar(entityId, entity, 's')}
data.append(_data)
request.write(json.dumps(data))
示例9: fetchData
def fetchData(self, args, convId=None, userId=None, columns=[]):
convId = convId or args["convId"]
myId = userId or args.get("myId", None)
conv = yield db.get_slice(convId, "items",
['options', 'counts'].extend(columns))
conv = utils.supercolumnsToDict(conv, True)
conv.update(args.get("items", {}).get(convId, {}))
options = conv["options"] if "options" in conv else None
if not options:
raise errors.InvalidRequest("The poll does not have any options")
myVote = yield db.get_slice(myId, "userVotes", [convId])
myVote = myVote[0].column.value if myVote else None
startTime = conv['meta'].get('start', None)
endTime = conv['meta'].get('end', None)
showResults = conv['meta'].get('showResults', 'True') == True
if not showResults:
# FIX: endTime is String. convert to time
if not endTime or time.gmtime() > endTime:
showResults = "True"
args.setdefault("items", {})[convId] = conv
args.setdefault("myVotes", {})[convId] = myVote
args.setdefault("showResults", {})[convId] = showResults
defer.returnValue(set())
示例10: _tags
def _tags(self, request, term):
if len(term) < 2:
request.write("[]")
return
orgId = request.getSession(IAuthInfo).organization
finish = _getFinishTerm(term)
itemId = utils.getRequestArg(request, "itemId")
if not itemId:
request.write("[]")
return
toFetchTags = set()
d1 = db.get_slice(orgId, "orgTagsByName", start=term, finish=finish, count=10)
tags = []
matchedTags = yield d1
matchedTags = [match.column.value for match in matchedTags]
if matchedTags:
matchedTags = yield db.get_slice(orgId, "orgTags", matchedTags)
matchedTags = utils.supercolumnsToDict(matchedTags)
for tagId in matchedTags:
tags.append({"title": matchedTags[tagId]["title"], "id": tagId})
tags.sort(key=itemgetter("title"))
output = []
template = self._singleLineTemplate
for tag in tags:
data = {"title": tag["title"], "meta": ""}
output.append({"value": tag["title"], "label": template % data, "href": "/tags?id=%s" % tag["id"]})
request.write(json.dumps(output))
示例11: _revoke
def _revoke(self, request):
authinfo = request.getSession(IAuthInfo)
myId = authinfo.username
myOrgId = authinfo.organization
clientId = utils.getRequestArg(request, "id", sanitize=False)
client = yield db.get_slice(clientId, "apps")
client = utils.supercolumnsToDict(client)
if not client:
raise errors.InvalidApp(clientId)
me = yield db.get_slice(myId, "entities", ["apikeys", "apps"])
me = utils.supercolumnsToDict(me)
# Remove the client in case of API Key
if client["meta"]["category"] == "apikey":
if client["meta"]["author"] != myId:
raise errors.AppAccessDenied(clientId)
d1 = db.remove(clientId, "apps")
d2 = db.remove(myId, "appsByOwner", clientId)
d3 = db.remove(myId, "entities", clientId, "apikeys")
d4 = db.remove(myOrgId, "appsByOwner", clientId)
yield defer.DeferredList([d1, d2, d3, d4])
# Remove the refresh token
# XXX: Valid access tokens could still exist
else:
authorization = me["apps"][clientId]
d1 = db.remove(myId, "entities", clientId, "apps")
d2 = db.remove(authorization, "oAuthData")
yield defer.DeferredList([d1, d2])
示例12: _myCollection
def _myCollection(self, request, term):
authInfo = request.getSession(IAuthInfo)
myId = authInfo.username
orgId = authInfo.organization
finish = _getFinishTerm(term)
# Fetch list of tags and names that match the given term
d2 = db.get_slice(orgId, "nameIndex", start=term, finish=finish, count=10)
toFetchEntities = set()
users = []
# List of users that match the given term
matchedUsers = yield d2
for user in matchedUsers:
name, uid = user.column.name.rsplit(":")
if uid not in toFetchEntities:
users.append(uid)
toFetchEntities.add(uid)
# Fetch the required entities
entities = {}
if toFetchEntities:
entities = base.EntitySet(toFetchEntities)
yield entities.fetchData()
output = []
template = self._dlgLinetemplate
avatar = utils.userAvatar
for uid in users:
if uid in entities:
name = entities[uid].basic["name"]
data = {
"icon": avatar(uid, entities[uid], "s"),
"title": name,
"meta": entities[uid].basic.get("jobTitle", ""),
}
output.append({"label": template % data, "type": "user", "value": uid})
cols = yield db.get_slice(myId, "entityGroupsMap", start=term.lower(), finish=finish.lower(), count=10)
groupIds = [x.column.name.split(":", 1)[1] for x in cols]
avatar = utils.groupAvatar
groups = {}
if groupIds:
groups = base.EntitySet(groupIds)
yield groups.fetchData()
for groupId in groupIds:
data = {
"icon": avatar(groupId, groups[groupId], "s"),
"title": groups[groupId].basic["name"],
"meta": groups[groupId].basic.get("desc", " "),
}
obj = {"value": groupId, "label": template % data, "type": "group"}
output.append(obj)
request.write(json.dumps(output))
示例13: _unlike
def _unlike(self, request, data=None):
(appchange, script, args, myId) = yield self._getBasicArgs(request)
orgId = args['orgId']
itemId, item = data['id']
item = yield Item.unlike(itemId, item, myId, orgId)
if not item:
return
args["items"] = {itemId: item}
args["myLikes"] = {itemId: []}
likesCount = int(item["meta"]["likesCount"])
convId = item["meta"].get('parent', itemId)
if itemId != convId:
t.renderScriptBlock(request, "item.mako", "item_footer", False,
"#item-footer-%s" % (itemId), "set",
args=[itemId], **args)
else:
relation = Relation(myId, [])
yield relation.initSubscriptionsList()
toFetchEntities = set()
likes = []
subscriptions = list(relation.subscriptions)
if subscriptions:
likes = yield db.get_slice(convId, "itemLikes", subscriptions)
likes = [x.column.name for x in likes]
toFetchEntities = set(likes)
feedItems = yield db.get_slice(myId, "feedItems", [convId])
feedItems = utils.supercolumnsToDict(feedItems)
isFeed = (utils.getRequestArg(request, "_pg") != "/item")
hasComments = False
if not isFeed:
hasComments = True
else:
feedItems = yield db.get_slice(myId, "feedItems", [convId])
feedItems = utils.supercolumnsToDict(feedItems)
for tuuid in feedItems.get(convId, {}):
val = feedItems[convId][tuuid]
rtype = val.split(":")[0]
if rtype == "C":
hasComments = True
entities = base.EntitySet(toFetchEntities)
if toFetchEntities:
yield entities.fetchData()
args["entities"] = entities
handler = {"onload": "(function(){$$.convs.showHideComponent('%s', 'likes', false)})();" % (convId)} if not likes else None
t.renderScriptBlock(request, "item.mako", "conv_footer", False,
"#item-footer-%s" % (itemId), "set",
args=[itemId, hasComments, likes], **args)
t.renderScriptBlock(request, "item.mako", 'conv_likes', False,
'#conv-likes-wrapper-%s' % convId, 'set', True,
args=[itemId, likesCount, False, likes], handlers=handler, **args)
示例14: fetchData
def fetchData(self, columns=None):
if columns == None:
columns = ['basic']
if columns == []:
data = yield db.get_slice(self.id, "entities")
else:
data = yield db.get_slice(self.id, "entities", columns)
data = utils.supercolumnsToDict(data)
self._data = data
示例15: _getFileInfo
def _getFileInfo(self, request):
"""Fetch the meta info on a file that is being requested to be
downloaded. Returns the meta info of the file in question.
Keyword Arguments:
itemId: id of the conversation on which this file is attached.
attachmentId: id of the file on the amazon S3 that is to be served.
version: version of the file on the amazon S3 that the user is
requesting.
"""
authinfo = request.getSession(IAuthInfo)
myId = authinfo.username
myOrgId = authinfo.organization
itemId = utils.getRequestArg(request, "id", sanitize=False)
attachmentId = utils.getRequestArg(request, "fid", sanitize=False)
version = utils.getRequestArg(request, "ver", sanitize=False) or ''
columns = ["meta", "attachments", "participants"]
if not (itemId and attachmentId):
raise errors.MissingParams([])
item = yield db.get_slice(itemId, "mConversations", columns)
item = utils.supercolumnsToDict(item)
if not item:
raise errors.InvalidMessage(itemId)
if myId not in item.get('participants', {}):
raise errors.MessageAccessDenied(itemId)
# Check if the attachmentId belong to item
if attachmentId not in item['attachments'].keys():
raise errors.InvalidAttachment(itemId, attachmentId, version)
fileId, filetype, name = None, 'text/plain', 'file'
if version:
version = utils.decodeKey(version)
try:
cols = yield db.get(attachmentId, "attachmentVersions", version)
except ttypes.NotFoundException:
raise errors.InvalidAttachment(itemId, attachmentId, version)
except ttypes.InvalidRequestException:
raise errors.InvalidAttachment(itemId, attachmentId, version)
cols = utils.columnsToDict([cols])
else:
cols = yield db.get_slice(attachmentId, "attachmentVersions", count=1, reverse=True)
cols = utils.columnsToDict(cols)
version = cols.keys()[0]
fileId, name, size, filetype = cols[version].split(':')
files = yield db.get_slice(fileId, "files", ["meta"])
files = utils.supercolumnsToDict(files)
url = files['meta']['uri']
owner = files["meta"]["owner"]
defer.returnValue([owner, url, filetype, size, name])