예제 #1
0
    def delete(self, id):
        '''
        Deletes the post of which id is equal to postId, add an activity and
        forwards the delete request to each trusted contact.

        put instead of delete because tornado does not support body in DELETE
        requests...
        '''

        micropost = MicroPostManager.get_micropost(id)

        if micropost:
            user = UserManager.getUser()

            if micropost.authorKey == user.key:
                self.create_owner_deletion_activity(micropost, "deletes",
                                                    "micropost")
                self.send_deletion_to_contacts(CONTACT_PATH, micropost)
            postIndexer = indexer.Indexer()
            postIndexer.remove_doc(micropost)
            micropost.delete()
            self.return_success("Micropost deletion succeeds.")

        else:
            self.return_failure("Micropost not found.", 404)
예제 #2
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)
예제 #3
0
파일: handlers.py 프로젝트: mpmedia/newebe
    def delete(self, id):
        '''
        Deletes the post of which id is equal to postId, add an activity and
        forwards the delete request to each trusted contact.

        put instead of delete because tornado does not support body in DELETE
        requests...
        '''

        micropost = MicroPostManager.get_micropost(id)

        if micropost:
            user = UserManager.getUser()

            if micropost.authorKey == user.key:
                self.create_owner_deletion_activity(
                    micropost, "deletes", "micropost")
                self.send_deletion_to_contacts(CONTACT_PATH, micropost)
            postIndexer = indexer.Indexer()
            postIndexer.remove_doc(micropost)
            micropost.delete()
            self.return_success("Micropost deletion succeeds.")

        else:
            self.return_failure("Micropost not found.", 404)
예제 #4
0
파일: handlers.py 프로젝트: mpmedia/newebe
    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)
예제 #5
0
파일: handlers.py 프로젝트: prologic/newebe
    def post(self, postId):
        """
        Grab from contact the file corresponding to given path and given post
        (post of which ID is equal to *postId*).
        """

        data = self.get_body_as_dict(expectedFields=["path"])

        micropost = MicroPostManager.get_micropost(postId)
        contact = ContactManager.getTrustedContact(micropost.authorKey)
        user = UserManager.getUser()
        if micropost and data and contact:
            path = data["path"]
            client = ContactClient()
            body = {"date": date_util.get_db_date_from_date(micropost.date), "contactKey": user.key, "path": path}

            client.post(
                contact, "microposts/contacts/attach/", json_encode(body), callback=(yield gen.Callback("getattach"))
            )
            response = yield gen.Wait("getattach")

            if response.error:
                self.return_failure("An error occured while retrieving picture.")
            else:
                micropost.put_attachment(response.body, data["path"])
                self.return_success("Download succeeds.")

        else:
            if not data:
                self.return_failure("Wrong data.", 400)
            elif not contact:
                self.return_failure("Contact no more available.", 400)
            else:
                self.return_failure("Micropost not found.", 404)
예제 #6
0
    def get(self, postId):
        '''
        GET request returns post corresponding to the id given in the request
        URL.
        '''

        micropost = MicroPostManager.get_micropost(postId)
        self.return_one_document_or_404(micropost, "No post found")
예제 #7
0
파일: handlers.py 프로젝트: mpmedia/newebe
    def get(self, postId):
        '''
        GET request returns post corresponding to the id given in the request
        URL.
        '''

        micropost = MicroPostManager.get_micropost(postId)
        self.return_one_document_or_404(micropost, "No post found")
예제 #8
0
def and_this_micropost_has_timezone_date(step):
    world.date_micropost = world.microposts[-1]
    db_micropost = MicroPostManager.get_micropost(world.date_micropost["_id"])

    date = date_util.get_date_from_db_date(world.date_micropost["date"])

    assert db_micropost.date.replace(tzinfo=pytz.utc) == \
        date_util.convert_timezone_date_to_utc(date)
예제 #9
0
def and_this_micropost_has_timezone_date(step):
    world.date_micropost = world.microposts[-1]
    db_micropost = MicroPostManager.get_micropost(world.date_micropost["_id"])

    date = date_util.get_date_from_db_date(world.date_micropost["date"])

    assert db_micropost.date.replace(tzinfo=pytz.utc) == \
        date_util.convert_timezone_date_to_utc(date)
예제 #10
0
    def get(self, postId):
        '''
        Returns for given id the HTML representation of corresponding
        micropost.
        '''

        micropost = MicroPostManager.get_micropost(postId)
        if micropost:
            if micropost.content:
                micropost.content = markdown.markdown(micropost.content)

            self.render("templates/micropost.html", micropost=micropost)
        else:
            self.return_failure("Micropost not found.", 404)
예제 #11
0
파일: handlers.py 프로젝트: mpmedia/newebe
    def get(self, postId):
        '''
        Returns for given id the HTML representation of corresponding
        micropost.
        '''

        micropost = MicroPostManager.get_micropost(postId)
        if micropost:
            if micropost.content:
                micropost.content = markdown.markdown(micropost.content)

            self.render("templates/micropost.html", micropost=micropost)
        else:
            self.return_failure("Micropost not found.", 404)
예제 #12
0
    def get(self, postId, fileName):
        '''
        Return file which corresponds to *filename* and which is attached to
        micropost of which ID is equal to postId.
        '''

        micropost = MicroPostManager.get_micropost(postId)
        if micropost:
            try:
                fileContent = micropost.fetch_attachment(fileName)
                self.return_file(fileName, fileContent)
            except ResourceNotFound:
                self.return_failure("File not found", 404)
        else:
            self.return_failure("Micropost not found.", 404)
예제 #13
0
파일: handlers.py 프로젝트: mpmedia/newebe
    def get(self, postId, fileName):
        '''
        Return file which corresponds to *filename* and which is attached to
        micropost of which ID is equal to postId.
        '''

        micropost = MicroPostManager.get_micropost(postId)
        if micropost:
            try:
                fileContent = micropost.fetch_attachment(fileName)
                self.return_file(fileName, fileContent)
            except ResourceNotFound:
                self.return_failure("File not found", 404)
        else:
            self.return_failure("Micropost not found.", 404)
예제 #14
0
    def post(self, postId):
        '''
        Grab from contact the file corresponding to given path and given post
        (post of which ID is equal to *postId*).
        '''

        data = self.get_body_as_dict(expectedFields=["path"])

        micropost = MicroPostManager.get_micropost(postId)
        contact = ContactManager.getTrustedContact(micropost.authorKey)
        user = UserManager.getUser()
        if micropost and data and contact:
            path = data["path"]
            client = ContactClient()
            body = {
                "date": date_util.get_db_date_from_date(micropost.date),
                "contactKey": user.key,
                "path": path
            }

            client.post(contact,
                        "microposts/contacts/attach/",
                        json_encode(body),
                        callback=(yield gen.Callback("getattach")))
            response = yield gen.Wait("getattach")

            if response.error:
                self.return_failure(
                    "An error occured while retrieving picture.")
            else:
                micropost.put_attachment(response.body, data["path"])
                self.return_success("Download succeeds.")

        else:
            if not data:
                self.return_failure("Wrong data.", 400)
            elif not contact:
                self.return_failure("Contact no more available.", 400)
            else:
                self.return_failure("Micropost not found.", 404)
예제 #15
0
def when_i_retrieve_a_post_for_a_given_id(step):
    world.micropost_id = MicroPostManager.get_micropost(world.micropost._id)
예제 #16
0
def when_i_retrieve_a_post_for_a_given_id(step):
    world.micropost_id = MicroPostManager.get_micropost(world.micropost._id)