add and return photo_thumbnail2 relative

Brightcells 9 年之前
父节点
当前提交
d64b3c216b
共有 6 个文件被更改,包括 84 次插入11 次删除
  1. 29 0
      group/migrations/0018_auto_20160417_2246.py
  2. 16 0
      group/models.py
  3. 21 7
      group/views.py
  4. 2 1
      pai2/settings.py
  5. 12 0
      photo/views.py
  6. 4 3
      utils/sql/raw.py

+ 29 - 0
group/migrations/0018_auto_20160417_2246.py

@@ -0,0 +1,29 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.db import models, migrations
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('group', '0017_groupphotoinfo_photo_from'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='groupphotoinfo',
16
+            name='photo_thumbnail2_h',
17
+            field=models.IntegerField(default=0, help_text='\u7167\u7247\u7f29\u7565\u56fe\u9ad8\u5ea6', verbose_name='photo_thumbnail2_h'),
18
+        ),
19
+        migrations.AddField(
20
+            model_name='groupphotoinfo',
21
+            name='photo_thumbnail2_path',
22
+            field=models.CharField(help_text='\u7167\u7247\u7f29\u7565\u56fe\u5b58\u653e\u8def\u5f84', max_length=255, null=True, verbose_name='photo_thumbnail2_path', blank=True),
23
+        ),
24
+        migrations.AddField(
25
+            model_name='groupphotoinfo',
26
+            name='photo_thumbnail2_w',
27
+            field=models.IntegerField(default=0, help_text='\u7167\u7247\u7f29\u7565\u56fe\u5bbd\u5ea6', verbose_name='photo_thumbnail2_w'),
28
+        ),
29
+    ]

+ 16 - 0
group/models.py

@@ -140,12 +140,21 @@ class GroupPhotoInfo(CreateUpdateMixin):
140 140
     user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
141 141
     nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户群组昵称')
142 142
     avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
