本文整理汇总了Python中newebe.contacts.models.ContactManager.getTrustedContact方法的典型用法代码示例。如果您正苦于以下问题:Python ContactManager.getTrustedContact方法的具体用法?Python ContactManager.getTrustedContact怎么用?Python ContactManager.getTrustedContact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类newebe.contacts.models.ContactManager
的用法示例。
在下文中一共展示了ContactManager.getTrustedContact方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from newebe.contacts.models import ContactManager [as 别名]
# 或者: from newebe.contacts.models.ContactManager import getTrustedContact [as 别名]
def post(self):
'''
Returns file which is attached to post corresponding to a given
date (we assumed a user can't post two posts at the same time).
Expected data :
* path : file name
* date : date on which post was posted
* contactKey : the key of the contact which claims the file.
'''
data = self.get_body_as_dict(expectedFields=["path", "date",
"contactKey"])
if data:
contact = ContactManager.getTrustedContact(data["contactKey"])
micropost = MicroPostManager.get_first(data["date"])
if micropost and contact:
try:
fileContent = micropost.fetch_attachment(data["path"])
self.return_file(data["path"], fileContent)
except ResourceNotFound:
self.return_failure("File not found", 404)
else:
self.return_failure("Micropost not found.", 404)
else:
self.return_failure("Wrong data.", 400)
示例2: put
# 需要导入模块: from newebe.contacts.models import ContactManager [as 别名]
# 或者: from newebe.contacts.models.ContactManager import getTrustedContact [as 别名]
def put(self):
'''
When a delete request from a contact is incoming, it executes the
delete request locally then it creates a new activity corresponding
to this deletion.
'''
data = self.get_body_as_dict(expectedFields=["date", "authorKey"])
if data:
authorKey = data["authorKey"]
date = data["date"]
micropost = MicroPostManager.get_contact_micropost(authorKey, date)
contact = ContactManager.getTrustedContact(authorKey)
if micropost and contact:
self.create_deletion_activity(contact, micropost, "deletes",
"micropost")
micropost.delete()
self._write_delete_log(micropost)
self.return_success("Micropost deleted.")
else:
self.return_failure("Micropost not found", 404)
else:
self.return_failure("No data sent.", 400)
示例3: get
# 需要导入模块: from newebe.contacts.models import ContactManager [as 别名]
# 或者: from newebe.contacts.models.ContactManager import getTrustedContact [as 别名]
def get(self, key):
'''
Returns an HTML representation of contact corresponding to given
ID. If ID is equal to null Newebe owner representation is returned.
'''
if key == "null" or key == UserManager.getUser().key:
contact = UserManager.getUser().asContact()
else:
contact = ContactManager.getTrustedContact(key)
if contact:
if contact.description:
contact.description = markdown.markdown(contact.description)
self.render("templates/contact_render.html",
contact=contact)
else:
return self.return_failure("Contact not found.", 404)
示例4: post
# 需要导入模块: from newebe.contacts.models import ContactManager [as 别名]
# 或者: from newebe.contacts.models.ContactManager import getTrustedContact [as 别名]
def post(self):
'''
When sync request is received, if contact is a trusted contact, it
sends again all posts from last month to contact.
'''
client = ContactClient()
now = datetime.datetime.utcnow()
date = now - datetime.timedelta(365/12)
contact = self.get_body_as_dict()
localContact = ContactManager.getTrustedContact(contact.get("key", ""))
if localContact:
self.send_posts_to_contact(client, localContact, now, date)
self.send_pictures_to_contact(client, localContact, now, date)
self.return_document(UserManager.getUser().asContact())
else:
self.return_failure("Contact does not exist.")
示例5: on_picture_found
# 需要导入模块: from newebe.contacts.models import ContactManager [as 别名]
# 或者: from newebe.contacts.models.ContactManager import getTrustedContact [as 别名]
def on_picture_found(self, picture, id):
'''
'''
self.picture = picture
data = dict()
data["picture"] = picture.toDict(localized=False)
data["contact"] = UserManager.getUser().asContact().toDict()
contact = ContactManager.getTrustedContact(picture.authorKey)
client = ContactClient()
body = json_encode(data)
try:
client.post(contact, u"pictures/contact/download/",
body, self.on_download_finished)
except HTTPError:
self.return_failure("Cannot download picture from contact.")
示例6: get_trusted_contact_with_key
# 需要导入模块: from newebe.contacts.models import ContactManager [as 别名]
# 或者: from newebe.contacts.models.ContactManager import getTrustedContact [as 别名]
def get_trusted_contact_with_key(step, key):
world.contact = ContactManager.getTrustedContact(key)