Exemplo n.º 1
0
    def post(self):
        '''
        Creates a picture and corresponding activity. Then picture is
        propagated to all trusted contacts.

        Errors are stored inside activity.
        '''

        filebody = self.request.body
        filename = self.get_argument("qqfile")
        try:
            tag = self.get_argument("tag")
        except:
            tag = "all"
        filetype = mimetypes.guess_type(filename)[0] or \
                'application/octet-stream'

        if filebody:

            picture = Picture(
                title="New Picture",
                path=filename,
                contentType=filetype,
                authorKey=UserManager.getUser().key,
                author=UserManager.getUser().name,
                isMine=True,
                isFile=True,
                tags=[tag]
            )
            picture.save()

            picture.put_attachment(content=filebody, name=filename)
            thumbnail = self.get_thumbnail(filebody, filename, (200, 200))
            thbuffer = thumbnail.read()
            picture.put_attachment(thbuffer, "th_" + filename)
            thpath = os.path.join(CONFIG.main.path, "th_" + filename)

            os.remove(thpath)
            preview = self.get_thumbnail(filebody, filename, (1000, 1000))
            picture.put_attachment(preview.read(), "prev_" + filename)
            os.remove(thpath)
            picture.save()

            self.create_owner_creation_activity(
                    picture, "publishes", "picture")

            self.send_files_to_contacts("pictures/contact/",
                        fields={"json": str(picture.toJson(localized=False))},
                        files=[("picture", str(picture.path), thbuffer)],
                        tag=tag)

            logger.info("Picture %s successfuly posted." % filename)
            self.return_json(picture.toJson(), 201)

        else:
            self.return_failure("No picture posted.", 400)
Exemplo n.º 2
0
    def post(self):
        '''
        Creates a picture and corresponding activity. Then picture is
        propagated to all trusted contacts.

        Errors are stored inside activity.
        '''

        filebody = self.request.body
        filename = self.get_argument("qqfile")
        try:
            tag = self.get_argument("tag")
        except:
            tag = "all"
        filetype = mimetypes.guess_type(filename)[0] or \
                'application/octet-stream'

        if filebody:

            picture = Picture(title="New Picture",
                              path=filename,
                              contentType=filetype,
                              authorKey=UserManager.getUser().key,
                              author=UserManager.getUser().name,
                              isMine=True,
                              isFile=True,
                              tags=[tag])
            picture.save()

            picture.put_attachment(content=filebody, name=filename)
            thumbnail = self.get_thumbnail(filebody, filename, (200, 200))
            thbuffer = thumbnail.read()
            picture.put_attachment(thbuffer, "th_" + filename)
            thpath = os.path.join(CONFIG.main.path, "th_" + filename)

            os.remove(thpath)
            preview = self.get_thumbnail(filebody, filename, (1000, 1000))
            picture.put_attachment(preview.read(), "prev_" + filename)
            os.remove(thpath)
            picture.save()

            self.create_owner_creation_activity(picture, "publishes",
                                                "picture")

            self.send_files_to_contacts(
                "pictures/contact/",
                fields={"json": str(picture.toJson(localized=False))},
                files=[("picture", str(picture.path), thbuffer)],
                tag=tag)

            logger.info("Picture %s successfuly posted." % filename)
            self.return_json(picture.toJson(), 201)

        else:
            self.return_failure("No picture posted.", 400)
Exemplo n.º 3
0
    def post(self):
        """
        Creates a picture and corresponding activity. Then picture is
        propagated to all trusted contacts.

        Errors are stored inside activity.
        """

        file = self.request.files["picture"][0]

        if file:
            filebody = file["body"]

            picture = Picture(
                title="New Picture",
                contentType=file["content_type"],
                authorKey=UserManager.getUser().key,
                author=UserManager.getUser().name,
                isFile=True,
            )
            picture.save()

            filename = "%s.jpg" % picture._id
            picture.path = filename
            picture.put_attachment(filebody, filename)
            thumbnail = self.get_thumbnail(filebody, filename, (200, 200))
            thbuffer = thumbnail.read()
            picture.put_attachment(thbuffer, "th_" + filename)
            thpath = os.path.join(CONFIG.main.path, "th_" + filename)
            os.remove(thpath)
            preview = self.get_thumbnail(filebody, filename, (1000, 1000))
            picture.put_attachment(preview.read(), "prev_" + filename)
            os.remove(thpath)
            picture.save()

            self.create_owner_creation_activity(picture, "publishes", "picture")

            self.send_files_to_contacts(
                "pictures/contact/",
                fields={"json": str(picture.toJson(localized=False))},
                files=[("picture", str(picture.path), thbuffer)],
            )

            logger.info("Picture %s successfuly posted." % filename)
            self.return_json(picture.toJson(), 201)

        else:
            self.return_failure("No picture posted.", 400)
Exemplo n.º 4
0
    def post(self):
        '''
        Creates a picture and corresponding activity. Then picture is
        propagated to all trusted contacts.

        Errors are stored inside activity.
        '''

        file = self.request.files['picture'][0]

        if file:
            filebody = file["body"]

            picture = Picture(title="New Picture",
                              contentType=file["content_type"],
                              authorKey=UserManager.getUser().key,
                              author=UserManager.getUser().name,
                              isFile=True)
            picture.save()

            filename = '%s.jpg' % picture._id
            picture.path = filename
            picture.put_attachment(filebody, filename)
            thumbnail = self.get_thumbnail(filebody, filename, (200, 200))
            thbuffer = thumbnail.read()
            picture.put_attachment(thbuffer, "th_" + filename)
            thpath = os.path.join(CONFIG.main.path, "th_" + filename)
            os.remove(thpath)
            preview = self.get_thumbnail(filebody, filename, (1000, 1000))
            picture.put_attachment(preview.read(), "prev_" + filename)
            os.remove(thpath)
            picture.save()

            self.create_owner_creation_activity(picture, "publishes",
                                                "picture")

            self.send_files_to_contacts(
                "pictures/contact/",
                fields={"json": str(picture.toJson(localized=False))},
                files=[("picture", str(picture.path), thbuffer)])

            logger.info("Picture %s successfuly posted." % filename)
            self.return_json(picture.toJson(), 201)

        else:
            self.return_failure("No picture posted.", 400)