143
+
143 144
     photo_path = models.CharField(_(u'photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径')
144 145
     photo_w = models.IntegerField(_(u'photo_w'), default=0, help_text=u'照片宽度')
145 146
     photo_h = models.IntegerField(_(u'photo_h'), default=0, help_text=u'照片高度')
147
+
148
+    # 双列: 540, 40-50K
146 149
     photo_thumbnail_path = models.CharField(_(u'photo_thumbnail_path'), max_length=255, blank=True, null=True, help_text=u'照片缩略图存放路径')
147 150
     photo_thumbnail_w = models.IntegerField(_(u'photo_thumbnail_w'), default=0, help_text=u'照片缩略图宽度')
148 151
     photo_thumbnail_h = models.IntegerField(_(u'photo_thumbnail_h'), default=0, help_text=u'照片缩略图高度')
152
+
153
+    # 单列: 1080, xx-100K
154
+    photo_thumbnail2_path = models.CharField(_(u'photo_thumbnail2_path'), max_length=255, blank=True, null=True, help_text=u'照片缩略图存放路径')
155
+    photo_thumbnail2_w = models.IntegerField(_(u'photo_thumbnail2_w'), default=0, help_text=u'照片缩略图宽度')
156
+    photo_thumbnail2_h = models.IntegerField(_(u'photo_thumbnail2_h'), default=0, help_text=u'照片缩略图高度')
157
+
149 158
     comment_num = models.IntegerField(_(u'comment_num'), default=0, help_text=u'照片评论数量')
150 159
     thumbup_num = models.IntegerField(_(u'thumbup_num'), default=0, help_text=u'照片点赞数量')
151 160
     photo_from = models.IntegerField(_(u'photo_from'), choices=PHOTO_FROM, default=APP_GROUP, help_text=u'照片来源')
@@ -165,6 +174,10 @@ class GroupPhotoInfo(CreateUpdateMixin):
165 174
     def photo_thumbnail_url(self):
166 175
         return img_url(self.photo_thumbnail_path)
167 176
 
177
+    @property
178
+    def photo_thumbnail2_url(self):
179
+        return img_url(self.photo_thumbnail2_path)
180
+
168 181
     def photo_info(self, user_id):
169 182
         try:
170 183
             group = GroupInfo.objects.get(group_id=self.group_id)
@@ -183,6 +196,9 @@ class GroupPhotoInfo(CreateUpdateMixin):
183 196
             'photo_thumbnail_url': self.photo_thumbnail_url,
184 197
             'photo_thumbnail_w': self.photo_thumbnail_w,
185 198
             'photo_thumbnail_h': self.photo_thumbnail_h,
199
+            'photo_thumbnail2_url': self.photo_thumbnail2_url,
200
+            'photo_thumbnail2_w': self.photo_thumbnail2_w,
201
+            'photo_thumbnail2_h': self.photo_thumbnail2_h,
186 202
             'user_id': self.user_id,
187 203
             'nickname': self.nickname,
188 204
             'avatar': self.avatar,

+ 21 - 7
group/views.py

@@ -552,6 +552,7 @@ def flyimg_upload_api(request):
552 552
     if photo:
553 553
         photo_path = 'fly/{uuid}{extension}'.format(uuid=shortuuid.uuid(), extension=os.path.splitext(photo.name)[1])
554 554
         photo_thumbnail_path = photo_path.replace('.', '_thumbnail.')
555
+        photo_thumbnail2_path = photo_path.replace('.', '_thumbnail2.')
555 556
 
556 557
         if default_storage.exists(photo_path):
557 558
             default_storage.delete(photo_path)
@@ -562,11 +563,18 @@ def flyimg_upload_api(request):
562 563
         # default_storage.save(photo_thumbnail_path, photo)
563 564
 
564 565
         # 群组照片缩略图生成
566
+        # 双列: 540, 40-50K
565 567
         photo_w, photo_h, photo_thumbnail_w, photo_thumbnail_h = make_thumbnail(
566 568
             os.path.join(settings.MEDIA_ROOT, photo_path).replace('\\', '/'),
567 569
             os.path.join(settings.MEDIA_ROOT, photo_thumbnail_path).replace('\\', '/'),
568 570
             settings.THUMBNAIL_MAX_WIDTH
569 571
         )
572
+        # 单列: 1080, xx-100K
573
+        photo_w, photo_h, photo_thumbnail2_w, photo_thumbnail2_h = make_thumbnail(
574
+            os.path.join(settings.MEDIA_ROOT, photo_path).replace('\\', '/'),
575
+            os.path.join(settings.MEDIA_ROOT, photo_thumbnail_path).replace('\\', '/'),
576
+            settings.THUMBNAIL_MAX_WIDTH2
577
+        )
570 578
 
571 579
         # 群组照片记录创建
572 580
         group_photo = GroupPhotoInfo.objects.create(
@@ -580,6 +588,9 @@ def flyimg_upload_api(request):
580 588
             photo_thumbnail_path=photo_thumbnail_path,
581 589
             photo_thumbnail_w=photo_thumbnail_w,
582 590
             photo_thumbnail_h=photo_thumbnail_h,
591
+            photo_thumbnail2_path=photo_thumbnail2_path,
592
+            photo_thumbnail2_w=photo_thumbnail2_w,
593
+            photo_thumbnail2_h=photo_thumbnail2_h,
583 594
         )
584 595
 
585 596
         # 设置群组最后一张照片PK
@@ -879,13 +890,16 @@ def pai2_home_api(request):
879 890
         'photo_thumbnail_url': img_url(row[9]),
880 891
         'photo_thumbnail_w': row[10],
881 892
         'photo_thumbnail_h': row[11],
882
-        'user_id': row[12],
883
-        'nickname': row[13],
884
-        'avatar': row[14],
885
-        'comment_num': row[15],
886
-        'thumbup_num': row[16],
887
-        'photo_from': row[17],
888
-        'created_at': row[18],
893
+        'photo_thumbnail2_url': img_url(row[12]),
894
+        'photo_thumbnail2_w': row[13],
895
+        'photo_thumbnail2_h': row[14],
896
+        'user_id': row[15],
897
+        'nickname': row[16],
898
+        'avatar': row[17],
899
+        'comment_num': row[18],
900
+        'thumbup_num': row[19],
901
+        'photo_from': row[20],
902
+        'created_at': row[21],
889 903
     } for row in rows]
890 904
 
891 905
     [row.update({'thumbup': get_group_photo_thumbup_flag(row['photo_id'], user_id)}) for row in rows]

+ 2 - 1
pai2/settings.py

