暂无描述

group_photo_utils.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. import itertools
  3. from group.models import GroupPhotoInfo
  4. def get_current_photos(group_id, user_id, current_id, request=None):
  5. # 获取从 current_id 到 now 的群组照片列表
  6. group_photos = GroupPhotoInfo.objects.filter(
  7. group_id=group_id,
  8. status=True,
  9. pk__gt=current_id,
  10. )
  11. # 最新照片
  12. group_tmp_photos = group_photos.order_by(
  13. '-pk',
  14. )
  15. latest_photo = group_tmp_photos.first()
  16. # 照片按照 session_id 分组
  17. # TODO: How to order by session_id and session_id's created time
  18. # group_photos = group_photos.order_by(
  19. # '-session_id',
  20. # '-pk',
  21. # )
  22. group_photos = group_photos.order_by(
  23. '-pk',
  24. )
  25. if request and request.weixin:
  26. group_photos = group_photos[:30]
  27. group_photos = map(lambda x: {'session_id': x[0], 'photos': [y.photo_info(user_id) for y in x[1]]},
  28. itertools.groupby(group_photos, lambda x: x.session_id))
  29. return {
  30. 'current_id': latest_photo and latest_photo.pk or current_id,
  31. 'photos': group_photos,
  32. }