예제 #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")
                postIndexer = indexer.Indexer()
                postIndexer.remove_doc(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)
예제 #2
0
파일: handlers.py 프로젝트: mpmedia/newebe
    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")
                postIndexer = indexer.Indexer()
                postIndexer.remove_doc(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)
예제 #3
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", []),
                        pictures_to_download=data.get("pictures", []),
                        commons_to_download=data.get("commons", []),
                        isMine=False,
                        tags=contact.tags)
                    micropost.save()

                    self.create_creation_activity(contact, micropost, "writes",
                                                  "micropost")
                    self._write_create_log(micropost)

                    postIndexer = indexer.Indexer()
                    postIndexer.index_micropost(micropost)
                    for websocket_client in websocket_clients:
                        websocket_client.write_message(micropost.toJson())

                self.return_json(micropost.toJson(), 201)

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

        else:
            self.return_failure("No data sent.", 405)
예제 #4
0
파일: handlers.py 프로젝트: prologic/newebe
    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", []),
                        pictures_to_download=data.get("pictures", []),
                        commons_to_download=data.get("commons", []),
                        isMine=False,
                        tags=contact.tags,
                    )
                    micropost.save()

                    self.create_creation_activity(contact, micropost, "writes", "micropost")
                    self._write_create_log(micropost)

                    postIndexer = indexer.Indexer()
                    postIndexer.index_micropost(micropost)
                    for websocket_client in websocket_clients:
                        websocket_client.write_message(micropost.toJson())

                self.return_json(micropost.toJson(), 201)

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

        else:
            self.return_failure("No data sent.", 405)
예제 #5
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")
예제 #6
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")