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)
    def put(self, id, user):
        album = Album.query.get_or_404(id)
        keys = request.form.keys()

        if "title" in keys:
            album.title = request.form["name"]
        if "receptionAppropriate" in keys:
            album.receptionAppropriate = request.form["receptionAppropriate"]

        ## TODO: Remove images from albums

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

        album.lastEdit = datetime.now()

        db.session.commit()
        return jsonify({"message": "ok"})
Exemple #3
0
 def get(self):
     return [Image('test', 1000)]
Exemple #4
0
 def post(self):
     return Image('test', 500)
Exemple #5
0
 def get(self, **kwargs):
     return Image('test', 1000)