Return session_id grouped photos in group_join_api & Return session_id in photo detail

Brightcells 8 年之前
父節點
當前提交
347e920d39
共有 4 個文件被更改,包括 40 次插入29 次删除
  1. 1 0
      group/models.py
  2. 6 22
      group/views.py
  3. 7 7
      requirements.txt
  4. 26 0
      utils/group_photo_utils.py

+ 1 - 0
group/models.py

@@ -227,6 +227,7 @@ class GroupPhotoInfo(CreateUpdateMixin):
227 227
             'thumbup': get_group_photo_thumbup_flag(self.pk, user_id),
228 228
             'thumbup_num': self.thumbup_num,
229 229
             'photo_from': self.photo_from,
230
+            'session_id': self.session_id,
230 231
             'porder': porder,
231 232
             'created_at': self.created_at.replace(microsecond=0),
232 233
             'origin_expired_stamps': origin_expired_stamps(self.lensman_photo_id, self.user_id)

+ 6 - 22
group/views.py

@@ -6,7 +6,6 @@ import itertools
6 6
 import os
7 7
 import random
8 8
 
9
-import records
10 9
 import shortuuid
11 10
 from curtail_uuid import CurtailUUID
12 11
 from django.conf import settings
@@ -23,6 +22,7 @@ from group.serializers import GroupInfoSerializer, GroupPhotoInfoSerializer, Gro
23 22
 from message.models import UserMessageInfo
24 23
 from utils.error.errno_utils import GroupPhotoStatusCode, GroupStatusCode, GroupUserStatusCode, UserStatusCode
25 24
 from utils.error.response_utils import response
25
+from utils.group_photo_utils import get_current_photos
26 26
 from utils.page_utils import pagination
27 27
 from utils.redis.rgroup import (del_group_photo_thumbup_flag, get_group_info, get_group_photo_comment_list,
28 28
                                 get_group_photo_data, get_group_photo_thumbup_flag, get_group_photo_thumbup_list,
@@ -243,9 +243,11 @@ def group_join_api(request):
243 243
     r.srem(GROUP_USERS_QUIT_SET % group_id, user_id)
244 244
     r.sadd(GROUP_USERS_PASSED_SET % group_id, user_id)
245 245
 
246
+    curinfo = get_current_photos(group_id, user_id, group_user.current_id)
247
+
246 248
     return response(200, 'Apply Success', u'申请成功', {
247
-        'current_id': group_user.current_id,
248
-        'photos': [],
249
+        'current_id': curinfo.get('current_id', ''),
250
+        'photos': curinfo.get('photos', ''),
249 251
         'group_id': group_id,
250 252
         'group': get_group_info(group_id),
251 253
         'user_id': user_id,
@@ -580,25 +582,7 @@ def flyimg_upload_api(request):
580 582
         # 设置群组最后一张照片PK
581 583
         r.set(GROUP_LAST_PHOTO_PK % group_id, group_photo.pk)
582 584
 
583
-    # 获取从 current_id 到 now 的群组照片列表
584
-    group_photos = GroupPhotoInfo.objects.filter(
585
-        group_id=group_id,
586
-        status=True,
587
-        pk__gt=max(current_id, group_user.current_id),
588
-    ).order_by(
589
-        '-session_id',
590
-        '-pk'
591
-    )
592
-    # 最新照片
593
-    latest_photo = group_photos.first()
594
-    # 照片按照 session_id 分组
595
-    group_photos = map(lambda x: {'session_id': x[0], 'photos': [y.photo_info(user_id) for y in x[1]]},
596
-                       itertools.groupby(group_photos, lambda x: x.session_id))
597
-
598
-    return response(200, 'Flyimg Upload Success', u'飞图上传成功', {
599
-        'current_id': latest_photo and latest_photo.pk or current_id,
600
-        'photos': group_photos,
601
-    })
585
+    return response(200, 'Flyimg Upload Success', u'飞图上传成功', get_current_photos(group_id, user_id, max(current_id, group_user.current_id)))
602 586
 
603 587
 
604 588
 @logit

+ 7 - 7
requirements.txt

@@ -1,24 +1,24 @@
1 1
 CodeConvert==2.0.4
2 2
 Django==1.8.4
3 3
 MySQL-python==1.2.5
4
-Pillow==3.2.0
4
+Pillow==3.4.2
5 5
 TimeConvert==1.3.9
6 6
 cryptography==1.5.2
7 7
 django-curtail-uuid==1.0.0
8
-django-detect==1.0.4
8
+django-detect==1.0.5
9 9
 django-json-response==1.1.3
10 10
 django-logit==1.0.6
11 11
 django-multidomain==1.1.4
12
-django-rlog==1.0.6
12
+django-rlog==1.0.7
13 13
 django-shortuuidfield==0.1.3
14
-djangorestframework==3.3.1
15
-furl==0.4.95
14
+djangorestframework==3.5.3
15
+furl==0.5.6
16 16
 hiredis==0.2.0
17
-ipdb==0.8.1
17
+ipdb==0.10.1
18 18
 ipython==5.1.0
19 19
 jsonfield==1.0.3
20 20
 isoweek==1.3.1
21
-kkconst==1.1.2
21
+kkconst==1.1.3
22 22
 mock==2.0.0
23 23
 pep8==1.7.0
24 24
 records==0.4.3

+ 26 - 0
utils/group_photo_utils.py

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