Esempio n. 1
0
    def post(self, image_id):
        """ POST /image/id/tags
            Creates a new tag and links it to the given image.
        """
        form = forms.TagForm()
        form.csrf_enabled = False

        if form.validate_on_submit():
            image = models.Image.query.get(image_id)
            if not image:
                raise ItemNotFoundError

            tag = models.Tag.query.filter_by(name=form.name.data).first()
            if tag:
                if image not in tag.images:
                    tag.images.append(image)
                else:
                    return {'error': 'connection already exists.'}  # TODO: better flow.
            else:
                tag = models.Tag(name=form.name.data, image=image)

            models.db.session.add(tag)
            models.db.session.commit()

            return {'id': tag.id}  # TODO: return message
        else:
            return form_errors_to_dict(form)
Esempio n. 2
0
    def post(self):
        """ POST /albums
            Create a new albums.
        """
        form = forms.AlbumForm()
        form.csrf_enabled = False

        if form.validate_on_submit():
            album = models.Album(name=form.name.data)
            models.db.session.add(album)
            models.db.session.commit()

            return {'slug': album.slug}
        else:
            return form_errors_to_dict(form)
Esempio n. 3
0
    def put(self, album_id):
        """ PUT /album/id
            Update the album with the given id.
        """
        form = forms.AlbumForm()
        form.csrf_enabled = False

        if form.validate_on_submit():
            album = models.Album.query.get(album_id)
            if not album:
                raise ItemNotFoundError

            # Update the album model in the database
            album.name = form.name.data
            models.db.session.add(album)

            # Commit the update to the database
            models.db.session.commit()

            return {'slug': album.slug}
        else:
            return form_errors_to_dict(form)