本文整理汇总了Python中newebe.apps.contacts.models.ContactManager类的典型用法代码示例。如果您正苦于以下问题:Python ContactManager类的具体用法?Python ContactManager怎么用?Python ContactManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContactManager类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: delete
def delete(self, id):
'''
Deletes given tag.
'''
tag = ContactManager.getTag(id)
name = tag.name
tag.delete()
for contact in ContactManager.getTrustedContacts():
if name in contact.tags:
contact.tags.remove(name)
contact.save()
self.return_success("Tag successfully deleted.", 204)
开发者ID:WentaoXu,项目名称:newebe,代码行数:15,代码来源:handlers.py
示例2: on_picture_found
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.")
开发者ID:DopeChicCity,项目名称:newebe,代码行数:29,代码来源:handlers.py
示例3: put
def put(self):
'''
Delete picture of which data are given inside request.
Picture is found with contact key and creation date.
If author is not inside trusted contacts, the request is rejected.
'''
data = self.get_body_as_dict()
if data:
contact = ContactManager.getTrustedContact(
data.get("authorKey", ""))
if contact:
picture = PictureManager.get_contact_picture(
contact.key, data.get("date", ""))
if picture:
self.create_deletion_activity(contact,
picture, "deletes", "picture")
picture.delete()
self.return_success("Deletion succeeds")
else:
self.return_failure("Author is not trusted.", 400)
else:
self.return_failure("No data sent.", 405)
开发者ID:mpmedia,项目名称:newebe,代码行数:30,代码来源:handlers.py
示例4: post
def post(self, key):
'''
Resend post 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"}
'''
picture = PictureManager.get_picture(key)
idInfos = self.request.body
ids = json_decode(idInfos)
if picture and idInfos:
contactId = ids["contactId"]
activityId = ids["activityId"]
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:
info = "Attemp to resend a picture to contact: {}."
logger.info(info.format(contact.name))
self.forward_to_contact(picture, contact, activity)
else:
self.return_failure("Picture not found", 404)
开发者ID:mpmedia,项目名称:newebe,代码行数:29,代码来源:handlers.py
示例5: put
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)
开发者ID:WentaoXu,项目名称:newebe,代码行数:35,代码来源:handlers.py
示例6: get
def get(self):
'''
Retrieves whole contact list at JSON format.
'''
contacts = ContactManager.getContacts()
self.return_documents(contacts)
开发者ID:mpmedia,项目名称:newebe,代码行数:7,代码来源:handlers.py
示例7: post
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)
开发者ID:prologic,项目名称:newebe,代码行数:34,代码来源:handlers.py
示例8: get
def get(self):
'''
Returns the list of available tags.
'''
tags = ContactManager.getTags()
tags.insert(0, ContactTag(name="all"))
self.return_documents(tags)
开发者ID:WentaoXu,项目名称:newebe,代码行数:8,代码来源:handlers.py
示例9: delete
def delete(self, slug):
'''
Deletes contact corresponding to slug.
'''
contact = ContactManager.getContact(slug)
if contact:
contact.delete()
return self.return_success("Contact has been deleted.")
else:
self.return_failure("Contact does not exist.")
开发者ID:mpmedia,项目名称:newebe,代码行数:11,代码来源:handlers.py
示例10: post
def post(self):
'''
Creates a new tag.
'''
data = self.get_body_as_dict(["name"])
tag = ContactManager.getTagByName(data["name"])
if tag is None:
tag = ContactTag(name=data["name"])
tag.save()
self.return_one_document(tag, 201)
开发者ID:DopeChicCity,项目名称:newebe,代码行数:11,代码来源:handlers.py
示例11: check_that_request_date_is_set_to_europe_paris_timezone
def check_that_request_date_is_set_to_europe_paris_timezone(step, timezone):
Contact._db = db2
contact = ContactManager.getRequestedContacts().first()
Contact._db = db
date = date_util.get_date_from_db_date(world.contacts[0]["requestDate"])
tz = pytz.timezone(timezone)
date = date.replace(tzinfo=tz)
assert_equals(
date_util.convert_utc_date_to_timezone(contact.requestDate, tz),
date)
开发者ID:mpmedia,项目名称:newebe,代码行数:11,代码来源:steps.py
示例12: send_profile_to_contacts
def send_profile_to_contacts(self):
'''
External methods to not send too much times the changed profile.
A timer is set to wait for other modifications before running this
function that sends modification requests to every contacts.
'''
client = HTTPClient()
self.sending_data = False
user = UserManager.getUser()
jsonbody = user.toJson()
activity = Activity(
authorKey=user.key,
author=user.name,
verb="modifies",
docType="profile",
method="PUT",
docId="none",
isMine=True
)
activity.save()
for contact in ContactManager.getTrustedContacts():
try:
request = HTTPRequest(
"%scontacts/update-profile/" % contact.url,
method="PUT",
body=jsonbody,
validate_cert=False)
response = client.fetch(request)
if response.error:
logger.error("""
Profile sending to a contact failed, error infos are
stored inside activity.
""")
activity.add_error(contact)
activity.save()
except:
logger.error("""
Profile sending to a contact failed, error infos are
stored inside activity.
""")
activity.add_error(contact)
activity.save()
logger.info("Profile update sent to all contacts.")
开发者ID:mpmedia,项目名称:newebe,代码行数:50,代码来源:handlers.py
示例13: get
def get(self):
'''
Asks for all contacts to resend their data from last month.
As answer contacts send their profile. So contact data are updated,
then contacts resend all their from their last month just like they
were posted now.
Current newebe has to check himself if he already has these data.
'''
client = ContactClient()
user = UserManager.getUser()
self.contacts = dict()
for contact in ContactManager.getTrustedContacts():
self.ask_to_contact_for_sync(client, user, contact)
self.return_success("", 200)
开发者ID:DopeChicCity,项目名称:newebe,代码行数:16,代码来源:handlers.py
示例14: send_files_to_contacts
def send_files_to_contacts(self, path, fields, files, tag=None):
'''
Sends in a form given file and fields to all trusted contacts (at given
path).
If any error occurs, it is stored in linked activity.
'''
contacts = ContactManager.getTrustedContacts(tag=tag)
client = ContactClient(self.activity)
for contact in contacts:
try:
client.post_files(contact, path, fields=fields, files=files)
except HTTPError:
self.activity.add_error(contact)
self.activity.save()
开发者ID:savitasinghvit,项目名称:newebe,代码行数:16,代码来源:handlers.py
示例15: send_creation_to_contacts
def send_creation_to_contacts(self, path, doc):
'''
Sends a POST request to all trusted contacts.
Request body contains object to post at JSON format.
'''
tag = None
if doc.tags:
tag = doc.tags[0]
contacts = ContactManager.getTrustedContacts(tag=tag)
client = ContactClient(self.activity)
for contact in contacts:
try:
client.post(contact, path, doc.toJson(localized=False))
except HTTPError:
self.activity.add_error(contact)
self.activity.save()
开发者ID:WentaoXu,项目名称:newebe,代码行数:18,代码来源:handlers.py
示例16: on_picture_found
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.")
开发者ID:mpmedia,项目名称:newebe,代码行数:19,代码来源:handlers.py
注:本文中的newebe.apps.contacts.models.ContactManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论