hovel / imagestore

Django gallery solution.
BSD 3-Clause "New" or "Revised" License
164 stars 71 forks source link

Exclude empty albums from album list (for non-owner) #57

Open sandino opened 9 years ago

sandino commented 9 years ago

Sometimes users create albums but do not upload images (sometimes they do it later). Though empty albums are not displayed to non-owner, they are still included in queryset in AlbumListView. Thus, e.g., if IMAGESTORE_ALBUMS_ON_PAGE = 12 and one of albums has no images (and therefore no head) and non-owner opens imagestore:index page, there will be only 11 albums on page.

By this reason some precisely built pages are displayed not very neat way. I suggest excluding such albums from queryset (to insert before return albums):

    if self.request.user.is_authenticated():
        albums = albums.exclude(Q(head__isnull=True), ~Q(user=self.request.user))
    else:
        albums = albums.exclude(head__isnull=True)