本文整理汇总了Python中newebe.contacts.models.ContactManager类的典型用法代码示例。如果您正苦于以下问题:Python ContactManager类的具体用法?Python ContactManager怎么用?Python ContactManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContactManager类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self, slug):
'''
When post request is received, contact of which slug is equal to
slug is retrieved. If its state is Pending or Error, the contact
request is send again.
'''
logger = logging.getLogger("newebe.contact")
self.contact = ContactManager.getContact(slug)
owner = UserManager.getUser()
if self.contact and self.contact.url != owner.url:
try:
data = owner.asContact().toJson()
client = ContactClient()
client.post(self.contact, "contacts/request/", data,
self.on_contact_response)
except Exception:
import traceback
logger.error("Error on adding contact:\n %s" %
traceback.format_exc())
self.contact.state = STATE_ERROR
self.contact.save()
self.return_one_document(self.contact)
else:
self.return_failure("Contact does not exist", 404)
示例2: 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)
示例3: get
def get(self):
'''
Retrieves whole contact list at JSON format.
'''
contacts = ContactManager.getContacts()
self.return_documents(contacts)
示例4: 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.")
示例5: 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)
示例6: 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.
'''
contacts = ContactManager.getTrustedContacts()
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()
示例7: 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.")
示例8: send_files_to_contacts
def send_files_to_contacts(self, path, fields, files):
'''
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()
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()
示例9: 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)
示例10: send_deletion_to_contacts
def send_deletion_to_contacts(self, path, doc):
'''
Send a delete request (PUT because Tornado don't handle DELETE request
with a body) to all trusted contacts.
Request body contains object to delete at JSON format.
'''
contacts = ContactManager.getTrustedContacts()
client = ContactClient(self.activity)
date = date_util.get_db_date_from_date(doc.date)
for contact in contacts:
try:
client.delete(contact, path, doc.toJson(localized=False), date)
except HTTPError:
import pdb
pdb.set_trace()
self.activity.add_error(contact, extra=date)
self.activity.save()
示例11: 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.")
示例12: post
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.")