示例#1
0
    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"}
        '''

        micropost = MicroPostManager.get_micropost(key)

        data = self.get_body_as_dict(
            expectedFields=["contactId", "activityId"])

        if micropost and data:

            contactId = data["contactId"]
            activityId = data["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:
                if contact.name:
                    info_str = "Attempt to resend a post to contact: %s."
                    logger.info(info_str % contact.name)
                self.forward_to_contact(micropost, contact, activity)
        else:
            self.return_failure("Micropost not found", 404)
示例#2
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()
                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)
示例#3
0
    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)
示例#4
0
    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"}
        '''
        common = CommonManager.get_common(key)
        idInfos = self.request.body

        ids = json_decode(idInfos)

        if common 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 common to contact: {}."
                logger.info(info.format(contact.name))
                self.forward_to_contact(common, contact, activity)
        else:
            self.return_failure("Common not found", 404)
示例#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)
示例#6
0
    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"}
        '''

        micropost = MicroPostManager.get_micropost(key)

        data = self.get_body_as_dict(expectedFields=["contactId",
                                                     "activityId"])

        if micropost and data:

            contactId = data["contactId"]
            activityId = data["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:
                if contact.name:
                    info_str = "Attempt to resend a post to contact: %s."
                    logger.info(info_str % contact.name)
                self.forward_to_contact(micropost, contact, activity)
        else:
            self.return_failure("Micropost not found", 404)
示例#7
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()
                common = Common(authorKey=user.key,
                                date=date_util.get_date_from_db_date(date))

                info = "Attemp to resend a common deletion to contact: {}."
                logger.info(info.format(contact.name))

                self.forward_to_contact(common,
                                        contact,
                                        activity,
                                        method="PUT")

        else:
            self.return_failure("Micropost not found", 404)
示例#8
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)
示例#9
0
文件: steps.py 项目: mpmedia/newebe
def get_activity_with_default_activity_id(step):

    world.new_activity = ActivityManager.get_activity(world.activity._id)
    assert world.new_activity is not None
示例#10
0
def and_first_activity_has_no_more_errors(step):
    activity = ActivityManager.get_activity(world.activity._id)
    assert 0 == len(activity.errors)
示例#11
0
def and_activity_has_no_more_errors(step):
    activity = ActivityManager.get_activity(world.activity._id)
    assert 0 == len(activity.errors)