Browse Source

新增批量删除语言参数

chenshibin 4 years ago
parent
commit
921df6cc4d
1 changed files with 22 additions and 15 deletions
  1. 22 15
      Controller/VoicePromptController.py

+ 22 - 15
Controller/VoicePromptController.py

@@ -139,24 +139,31 @@ class VoicePromptView(View):
 
     def do_delete(self, userID, request_dict, response):
         id = request_dict.get('id', None)
+        ids = request_dict.get('ids', None)
         if id:
             voice_qs = VoicePromptModel.objects.filter(id=id)
-            if voice_qs.exists():
-                uid = voice_qs[0].uid
-                device_qs = Device_Info.objects.filter(UID=uid, userID=userID)
-                if device_qs.exists():
-                    channel = voice_qs[0].channel
-                    filename = voice_qs[0].filename
-                    voice_qs.delete()
-                    auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-                    bucket = oss2.Bucket(auth, 'http://oss-cn-shenzhen.aliyuncs.com', 'ansjer-static-resources')
-                    obj = 'voice_prompt/{uid}/{channel}/'.format(uid=uid, channel=channel) + filename
-                    bucket.delete_object(obj)
-                    return response.json(0)
-                else:
-                    return response.json(404)
+        elif ids:
+            voice_qs = VoicePromptModel.objects.filter(id__in=ids.split(','))
+
+
+        if not voice_qs.exists():
+            return response.json(14)
+
+        for voice in voice_qs:
+            uid = voice.uid
+            device_qs = Device_Info.objects.filter(UID=uid, userID=userID)
+            if device_qs.exists():
+                channel = voice.channel
+                filename = voice.filename
+                voice_qs.delete()
+                auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
+                bucket = oss2.Bucket(auth, 'http://oss-cn-shenzhen.aliyuncs.com', 'ansjer-static-resources')
+                obj = 'voice_prompt/{uid}/{channel}/'.format(uid=uid, channel=channel) + filename
+                bucket.delete_object(obj)
+                return response.json(0)
             else:
-                return response.json(173)
+                return response.json(404)
+
         else:
             return response.json(444)