本文整理汇总了Python中newebe.apps.contacts.models.ContactManager.getTrustedContact方法的典型用法代码示例。如果您正苦于以下问题:Python ContactManager.getTrustedContact方法的具体用法?Python ContactManager.getTrustedContact怎么用?Python ContactManager.getTrustedContact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类newebe.apps.contacts.models.ContactManager
的用法示例。
在下文中一共展示了ContactManager.getTrustedContact方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getTrustedContact [as 别名]
def put(self):
'''
When a put request is received, contact data are expected. If contact
key is one of the trusted contact key, its data are updated with
received ones.
'''
data = self.get_body_as_dict(["key", "url", "name", "description"])
if data:
key = data["key"]
contact = ContactManager.getTrustedContact(key)
if contact:
contact.url = data["url"]
contact.description = data["description"]
contact.name = data["name"]
contact.save()
self.create_modify_activity(contact, "modifies", "profile")
self.return_success("Contact successfully modified.")
else:
self.return_failure(
"No contact found corresponding to given contact", 404)
else:
self.return_failure("Empty data or missing field.")
示例2: post
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getTrustedContact [as 别名]
def post(self, postId):
"""
Grab from contact the file corresponding to given path and given post
(post of which ID is equal to *postId*).
"""
data = self.get_body_as_dict(expectedFields=["path"])
micropost = MicroPostManager.get_micropost(postId)
contact = ContactManager.getTrustedContact(micropost.authorKey)
user = UserManager.getUser()
if micropost and data and contact:
path = data["path"]
client = ContactClient()
body = {"date": date_util.get_db_date_from_date(micropost.date), "contactKey": user.key, "path": path}
client.post(
contact, "microposts/contacts/attach/", json_encode(body), callback=(yield gen.Callback("getattach"))
)
response = yield gen.Wait("getattach")
if response.error:
self.return_failure("An error occured while retrieving picture.")
else:
micropost.put_attachment(response.body, data["path"])
self.return_success("Download succeeds.")
else:
if not data:
self.return_failure("Wrong data.", 400)
elif not contact:
self.return_failure("Contact no more available.", 400)
else:
self.return_failure("Micropost not found.", 404)
示例3: post
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.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)
示例4: on_picture_found
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.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()
print CURRENT_DOWNLOADS
print "data picture id %s" % data["picture"]["_id"]
for download in CURRENT_DOWNLOADS:
print "download %s " % download
if download == data["picture"]["_id"]:
return self.return_success('already downloading')
CURRENT_DOWNLOADS.append(data["picture"]["_id"])
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.")
示例5: put
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getTrustedContact [as 别名]
def put(self, key):
"""
Resend deletion of micropost with *key* as key to the contact given in
the posted JSON. Corresponding activity ID is given inside the posted
json.
Here is the format : {"contactId":"data","activityId":"data"}
"""
data = self.get_body_as_dict(expectedFields=["contactId", "activityId", "extra"])
if data:
contactId = data["contactId"]
activityId = data["activityId"]
date = data["extra"]
contact = ContactManager.getTrustedContact(contactId)
activity = ActivityManager.get_activity(activityId)
if not contact:
self.return_failure("Contact not found", 404)
elif not activity:
self.return_failure("Activity not found", 404)
else:
user = UserManager.getUser()
picture = Picture(authorKey=user.key, date=date_util.get_date_from_db_date(date))
info = "Attempt to resend a picture deletion to contact: {}."
logger.info(info.format(contact.name))
self.forward_to_contact(picture, contact, activity, method="PUT")
else:
self.return_failure("Micropost not found", 404)
示例6: post
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getTrustedContact [as 别名]
def post(self):
'''
Extract picture and file linked to the picture from request, then
creates a picture in database for the contact who sends it. An
activity is created too.
If author is not inside trusted contacts, the request is rejected.
'''
file = self.request.files['picture'][0]
data = json_decode(self.get_argument("json"))
if file and data:
contact = ContactManager.getTrustedContact(
data.get("authorKey", ""))
if contact:
date = date_util.get_date_from_db_date(data.get("date", ""))
picture = PictureManager.get_contact_picture(
contact.key, data.get("date", ""))
if not picture:
picture = Picture(
_id=data.get("_id", ""),
title=data.get("title", ""),
path=data.get("path", ""),
contentType=data.get("contentType", ""),
authorKey=data.get("authorKey", ""),
author=data.get("author", ""),
tags=contact.tags,
date=date,
isMine=False,
isFile=False
)
picture.save()
picture.put_attachment(content=file["body"],
name="th_" + picture._id)
picture.save()
self.create_creation_activity(contact,
picture, "publishes", "picture")
logger.info("New picture from %s" % contact.name)
self.return_success("Creation succeeds", 201)
else:
self.return_failure("Author is not trusted.", 400)
else:
self.return_failure("No data sent.", 405)
示例7: on_common_found
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getTrustedContact [as 别名]
def on_common_found(self, common, id):
'''
'''
self.common = common
data = dict()
data["common"] = common.toDict(localized=False)
data["contact"] = UserManager.getUser().asContact().toDict()
contact = ContactManager.getTrustedContact(common.authorKey)
client = ContactClient()
body = json_encode(data)
try:
client.post(contact, u"commons/contact/download/",
body, self.on_download_finished)
except HTTPError:
self.return_failure("Cannot download common from contact.")
示例8: on_picture_found
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.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.")
示例9: get
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.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)
示例10: post
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.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.send_commons_to_contact(client, localContact, now, date)
self.return_document(UserManager.getUser().asContact())
else:
self.return_failure("Contact does not exist.")
示例11: on_picture_found
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.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()
if picture._id in CURRENT_DOWNLOADS:
self.return_success("already downloading")
else:
CURRENT_DOWNLOADS.append(picture._id)
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.")
示例12: get_trusted_contact_with_key
# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getTrustedContact [as 别名]
def get_trusted_contact_with_key(step, key):
world.contact = ContactManager.getTrustedContact(key)