This method is more closer to the original and should be more robust even if you change the max number of avatars

This commit is contained in:
Mathieu Pillard 2010-01-22 15:12:54 +01:00 committed by Eric Florenzano
parent fe2fe0c1c3
commit 7a6c2e04a9

View file

@ -50,17 +50,20 @@ def _notification_updated(request, avatar):
def _get_avatars(user):
# Default set. Needs to be sliced, but that's it. Keep the natural order.
avatars = user.avatar_set.all()
avatars = user.avatar_set.all()
# Current avatar
avatar = avatars.filter(primary=True)[:1]
if avatar:
avatar = avatar[0]
primary_avatar = avatars.order_by('-primary')[:1]
if primary_avatar:
avatar = primary_avatar[0]
else:
avatar = None
# Slice the default set now that we used the queryset for the primary avatar
avatars = avatars[:AVATAR_MAX_AVATARS_PER_USER]
if AVATAR_MAX_AVATARS_PER_USER == 1:
avatars = primary_avatar
else:
# Slice the default set now that we used the queryset for the primary avatar
avatars = avatars[:AVATAR_MAX_AVATARS_PER_USER]
return (avatar, avatars)
def add(request, extra_context={}, next_override=None):