Example #1
0
    def test_find_all_images_in_an_album(self):
        session = Client().session()
        album = Album(name="my pix")
        session.add(album)
        session.flush()
        session.add(Image(album_id=album.album_id, filename="deadbeef"))
        session.add(Image(album_id=album.album_id, filename="badcafe"))
        session.add(Image(album_id=None, filename="cafebabe"))

        images = Album.images_for_album_id(album.album_id)
        eq_(["deadbeef", "badcafe"], map(lambda x: x.filename, images))
Example #2
0
    def test_find_all_images_in_an_album(self):
        session = Client().session()
        album = Album(name='my pix')
        session.add(album)
        session.flush()
        session.add(Image(album_id = album.album_id, filename='deadbeef'))
        session.add(Image(album_id = album.album_id, filename='badcafe'))
        session.add(Image(album_id = None, filename='cafebabe'))

        images = Album.images_for_album_id(album.album_id)
        eq_(['deadbeef', 'badcafe'],
                map(lambda x: x.filename, images))
Example #3
0
def view_album(request_format, album_id):
    album = Client().session().query(Album).\
            filter(Album.album_id == album_id).\
            one()
    images = Album.images_for_album_id(album_id)
    def struct_from_image(image):
        return {
            'url': url_for('show_image', image_id=image.image_id),
            'filename': image.filename,
            'caption': image.caption(),
        }
    image_structs = map(struct_from_image, images)

    if request_format == 'html':
        return render_template('view_album.html.jinja',
                images = image_structs,
                album=album)
    else:
        return images
Example #4
0
    def test_images_for_album_id_sorts_by_photographed_then_added_date(self):
        session = Client().session()
        album = Album(name="my pix")
        session.add(album)
        session.flush()

        han = Image(photographed_at="2012-05-13 03:00:00", album_id=album.album_id, filename="han")
        han.created_at = "2014-11-22 13:15:00"
        greedo = Image(photographed_at="2014-12-28 15:24:00", album_id=album.album_id, filename="greedo")
        greedo.created_at = "2014-08-01 08:00:00"
        artoo = Image(photographed_at=None, album_id=album.album_id, filename="R2D2")
        artoo.created_at = "1977-05-13 01:00:00"
        session.add(han)
        session.add(greedo)
        session.add(artoo)
        session.flush()

        # Sorting should be done by the date the image was shot, or the date
        # it was added if it has no photographed_at. Han shot first, so he
        # should show up before Greedo. Artoo never shot at all, so use his
        # created_at (which refers to the *record*, not the image) instead.
        images = Album.images_for_album_id(album.album_id)
        eq_(["R2D2", "han", "greedo"], map(lambda x: x.filename, images))