@@ -234,7 +234,8 @@ CURTAIL_UUID_LENGTH = 7
234 234
 WATERMARK_LOGO = os.path.join(PROJ_DIR, 'static/pai2/img/paiai_96_96.png').replace('\\', '/')
235 235
 
236 236
 # 缩略图设置
237
-THUMBNAIL_MAX_WIDTH = 360
237
+THUMBNAIL_MAX_WIDTH = 540
238
+THUMBNAIL_MAX_WIDTH2 = 1080
238 239
 
239 240
 # 首页设置
240 241
 PAI2_HOME_PER_PAGE = 20  # 首页照片每页数量

+ 12 - 0
photo/views.py

@@ -199,14 +199,23 @@ def session_join_api(request):
199 199
         for photo in photos:
200 200
             photo_path = photo.p_photo_path
201 201
             photo_thumbnail_path = photo_path.replace('.', '_thumbnail.')
202
+            photo_thumbnail_path = photo_path.replace('.', '_thumbnail2.')
202 203
 
203 204
             # 群组照片缩略图生成
205
+            # 双列: 540, 40-50K
204 206
             photo_w, photo_h, photo_thumbnail_w, photo_thumbnail_h = make_thumbnail(
205 207
                 os.path.join(settings.MEDIA_ROOT, photo_path).replace('\\', '/'),
206 208
                 os.path.join(settings.MEDIA_ROOT, photo_thumbnail_path).replace('\\', '/'),
207 209
                 settings.THUMBNAIL_MAX_WIDTH
208 210
             )
209 211
 
212
+            # 单列: 1080, xx-100K
213
+            photo_w, photo_h, photo_thumbnail2_w, photo_thumbnail2_h = make_thumbnail(
214
+                os.path.join(settings.MEDIA_ROOT, photo_path).replace('\\', '/'),
215
+                os.path.join(settings.MEDIA_ROOT, photo_thumbnail_path).replace('\\', '/'),
216
+                settings.THUMBNAIL_MAX_WIDTH2
217
+            )
218
+
210 219
             # 群组照片记录创建
211 220
             group_photo = GroupPhotoInfo.objects.create(
212 221
                 group_id=group_id,
@@ -219,6 +228,9 @@ def session_join_api(request):
219 228
                 photo_thumbnail_path=photo_thumbnail_path,
220 229
                 photo_thumbnail_w=photo_thumbnail_w,
221 230
                 photo_thumbnail_h=photo_thumbnail_h,
231
+                photo_thumbnail2_path=photo_thumbnail2_path,
232
+                photo_thumbnail2_w=photo_thumbnail2_w,
233
+                photo_thumbnail2_h=photo_thumbnail2_h,
222 234
                 photo_from=GroupPhotoInfo.SESSION_GROUP,
223 235
             )
224 236
 

+ 4 - 3
utils/sql/raw.py

@@ -2,9 +2,10 @@
2 2
 
3 3
 PAI2_HOME_API = (
4 4
     r"select "
5
-    r"T1.group_id, T2.group_name, T2.group_default_avatar, T2.group_avatar, T2.group_from, T3.id, T3.photo_path, T3.photo_w, "
6
-    r"T3.photo_h, T3.photo_thumbnail_path, T3.photo_thumbnail_w, T3.photo_thumbnail_h, T3.user_id, T3.nickname, "
7
-    r"T3.avatar, T3.comment_num, T3.thumbup_num, T3.photo_from, T3.created_at "
5
+    r"T1.group_id, T2.group_name, T2.group_default_avatar, T2.group_avatar, T2.group_from, T3.id, T3.photo_path, "
6
+    r"T3.photo_w, T3.photo_h, T3.photo_thumbnail_path, T3.photo_thumbnail_w, T3.photo_thumbnail_h, "
7
+    r"T3.photo_thumbnail2_path, T3.photo_thumbnail2_w, T3.photo_thumbnail2_h, T3.user_id, T3.nickname, T3.avatar, "
8
+    r"T3.comment_num, T3.thumbup_num, T3.photo_from, T3.created_at "
8 9
     r"from (select * from group_groupuserinfo where user_id='{user_id}' and user_status=1) as T1 "
9 10
     r"left outer join group_groupinfo as T2 on T1.group_id = T2.group_id "
10 11
     r"left outer join group_groupphotoinfo as T3 on T1.group_id = T3.group_id and T3.id > T1.current_id "