コード例 #1
0
ファイル: handlers.py プロジェクト: mpmedia/newebe
    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()
                micropost = MicroPost(
                    authorKey=user.key,
                    date=date_util.get_date_from_db_date(date)
                )

                logger.info(
                    "Attempt to resend a post deletion to contact: {}.".format(
                        contact.name))
                httpClient = ContactClient()
                body = micropost.toJson(localized=False)

                try:
                    httpClient.put(contact, CONTACT_PATH, body,
                                   callback=(yield gen.Callback("retry")))
                    response = yield gen.Wait("retry")

                    if response.error:
                        self.return_failure(
                                "Deleting micropost to contact failed.")

                    else:
                        for error in activity.errors:
                            if error["contactKey"] == contact.key:
                                activity.errors.remove(error)
                                activity.save()
                                self.return_success(
                                        "Micropost correctly redeleted.")

                except:
                    self.return_failure("Deleting micropost to contact failed.")

        else:
            self.return_failure("Micropost not found", 404)
コード例 #2
0
ファイル: handlers.py プロジェクト: DopeChicCity/newebe
    def forward_to_contact(self, common, contact, activity, method="POST"):
        '''
        *common 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()
        body = common.toJson()

        try:
            if method == "POST":
                client.post(contact, CONTACT_PATH, body,
                            callback=(yield gen.Callback("retry")))
                response = yield gen.Wait("retry")
            else:
                body = common.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 common 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("Common request correctly resent.")

        except:
            self.return_failure("Common resend to a contact failed again.")
コード例 #3
0
ファイル: handlers.py プロジェクト: HeartbliT/IReVeAI
    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.")
コード例 #4
0
ファイル: handlers.py プロジェクト: mike-perdide/newebe
    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:
                self.return_failure(
                  "Retry picture request to a contact failed ({}).".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.")
コード例 #5
0
    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()
                micropost = MicroPost(
                    authorKey=user.key,
                    date=date_util.get_date_from_db_date(date))

                logger.info(
                    "Attempt to resend a post deletion to contact: {}.".format(
                        contact.name))
                httpClient = ContactClient()
                body = micropost.toJson(localized=False)

                try:
                    httpClient.put(contact,
                                   CONTACT_PATH,
                                   body,
                                   callback=(yield gen.Callback("retry")))
                    response = yield gen.Wait("retry")

                    if response.error:
                        self.return_failure(
                            "Deleting micropost to contact failed.")

                    else:
                        for error in activity.errors:
                            if error["contactKey"] == contact.key:
                                activity.errors.remove(error)
                                activity.save()
                                self.return_success(
                                    "Micropost correctly redeleted.")

                except:
                    self.return_failure(
                        "Deleting micropost to contact failed.")

        else:
            self.return_failure("Micropost not found", 404)