本文整理汇总了Python中dbclient.DbClient.hasFriends方法的典型用法代码示例。如果您正苦于以下问题:Python DbClient.hasFriends方法的具体用法?Python DbClient.hasFriends怎么用?Python DbClient.hasFriends使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dbclient.DbClient
的用法示例。
在下文中一共展示了DbClient.hasFriends方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: servePage
# 需要导入模块: from dbclient import DbClient [as 别名]
# 或者: from dbclient.DbClient import hasFriends [as 别名]
def servePage(self, view, url, params):
print("Special function:", url)
if url == "/selectprofilepic":
# Get home directory for file dialog
homedir = os.path.expanduser("~/")
fname = QtGui.QFileDialog.getOpenFileName(view, I18nManager.getText("gui.dialogtitle.openimage"),
homedir, I18nManager.getText("gui.fileselection.filetypes.jpg"))
if fname:
view.page().mainFrame().evaluateJavaScript("updateProfilePic('" + fname + "');")
elif url == "/friendstorm":
if not DbClient.hasFriends():
view.page().mainFrame().evaluateJavaScript("window.alert('No friends :(');")
return
# Launch a storm
self.bs = Brainstorm(I18nManager.getText("contacts.storm.title"))
self.bs.show()
storm = Storm()
# Build up Nodes and Edges using our contact list and if possible our friends' contact lists
myTorId = DbClient.getOwnTorId()
friends = {}
friendsOfFriends = {}
for c in DbClient.getContactList():
#print("Contact:", c['torid'], "'", c['displayName'], "'")
nodeid = storm.getUnusedNodeId()
torid = c['torid']
friends[torid] = nodeid
storm.addNode(Node(None, nodeid, c['displayName']))
friendsOfFriends[torid] = c.get('contactlist', "")
for torid in friends:
if torid != myTorId:
storm.addEdge(friends[torid], friends[myTorId])
for torid in friendsOfFriends:
if torid != myTorId:
ffList = friendsOfFriends[torid]
if ffList:
for ff in ffList.split(","):
if ff and len(ff) > 16:
ffTorid = ff[:16]
ffName = ff[16:]
if ffTorid != myTorId:
if not friends.get(ffTorid, None):
# Friend's friend is not in the list yet - add it
nodeid = storm.getUnusedNodeId()
friends[ffTorid] = nodeid
storm.addNode(Node(None, nodeid, ffName))
# Add edge from torid to ffTorid
storm.addEdge(friends[torid], friends[ffTorid])
self.bs.setStorm(storm)
示例2: testGetProfile
# 需要导入模块: from dbclient import DbClient [as 别名]
# 或者: from dbclient.DbClient import hasFriends [as 别名]
def testGetProfile(self):
# Delete whole profiles table
DbClient._getProfileTable().remove({})
self.assertEqual(DbClient._getProfileTable().count(), 0, "Profiles table should be empty")
# Add own profile
myTorId = "ABC123DEF456GH78"
myprofile = {"name" : "Constantin Taylor", "keyid" : "someKeyId", "displayName" : "Me",
"status" : "self", "ownprofile" : True}
DbClient.updateContact(myTorId, myprofile)
self.assertEqual(DbClient._getProfileTable().count(), 1, "Profiles table should have my profile in it")
profileFromDb = DbClient.getProfile(None)
self.assertIsNotNone(profileFromDb, "Couldn't retrieve own profile")
profileFromDb = DbClient.getProfile(myTorId)
self.assertIsNotNone(profileFromDb, "Couldn't retrieve profile using own id")
# Initiate contact with a new person
otherTorId = "PQR123STU456VWX78"
otherName = "Olivia Barnacles"
DbClient.updateContact(otherTorId, {"status" : "untrusted", "keyid" : "donotknow", "name" : otherName})
self.assertEqual(DbClient._getProfileTable().count(), 2, "Profiles table should have 2 profiles")
self.assertEqual(DbClient.getMessageableContacts().count(), 1, "Profiles table should have 1 messageable")
self.assertEqual(DbClient.getTrustedContacts().count(), 0, "Profiles table should have 0 trusted")
profileFromDb = DbClient.getProfile(otherTorId)
self.assertIsNotNone(profileFromDb, "Couldn't retrieve profile using other id")
self.assertEqual(profileFromDb.get("name", None), otherName, "Profile name doesn't match what was stored")
self.assertEqual(profileFromDb.get("status", None), "untrusted", "Profile status doesn't match what was stored")
# Update existing record, change status
DbClient.updateContact(otherTorId, {"status" : "trusted"})
self.assertEqual(DbClient._getProfileTable().count(), 2, "Profiles table should still have 2 profiles")
profileFromDb = DbClient.getProfile(otherTorId)
self.assertIsNotNone(profileFromDb, "Couldn't retrieve profile using other id")
self.assertEqual(profileFromDb.get("status", None), "trusted", "Profile status should have been updated")
self.assertEqual(DbClient.getMessageableContacts().count(), 1, "Profiles table should have 1 messageable")
self.assertEqual(DbClient.getTrustedContacts().count(), 1, "Profiles table should have 1 trusted")
# Delete other contact
DbClient.updateContact(otherTorId, {"status" : "deleted"})
self.assertEqual(DbClient.getMessageableContacts().count(), 0, "Profiles table should have 0 messageable")
self.assertEqual(DbClient.getTrustedContacts().count(), 0, "Profiles table should have 0 trusted")
self.assertFalse(DbClient.hasFriends(), "Shouldn't have any friends any more")