Esempio n. 1
0
    def post(self):
        args = self.parser.parse_args()
        portrait_name, portrait = args['portrait_filename'], args['portrait']

        author = Author(args['name'])
        if portrait_name and portrait:
            author.portrait = decode_image(name=secure_filename(portrait_name),
                                           data64=portrait,
                                           max_length=255)
        author.save()
        return marshal(author, self.fields, envelope='author_list'), 200
Esempio n. 2
0
    def post(self):
        args = self.parser.parse_args()
        cover_image_name, cover_image = args.get(
            'cover_image_filename'), args['cover_image']

        book = Book(args['name'], args["authors"])

        if cover_image_name and cover_image:
            book.cover_image = decode_image(
                name=secure_filename(cover_image_name),
                data64=cover_image,
                max_length=255)
        book.save()

        return marshal(book, self.fields, envelope='book'), 200
Esempio n. 3
0
def add_user(data):
    name = data.get('name')
    mail = data.get('mail')
    photo = data.get('photo')
    birth_date = datetime.strptime(data.get('birth_date'), "%Y-%m-%dT%H:%M:%S.%fZ")
    password = data.get('password')
    bio = data.get('bio')
    telephone = data.get('telephone')
    instagram = data.get('instagram')

    image_path = decode_image(photo)
    if image_path is not None:
        photo_url = upload_image_gcp(image_path)
    else:
        photo_url = photo

    new_user = User(name, mail, photo_url, birth_date, password, bio, telephone, instagram)
    db.session.add(new_user)
    db.session.commit()
Esempio n. 4
0
    def put(self, id):
        self.get_object(id)

        args = self.parser.parse_args()
        portrait_name, portrait = args['portrait_filename'], args['portrait']

        author = self.object
        author.name = args['name']

        prev_portrait = author.portrait

        if portrait_name and portrait:
            author.portrait = decode_image(name=secure_filename(portrait_name),
                                           data64=portrait,
                                           max_length=255)
        author.save()

        if portrait_name and portrait and prev_portrait:
            os.remove(prev_portrait)
        return marshal(author, self.fields, envelope='author'), 200
Esempio n. 5
0
    def put(self, id):
        self.get_object(id)

        args = self.parser.parse_args()
        cover_image_name, cover_image = args.get(
            'cover_image_filename'), args['cover_image']

        book = self.object
        book.name = args['name']
        book.update_authors(args['authors'])
        prev_cover = book.cover_image

        if cover_image_name and cover_image:
            book.cover_image = decode_image(
                name=secure_filename(cover_image_name),
                data64=cover_image,
                max_length=255)
        book.save()

        if cover_image_name and cover_image and prev_cover:
            os.remove(prev_cover)

        return marshal(book, self.fields, envelope='book'), 200