emencia / emencia-django-slideshows

A Django application to make slideshows
MIT License
5 stars 7 forks source link

Bug on random slide when the slideshow have 0 slides #2

Closed rage2000 closed 10 years ago

rage2000 commented 10 years ago

On slideshows/views.py

line: 57

    count = queryset.aggregate(count=Count('id'))['count']
    random_index = random.randint(0, count - 1)
    return queryset.all()[random_index]

if count == 0 we call randint with (0, -1), and raise ValueError: empty range for randrange() (0,0, 0)

If count == 0 we could return None:

    count = queryset.aggregate(count=Count('id'))['count']
    if count == 0:
        return None
    random_index = random.randint(0, count - 1)
    return queryset.all()[random_index]
sveetch commented 10 years ago

Ok thanks, this is done in commit 14c0e3f with 0.8.1.1 release on Pypi.

Note than i return an empty list instead of None value.