add Only Once Function refresh_thumbnail

Brightcells %!s(int64=9) %!d(string=hace) años
padre
commit
efaa518b96
Se han modificado 2 ficheros con 41 adiciones y 1 borrados
  1. 1 1
      group/admin.py
  2. 40 0
      group/views.py

+ 1 - 1
group/admin.py

@@ -16,7 +16,7 @@ class GroupUserInfoAdmin(admin.ModelAdmin):
16 16
 
17 17
 
18 18
 class GroupPhotoInfoAdmin(admin.ModelAdmin):
19
-    list_display = ('group_id', 'user_id', 'nickname', 'photo_path', 'photo_thumbnail_path', 'status', 'created_at', 'updated_at')
19
+    list_display = ('group_id', 'user_id', 'nickname', 'photo_path', 'photo_thumbnail_path', 'photo_thumbnail2_path', 'status', 'created_at', 'updated_at')
20 20
     list_filter = ('status', )
21 21
 
22 22
 

+ 40 - 0
group/views.py

@@ -968,3 +968,43 @@ class GroupUserInfoViewSet(viewsets.ModelViewSet):
968 968
 class GroupPhotoInfoViewSet(viewsets.ModelViewSet):
969 969
     queryset = GroupPhotoInfo.objects.all().order_by('-pk')
970 970
     serializer_class = GroupPhotoInfoSerializer
971
+
972
+
973
+# Only Once Function
974
+def refresh_thumbnail():
975
+    photos = GroupPhotoInfo.objects.filter(status=True)
976
+
977
+    for photo in photos:
978
+        try:
979
+            photo_path = photo.photo_path
980
+            photo_thumbnail_path = photo_path.replace('.', '_thumbnail.')
981
+            photo_thumbnail2_path = photo_path.replace('.', '_thumbnail2.')
982
+
983
+            # 群组照片缩略图生成
984
+            # 双列: 540, 40-50K
985
+            photo_w, photo_h, photo_thumbnail_w, photo_thumbnail_h = make_thumbnail(
986
+                os.path.join(settings.MEDIA_ROOT, photo_path).replace('\\', '/'),
987
+                os.path.join(settings.MEDIA_ROOT, photo_thumbnail_path).replace('\\', '/'),
988
+                settings.THUMBNAIL_MAX_WIDTH
989
+            )
990
+            # 单列: 1080, xx-100K
991
+            photo_w, photo_h, photo_thumbnail2_w, photo_thumbnail2_h = make_thumbnail(
992
+                os.path.join(settings.MEDIA_ROOT, photo_path).replace('\\', '/'),
993
+                os.path.join(settings.MEDIA_ROOT, photo_thumbnail2_path).replace('\\', '/'),
994
+                settings.THUMBNAIL_MAX_WIDTH2
995
+            )
996
+
997
+            photo.photo_w = photo_w
998
+            photo.photo_h = photo_h
999
+            photo.photo_thumbnail_path = photo_thumbnail_path
1000
+            photo.photo_thumbnail_w = photo_thumbnail_w
1001
+            photo.photo_thumbnail_h = photo_thumbnail_h
1002
+            photo.photo_thumbnail2_path = photo_thumbnail2_path
1003
+            photo.photo_thumbnail2_w = photo_thumbnail2_w
1004
+            photo.photo_thumbnail2_h = photo_thumbnail2_h
1005
+
1006
+            photo.save()
1007
+        except Exception as e:
1008
+            pass
1009
+
1010
+    return 'Refresh Thumbnail OK'