def send_files_to_contact(self, contact, path, fields, files): ''' Sends in a form given file and fields to given contact (at given path). ''' if not hasattr(self, "activity"): self.activity = None client = ContactClient(self.activity) try: client.post_files(contact, path, fields=fields, files=files) except HTTPError: self.activity.add_error(contact) self.activity.save()
def send_files_to_contact(self, contact, path, fields, files): ''' Sends in a form given file and fields to given contact (at given path). ''' if not hasattr(self, "activity"): self.activity = None client = ContactClient(self.activity) try: client.post_files(contact, path, fields=fields, files=files) except HTTPError: self.activity.add_error(contact) self.activity.save()
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()
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) if not hasattr(self, "activity"): self.activity = None 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()
def forward_to_contact(self, picture, contact, activity, method="POST"): ''' *picture is sent to *contact* via a request of which method is set as *method*. If request succeeds, error linked to this contact is removed. Else nothing is done and error code is returned. ''' client = ContactClient() try: if method == "POST": client.post_files( contact, CONTACT_PATH, {"json": str(picture.toJson(localized=False))}, [("picture", str(picture.path), picture.fetch_attachment("th_" + picture.path)) ], callback=(yield gen.Callback("retry")) ) response = yield gen.Wait("retry") else: body = picture.toJson(localized=False) response = client.put(contact, CONTACT_PATH, body, callback=(yield gen.Callback("retry"))) response = yield gen.Wait("retry") if response.error: message = "Retry picture request to a contact failed ({})." self.return_failure(message.format(method)) else: for error in activity.errors: if error["contactKey"] == contact.key: activity.errors.remove(error) activity.save() self.return_success("Picture request correctly resent.") except: self.return_failure("Picture resend to a contact failed again.")
def forward_to_contact(self, picture, contact, activity, method="POST"): ''' *picture is sent to *contact* via a request of which method is set as *method*. If request succeeds, error linked to this contact is removed. Else nothing is done and error code is returned. ''' client = ContactClient() try: if method == "POST": client.post_files( contact, CONTACT_PATH, {"json": str(picture.toJson(localized=False))}, [("picture", str(picture.path), picture.fetch_attachment("th_" + picture.path))], callback=(yield gen.Callback("retry"))) response = yield gen.Wait("retry") else: body = picture.toJson(localized=False) response = client.put(contact, CONTACT_PATH, body, callback=(yield gen.Callback("retry"))) response = yield gen.Wait("retry") if response.error: message = "Retry picture request to a contact failed ({})." self.return_failure(message.format(method)) else: for error in activity.errors: if error["contactKey"] == contact.key: activity.errors.remove(error) activity.save() self.return_success( "Picture request correctly resent.") except: self.return_failure("Picture resend to a contact failed again.")