Browse Source

ota_完善文件删除功能

locky 4 years ago
parent
commit
d45a91c398
1 changed files with 9 additions and 11 deletions
  1. 9 11
      Controller/EquipmentOTA.py

+ 9 - 11
Controller/EquipmentOTA.py

@@ -64,22 +64,20 @@ class EquipmentOTA(View):
 
     def delete(self, request_dict, userID, response):
         eid = request_dict.get('eid', None)
-        if not eid:
-            return response.json(444, 'eid')
+        version = request_dict.get('version', None)
+        if not eid or not version:
+            return response.json(444, 'eid or version')
         own_perm = ModelService.check_perm(userID=userID, permID=230)
         if not own_perm:
             return response.json(404)
-        ev = Equipment_Version.objects.filter(eid=eid)
-        if not ev.exists():
+        equipment_version = Equipment_Version.objects.filter(eid=eid, version=version).values('filePath')
+        if not equipment_version.exists():
             return response.json(173)
         try:
-            has_ev = Equipment_Version.objects.filter(filePath=ev[0].filePath)
-            if has_ev.exists():
-                pass
-            else:
-                filepath = os.path.join(BASE_DIR, ev[0].filePath)
-                os.remove(filepath)
-            ev.delete()
+            # 删除文件和相应数据
+            file_path = equipment_version[0]['filePath']
+            os.remove(file_path)
+            equipment_version.delete()
         except Exception as e:
             return response.json(176, repr(e))
         else: