Ejemplo n.º 1
0
def edit_album(album_id=None):
    """
    Displays a form to either add or edit a photo album. If the album is
    created from scratch or updates an existing depends on the presence of the
    ``album_id`` parameter.
    """

    album = None
    if album_id is not None:
        album = PhotoAlbums.by_id(album_id)
        if album is None:
            raise NotFound("Photo album not found.")

    if request.method == "POST":
        form = PhotoAlbumForm(request.form, obj=album)
        if form.validate():
            form.save(album)

            if album is None:
                flash("New album created.")
            else:
                flash("Album saved.")
            return redirect(url_for("photos.index"))
    else:
        form = PhotoAlbumForm(obj=album)

    return render_template('admin/photos.html',
        form=form,
        album_id=album_id)
Ejemplo n.º 2
0
    def test_empty_next(self):
        """Tests what happens with a next on the last element."""

        with _request_context('/'):
            album = PhotoAlbums.by_id(1)
            next_list = list(album.next_photos('2765703092'))

            assert len(next_list) == 0
Ejemplo n.º 3
0
    def test_prev_truncated(self):
        """Tests the prev method with truncated result set."""

        with _request_context('/'):
            album = PhotoAlbums.by_id(1)
            prev_list = list(album.previous_photos('2764854905', 4))

            assert len(prev_list) == 1
            assert prev_list[0].id == '2765702228'
Ejemplo n.º 4
0
    def test_next(self):
        """Tests the next methods."""

        with _request_context('/'):
            album = PhotoAlbums.by_id(1)
            next_list = list(album.next_photos('2765702228', 5))

            assert len(next_list) == 5
            assert next_list[0].id == '2764854905'
            assert next_list[4].id == '2765704378'
Ejemplo n.º 5
0
    def test_prev(self):
        """Tests the prev method."""

        with _request_context('/'):
            album = PhotoAlbums.by_id(1)
            prev_list = list(album.previous_photos('2765703256', 4))

            assert len(prev_list) == 4
            assert prev_list[0].id == '2764854737'
            assert prev_list[3].id == '2765704162'
Ejemplo n.º 6
0
    def test_next_truncated(self):
        """Test next if above the upper limit."""

        with _request_context('/'):
            album = PhotoAlbums.by_id(1)
            next_list = list(album.next_photos('2765703772', 4))

            assert len(next_list) == 2
            assert next_list[0].id == '2765702000'
            assert next_list[1].id == '2765703092'
Ejemplo n.º 7
0
    def test_access_photo_not_in_album(self):
        """Access a photo that is not in an album."""

        with _request_context('/'):
            album = PhotoAlbums.by_id(1)
            prev_photo = album.previous_photo('2771608178')