Esempio n. 1
0
    def post(self, user):
        data = request.form

        album_name = data.get("name")

        if not album_name:
            return jsonify(success=False), 400

        album = Album()
        album.title = album_name

        albumDate = data.get("albumDate")

        if albumDate:
            albumDate = datetime.strptime(albumDate, ISO_DATE_DEF)
            album.date = albumDate

        receptionAppropriate = inputs.boolean(data.get("receptionAppropriate"))
        if receptionAppropriate:
            album.receptionAppropriate = receptionAppropriate

        #data to add to the image
        photographer = data.get("photographer")
        needsCred = inputs.boolean(data.get("needsCred"))
        editingAllowed = inputs.boolean(data.get("editingAllowed"))

        photos = request.files.getlist("photos")
        if photos:
            for photo in photos:
                image = Image()
                image.url = upload_album_photo(photo, album.title)
                if photographer:
                    image.photographer = photographer
                if albumDate:
                    image.date = albumDate
                image.needsCred = needsCred
                image.editingAllowed = editingAllowed
                album.images.append(image)
                db.session.add(image)

        ## TODO: Details for each photo

        db.session.add(album)
        db.session.commit()
        return jsonify(success=True, id=album.albumId)