Esempio n. 1
0
    def put(self):
        '''
        When a delete request from a contact is incoming, it executes the 
        delete request locally then it creates a new activity corresponding
        to this deletion.
        '''

        data = self.get_body_as_dict(expectedFields=["date", "authorKey"])

        if data:
            authorKey = data["authorKey"]
            date = data["date"]

            micropost = MicroPostManager.get_contact_micropost(authorKey, date)
            contact = ContactManager.getTrustedContact(authorKey)

            if micropost and contact:
                self.create_deletion_activity(contact, micropost, "deletes",
                        "micropost")
                micropost.delete()

                self._write_delete_log(micropost)
                self.return_success("Micropost deleted.")

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

        else:
            self.return_failure("No data sent.", 400)
Esempio n. 2
0
    def post(self):
        '''
        When post request is received, micropost content is expected inside
        a string under *content* of JSON object. It is extracted from it
        then stored inside a new Microposts object. Micropost author and date
        are set from incoming data.
        '''

        data = self.get_body_as_dict(expectedFields=["date", "authorKey"])

        if data:
            db_date = data.get("date")
            date = date_util.get_date_from_db_date(db_date)
            authorKey = data.get("authorKey")

            contact = ContactManager.getTrustedContact(authorKey)
            micropost = MicroPostManager.get_contact_micropost(
                             authorKey, db_date)

            if contact:
                if not micropost:
                    micropost = MicroPost(
                        authorKey = authorKey,
                        author = data["author"],
                        content = data['content'],
                        date = date,
                        attachments = data.get("attachments", []),
                        isMine = False,
                        tags = contact.tags
                    )
                    micropost.save()
                    self._notify_suscribers(micropost)

                self.create_creation_activity(contact, micropost, 
                        "writes", "micropost")
                self._write_create_log(micropost)
            
                self.return_json(micropost.toJson(), 201)

            else:
                self.return_failure("Contact is not registered.", 405)

        else:
            self.return_failure("No data sent.", 405)
Esempio n. 3
0
def when_i_retrieve_a_post_for_a_given_contact_and_a_given_date(step):
    world.micropost_contact = MicroPostManager.get_contact_micropost(
            world.user2.key, "2011-01-10T11:05:12Z")