Exemplo n.º 1
0
    def post(self):
        '''
        Extract picture and file linked to the picture from request, then
        creates a picture in database for the contact who sends it. An
        activity is created too.

        If author is not inside trusted contacts, the request is rejected.
        '''

        file = self.request.files['picture'][0]
        data = json_decode(self.get_argument("json"))

        if file and data:
            contact = ContactManager.getTrustedContact(
                    data.get("authorKey", ""))

            if contact:
                date = date_util.get_date_from_db_date(data.get("date", ""))

                picture = PictureManager.get_contact_picture(
                            contact.key, data.get("date", ""))

                if not picture:
                    picture = Picture(
                        _id=data.get("_id", ""),
                        title=data.get("title", ""),
                        path=data.get("path", ""),
                        contentType=data.get("contentType", ""),
                        authorKey=data.get("authorKey", ""),
                        author=data.get("author", ""),
                        tags=contact.tags,
                        date=date,
                        isMine=False,
                        isFile=False
                    )
                    picture.save()
                    picture.put_attachment(content=file["body"],
                                           name="th_" + picture._id)
                    picture.save()

                    self.create_creation_activity(contact,
                            picture, "publishes", "picture")

                logger.info("New picture from %s" % contact.name)
                self.return_success("Creation succeeds", 201)

            else:
                self.return_failure("Author is not trusted.", 400)
        else:
            self.return_failure("No data sent.", 405)
Exemplo n.º 2
0
def and_5_pictures_are_created_on_first_newebe(step, nbpics, tag):
    file = open("./apps/pictures/tests/test.jpg")
    for i in range(1, int(nbpics) + 1):
        picture = Picture(title="Pic 0%d" % i,
                          author=world.user.name,
                          authorKey=world.user.key,
                          date=datetime.datetime(2011, 11, i),
                          path="test.jpg",
                          contentType="image/jpeg",
                          isMine=True,
                          tags=[tag])
        picture.save()
        picture.put_attachment(file.read(), "th_test.jpg")
        picture.save()
Exemplo n.º 3
0
    def post(self):
        '''
        Extract picture and file linked to the picture from request, then
        creates a picture in database for the contact who sends it. An
        activity is created too.

        If author is not inside trusted contacts, the request is rejected.
        '''

        file = self.request.files['picture'][0]
        data = json_decode(self.get_argument("json"))

        if file and data:
            contact = ContactManager.getTrustedContact(
                data.get("authorKey", ""))

            if contact:
                date = date_util.get_date_from_db_date(data.get("date", ""))

                picture = PictureManager.get_contact_picture(
                    contact.key, data.get("date", ""))

                if not picture:
                    picture = Picture(_id=data.get("_id", ""),
                                      title=data.get("title", ""),
                                      path=data.get("path", ""),
                                      contentType=data.get("contentType", ""),
                                      authorKey=data.get("authorKey", ""),
                                      author=data.get("author", ""),
                                      tags=contact.tags,
                                      date=date,
                                      isMine=False,
                                      isFile=False)
                    picture.save()
                    picture.put_attachment(content=file["body"],
                                           name="th_" + picture._id)
                    picture.save()

                    self.create_creation_activity(contact, picture,
                                                  "publishes", "picture")

                logger.info("New picture from %s" % contact.name)
                self.return_success("Creation succeeds", 201)

            else:
                self.return_failure("Author is not trusted.", 400)
        else:
            self.return_failure("No data sent.", 405)
Exemplo n.º 4
0
def and_5_pictures_are_created_on_first_newebe(step, nbpics, tag):
    file = open("./apps/pictures/tests/test.jpg")
    for i in range(1, int(nbpics) + 1):
        picture = Picture(
            title = "Pic 0%d" % i,
            author =  world.user.name,
            authorKey = world.user.key,
            date = datetime.datetime(2011, 11, i),
            path = "test.jpg",
            contentType = "image/jpeg",
            isMine = True,
            tags = [tag]
        )
        picture.save()
        picture.put_attachment(file.read(), "th_test.jpg")
        picture.save()
Exemplo n.º 5
0
def add_three_pictures_to_the_database_with_different_dates(step):
    size = 200, 200
    image = Image.open("newebe/apps/pictures/tests/test.jpg")
    image.thumbnail(size, Image.ANTIALIAS)
    image.save("newebe/apps/pictures/tests/th_test.jpg")
    file = open("newebe/apps/pictures/tests/th_test.jpg")

    for i in range(1, 4):
        picture = Picture(
            title="Pic 0%d" % i,
            author=world.browser.user.name,
            authorKey=world.browser.user.key,
            date=datetime.datetime(2011, 11, i),
            path="test.jpg",
            isMine=i != 3
        )
        picture.save()
        picture.put_attachment(file.read(), "th_test.jpg")
Exemplo n.º 6
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.º 7
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.º 8
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.º 9
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)