本文整理汇总了Python中social.db.get_slice函数的典型用法代码示例。如果您正苦于以下问题:Python get_slice函数的具体用法?Python get_slice怎么用?Python get_slice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_slice函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:psunkari,项目名称:flocked-in,代码行数:32,代码来源:admin.py
示例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)
开发者ID:psunkari,项目名称:flocked-in,代码行数:27,代码来源:utils.py
示例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)
开发者ID:psunkari,项目名称:flocked-in,代码行数:33,代码来源:admin.py
示例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)
开发者ID:psunkari,项目名称:flocked-in,代码行数:34,代码来源:files.py
示例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
开发者ID:psunkari,项目名称:flocked-in,代码行数:25,代码来源:admin.py
示例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)
开发者ID:psunkari,项目名称:flocked-in,代码行数:32,代码来源:files.py
示例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)
开发者ID:psunkari,项目名称:flocked-in,代码行数:34,代码来源:Group.py
示例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))
开发者ID:psunkari,项目名称:flocked-in,代码行数:32,代码来源:presence.py
示例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())
开发者ID:psunkari,项目名称:flocked-in,代码行数:30,代码来源:poll.py
示例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))
开发者ID:psunkari,项目名称:flocked-in,代码行数:31,代码来源:auto.py
示例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])
开发者ID:psunkari,项目名称:flocked-in,代码行数:32,代码来源:apps.py
示例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))
开发者ID:psunkari,项目名称:flocked-in,代码行数:59,代码来源:auto.py
示例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)
开发者ID:psunkari,项目名称:flocked-in,代码行数:58,代码来源:item.py
示例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
开发者ID:psunkari,项目名称:flocked-in,代码行数:9,代码来源:base.py
示例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])
开发者ID:psunkari,项目名称:flocked-in,代码行数:57,代码来源:messaging.py
示例16: delete
def delete(self, myId, convId, conv):
log.debug("plugin:delete", convId)
user_tuids = {}
# Get the list of every user who responded to this event
res = yield db.get_slice(convId, "eventResponses")
attendees = [x.column.name.split(":", 1)[1] for x in res]
# Add all the invited people of the item
res = yield db.get_slice(convId, "items", ['invitees'])
res = utils.supercolumnsToDict(res)
attendees.extend(res["invitees"].keys())
invitedPeople = res["invitees"].keys()
log.debug("Maps", ["%s:%s"%(uId, convId) for \
uId in attendees])
# Get the Org and GroupIds if any.
convMeta = conv["meta"]
groupIds = convMeta["target"].split(",") if "target" in convMeta else []
attendees.extend(groupIds+[convMeta["org"]])
log.debug("Attendees", attendees)
# Get the timeuuids that were inserted for this user
res = yield db.multiget_slice(["%s:%s"%(uId, convId) for \
uId in attendees], "userAgendaMap")
res = utils.multiColumnsToDict(res)
for k, v in res.iteritems():
uid = k.split(":", 1)[0]
tuids = v.keys()
if tuids:
user_tuids[uid] = tuids
log.debug("userAgenda Removal", user_tuids)
# Delete their entries in the user's list of event entries
for attendee in user_tuids:
yield db.batch_remove({'userAgenda': [attendee]},
names=user_tuids[attendee])
# Delete invitation entries for invited people
invited_tuids = dict([[x, user_tuids[x]] for x in invitedPeople])
log.debug("userAgenda Invitation Removal", invited_tuids)
for attendee in invited_tuids:
yield db.batch_remove({'userAgenda': ['%s:%s' %(attendee, 'I')]},
names=invited_tuids[attendee])
log.debug("eventResponses Removal", convId)
# Delete the event's entry in eventResponses
yield db.remove(convId, "eventResponses")
log.debug("userAgendaMap Removal", user_tuids)
# Delete their entries in userAgendaMap
for attendee in user_tuids:
yield db.batch_remove({'userAgendaMap': ["%s:%s"%(attendee, convId)]},
names=user_tuids[attendee])
开发者ID:psunkari,项目名称:flocked-in,代码行数:57,代码来源:event.py
示例17: getGroups
def getGroups(me, entity, start='', count=PEOPLE_PER_PAGE):
"""get the groups of entity. (either groups of an organization
or groups of an user)
keyword params:
@me:
@entity: org/user
start: fetch group from @start
count: no.of groups to fetch.
"""
toFetchCount = count + 1
groups = {}
groupIds = []
myGroupsIds = []
groupFollowers = {}
pendingConnections = {}
toFetchGroups = set()
nextPageStart = ''
prevPageStart = ''
#TODO: list the groups in sorted order.
cols = yield db.get_slice(entity.id, 'entityGroupsMap',
start=start, count=toFetchCount)
groupIds = [x.column.name for x in cols]
if len(groupIds) > count:
nextPageStart = utils.encodeKey(groupIds[-1])
groupIds = groupIds[0:count]
toFetchGroups.update(set([y.split(':', 1)[1] for y in groupIds]))
if entity.id == me.id:
myGroupsIds = [x.split(':', 1)[1] for x in groupIds]
elif groupIds:
cols = yield db.get_slice(me.id, "entityGroupsMap", groupIds)
myGroupsIds = [x.column.name.split(':', 1)[1] for x in cols]
groupIds = [x.split(':', 1)[1] for x in groupIds]
if start:
cols = yield db.get_slice(entity.id, 'entityGroupsMap', start=start,
count=toFetchCount, reverse=True)
if len(cols) > 1:
prevPageStart = utils.encodeKey(cols[-1].column.name)
if toFetchGroups:
groups = base.EntitySet(toFetchGroups)
yield groups.fetchData()
groupFollowers = yield db.multiget_slice(toFetchGroups, "followers",
names=[me.id])
groupFollowers = utils.multiColumnsToDict(groupFollowers)
columns = reduce(lambda x, y: x + y, [["GO:%s" % (x), "GI:%s" % (x)] for x in toFetchGroups])
cols = yield db.get_slice(me.id, 'pendingConnections', columns)
pendingConnections = utils.columnsToDict(cols)
data = {"entities": groups, "groupIds": groupIds,
"pendingConnections": pendingConnections,
"myGroups": myGroupsIds, "groupFollowers": groupFollowers,
"nextPageStart": nextPageStart, "prevPageStart": prevPageStart}
defer.returnValue(data)
开发者ID:psunkari,项目名称:flocked-in,代码行数:56,代码来源:Group.py
示例18: edit
def edit(me, group, name, access, desc, displayPic):
"""update group meta info.
Only group-admin can edit group meta info.
Keyword params:
@me:
@group:
@name: name of the group.
@access: group access type (open/closed).
@desc: description of the group.
@displayPic: profile pic of the group.
"""
if me.id not in group.admins:
raise errors.PermissionDenied('Only administrator can edit group meta data')
if name:
start = name.lower() + ':'
cols = yield db.get_slice(me.basic['org'], "entityGroupsMap",
start=start, count=1)
for col in cols:
name_, groupId_ = col.column.name.split(':')
if name_ == name.lower() and groupId_ != group.id:
raise errors.InvalidGroupName(name)
meta = {'basic': {}}
if name and name != group.basic['name']:
meta['basic']['name'] = name
if desc and desc != group.basic.get('desc', ''):
meta['basic']['desc'] = desc
if access in ['closed', 'open'] and access != group.basic['access']:
meta['basic']['access'] = access
if displayPic:
avatar = yield saveAvatarItem(group.id, me.basic['org'], displayPic)
meta['basic']['avatar'] = avatar
if name and name != group.basic["name"]:
members = yield db.get_slice(group.id, "groupMembers")
members = utils.columnsToDict(members).keys()
entities = members + [me.basic['org']]
oldColName = "%s:%s" % (group.basic["name"].lower(), group.id)
colname = '%s:%s' % (name.lower(), group.id)
mutations = {}
for entity in entities:
mutations[entity] = {'entityGroupsMap': {colname: '',
oldColName: None}}
#XXX:notify group-members about the change in name
yield db.batch_mutate(mutations)
if meta['basic']:
yield db.batch_insert(group.id, 'entities', meta)
if not desc and group.basic.get('desc', ''):
yield db.remove(group.id, "entities", 'desc', 'basic')
if (not desc and group.basic.get('desc', '')) or meta['basic']:
defer.returnValue(True)
开发者ID:psunkari,项目名称:flocked-in,代码行数:53,代码来源:Group.py
示例19: getManagedGroups
def getManagedGroups(me, start, count=PEOPLE_PER_PAGE):
"""get all groups managed by me
Keyword params:
@me:
@start: get groups from @start.
@count: no.of groups to be fetched.
"""
groups = {}
groupIds = []
myGroupsIds = []
nextPageStart = ''
prevPageStart = ''
toFetchCount = count + 1
toFetchGroups = set()
groupFollowers = {}
pendingConnections = {}
try:
cols = yield db.get_slice(me.id, "entities",
super_column='adminOfGroups',
start=start, count=toFetchCount)
groupIds = [x.column.name for x in cols]
toFetchGroups.update(set(groupIds))
myGroupsIds = groupIds
if len(groupIds) > count:
nextPageStart = utils.encodeKey(groupIds[-1])
groupIds = groupIds[0:count]
except ttypes.NotFoundException:
pass
if start:
cols = yield db.get_slice(me.id, "entities",
super_column='adminOfGroups', start=start,
count=toFetchCount, reverse=True)
if len(cols) > 1:
prevPageStart = utils.encodeKey(cols[-1].column.name)
if toFetchGroups:
groups = base.EntitySet(toFetchGroups)
yield groups.fetchData()
groupFollowers = yield db.multiget_slice(toFetchGroups, "followers", names=[me.id])
groupFollowers = utils.multiColumnsToDict(groupFollowers)
columns = reduce(lambda x, y: x + y, [["GO:%s" % (x), "GI:%s" % (x)] for x in toFetchGroups])
cols = yield db.get_slice(me.id, 'pendingConnections', columns)
pendingConnections = utils.columnsToDict(cols)
data = {"entities": groups, "groupIds": groupIds,
"pendingConnections": pendingConnections,
"myGroups": myGroupsIds, "groupFollowers": groupFollowers,
"nextPageStart": nextPageStart, "prevPageStart": prevPageStart}
defer.returnValue(data)
开发者ID:psunkari,项目名称:flocked-in,代码行数:52,代码来源:Group.py
示例20: _listBlockedUsers
def _listBlockedUsers(self, request):
(appchange, script, args, myId) = yield self._getBasicArgs(request)
orgId = args["orgId"]
landing = not self._ajax
start = utils.getRequestArg(request, 'start') or ''
start = utils.decodeKey(start)
count = PEOPLE_PER_PAGE
toFetchCount = count + 1
nextPageStart = ''
prevPageStart = ''
args["title"] = "Manage Users"
args["menuId"] = "users"
args["viewType"] = "blocked"
if script and landing:
t.render(request, "admin.mako", **args)
if script and appchange:
t.renderScriptBlock(request, "admin.mako", "layout",
landing, "#mainbar", "set", **args)
args["heading"] = "Admin Console - Blocked Users"
cols = yield db.get_slice(orgId, "blockedUsers",
start=start, count=toFetchCount)
blockedUsers = [col.column.name for col in cols]
if len(blockedUsers) > count:
nextPageStart = utils.encodeKey(blockedUsers[-1])
blockedUsers = blockedUsers[:count]
if start:
cols = yield db.get_slice(orgId, "blockedUsers", start=start,
count=toFetchCount, reverse=True)
if len(cols) > 1:
prevPageStart = utils.decodeKey(cols[-1].column.name)
entities = base.EntitySet(blockedUsers)
yield entities.fetchData()
args["entities"] = entities
args['nextPageStart'] = nextPageStart
args['prevPageStart'] = prevPageStart
if script:
t.renderScriptBlock(request, "admin.mako", "viewOptions",
landing, "#users-view", "set", **args)
t.renderScriptBlock(request, "admin.mako", "list_users",
landing, "#content", "set", **args)
if script and landing:
request.write("</body></html>")
if not script:
t.render(request, "admin.mako", **args)
开发者ID:psunkari,项目名称:flocked-in,代码行数:51,代码来源:admin.py
注:本文中的social.db.get_slice函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论