Explorar o código

新增地图图片

Your Name %!s(int64=5) %!d(string=hai) anos
pai
achega
6160cadccb
Modificáronse 1 ficheiros con 22 adicións e 1 borrados
  1. 22 1
      apps/Equipment/views.py

+ 22 - 1
apps/Equipment/views.py

@@ -3016,7 +3016,28 @@ class SetMap_View(ListView):
         return render(request, 'backstageNet/systemSet/mapManage.html', context={"nums": nums,"page":page,"uname":uname})
 
     def post(self, request):
-        pass
+        map_photo = request.FILES.get('upicture')
+        if map_photo:
+            print("地图图片:", map_photo)
+            map_photo_dir = 'map_photo/'
+            end_name = map_photo.name.split('.')[-1]
+            # 判断如果路径不存在,即创建路径
+            if os.path.exists(map_photo_dir) == False:
+                os.makedirs(map_photo_dir)
+            img = Image.open(map_photo)
+            # img = img.convert('RGB')
+            now_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
+            pic_name = now_time + '.' + end_name
+            print("pic_name:", pic_name)
+            img.save(map_photo_dir + pic_name)
+            news_photo = map_photo_dir + pic_name
+            print("new_photo:",news_photo)
+            data = {"code": 0,"msg": "","data": {"src": news_photo}}
+        else:
+            new_photo = "0"
+            data = {"code": 404,"msg": "","data": {"src": news_photo}}
+        data = json.dumps(data)
+        return HttpResponse(data)
 
 
 class Person_List(ListView):