DetectController.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
  5. @AUTHOR: ASJRD018
  6. @NAME: AnsjerFormal
  7. @software: PyCharm
  8. @DATE: 2019/1/14 15:57
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: DetectController.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. import os
  15. import time
  16. import apns2
  17. import jpush as jpush
  18. import oss2
  19. from django.http import JsonResponse
  20. from django.views.generic.base import View
  21. from pyfcm import FCMNotification
  22. from AnsjerPush.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_PUSH_DOMAIN, JPUSH_CONFIG, \
  23. FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE
  24. from Model.models import Equipment_Info, UidSetModel, UidPushModel
  25. from Object.ETkObject import ETkObject
  26. from Object.RedisObject import RedisObject
  27. from Object.ResponseObject import ResponseObject
  28. from Object.UidTokenObject import UidTokenObject
  29. from Service.CommonService import CommonService
  30. # http://test.dvema.com/notify/push?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
  31. # http://test.dvema.com/notify/push?etk=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
  32. # 移动侦测接口
  33. class NotificationView(View):
  34. def get(self, request, *args, **kwargs):
  35. request.encoding = 'utf-8'
  36. # operation = kwargs.get('operation')
  37. return self.validation(request.GET)
  38. # def post(self, request, *args, **kwargs):
  39. # request.encoding = 'utf-8'
  40. # # operation = kwargs.get('operation')
  41. # return self.validation(request.POST)
  42. def validation(self, request_dict):
  43. response = ResponseObject()
  44. uidToken = request_dict.get('uidToken', None)
  45. etk = request_dict.get('etk', None)
  46. channel = request_dict.get('channel', '1')
  47. n_time = request_dict.get('n_time', None)
  48. event_type = request_dict.get('event_type', None)
  49. is_st = request_dict.get('is_st', None)
  50. if not all([channel, n_time]):
  51. return JsonResponse(status=200, data={
  52. 'code': 444,
  53. 'msg': 'param is wrong'})
  54. # return response.json(444)
  55. utko = UidTokenObject(uidToken)
  56. uid = utko.UID
  57. redisObj = RedisObject(db=6)
  58. # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
  59. pkey = '{uid}_ptl'.format(uid=uid)
  60. if redisObj.get_data(key=pkey):
  61. res_data = {'code': 0, 'msg': 'success,!'}
  62. return JsonResponse(status=200, data=res_data)
  63. else:
  64. # 设置推送间隔60秒一次
  65. redisObj.set_data(key=pkey, val=1, expire=60)
  66. uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
  67. # redisObj.set_data(key=pkey, val=list[0], expire=600)
  68. return response.json(0)
  69. if uid_set_qs.exists():
  70. uid_set_id = uid_set_qs[0].id
  71. nickname = uid_set_qs[0].nickname
  72. # if not is ==none
  73. if not nickname:
  74. nickname = uid
  75. uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
  76. values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName', 'lang',
  77. 'tz')
  78. if uid_push_qs.exists():
  79. auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  80. bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
  81. for up in uid_push_qs:
  82. push_type = up['push_type']
  83. # ios apns
  84. print(push_type)
  85. if push_type == 0:
  86. self.do_apns(request_dict, up, response, uid, channel, nickname)
  87. # android gcm
  88. elif push_type == 1:
  89. self.do_fcm(request_dict, up, response, uid, channel, nickname)
  90. # self.do_gmc(request_dict, up, response, uid, channel,nickname)
  91. # android jpush
  92. elif push_type == 2:
  93. self.do_jpush(request_dict, up, response, uid, channel, nickname)
  94. # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
  95. # 需求不一样,所以这么做的
  96. self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st, uid)
  97. if is_st == '0' or is_st == '2':
  98. return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
  99. elif is_st == '1':
  100. # Endpoint以杭州为例,其它Region请按实际情况填写。
  101. obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  102. # 设置此签名URL在60秒内有效。
  103. url = bucket.sign_url('PUT', obj, 7200)
  104. res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
  105. return JsonResponse(status=200, data=res_data)
  106. elif is_st == '3':
  107. # 人形检测带动图
  108. # Endpoint以杭州为例,其它Region请按实际情况填写。
  109. img_url_list = []
  110. for i in range(int(is_st)):
  111. obj = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  112. format(uid=uid, channel=channel, filename=n_time, st=i)
  113. # 设置此签名URL在60秒内有效。
  114. url = bucket.sign_url('PUT', obj, 7200)
  115. img_url_list.append(url)
  116. res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
  117. return JsonResponse(status=200, data=res_data)
  118. else:
  119. return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
  120. else:
  121. return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
  122. def validation(self, request_dict):
  123. response = ResponseObject()
  124. uidToken = request_dict.get('uidToken', None)
  125. channel = request_dict.get('channel', '1')
  126. n_time = request_dict.get('n_time', None)
  127. event_type = request_dict.get('event_type', None)
  128. is_st = request_dict.get('is_st', None)
  129. if not all([uidToken, channel, n_time]):
  130. return JsonResponse(status=200, data={
  131. 'code': 444,
  132. 'msg': 'param is wrong'})
  133. # return response.json(444)
  134. # 执行下面utko窗口会输出{'uid',""}
  135. utko = UidTokenObject(uidToken)
  136. uid = utko.UID
  137. redisObj = RedisObject(db=6)
  138. # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
  139. pkey = '{uid}_pptl'.format(uid=uid)
  140. # 判断redisObj.get_data(key=pkey):不为空
  141. if redisObj.get_data(key=pkey):
  142. res_data = {'code': 0, 'msg': 'success,!'}
  143. # 查询key对应的value
  144. res = redisObj.get_data(key=pkey)
  145. # redis中的字符串转回list
  146. redis_list = eval(res)
  147. else:
  148. # 从数据库查询出来
  149. uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
  150. values('token_val', 'app_type', 'appBundleId',
  151. 'push_type', 'userID_id', 'userID__NickName',
  152. 'lang', 'tz', 'uid_set__nickname')
  153. # 新建一个list接收数据
  154. uid_push_qs_list = []
  155. print("从数据库查到数据")
  156. # 把数据库数据追加进uid_push_qs_list
  157. for qs in uid_push_qs:
  158. uid_push_qs_list.append(qs)
  159. print(str(uid_push_qs_list))
  160. # 修改redis数据,并设置过期时间为10分钟
  161. redisObj.set_data(key=pkey, val=str(uid_push_qs_list), expire=600)
  162. # 查询key对应的value
  163. res = redisObj.get_data(key=pkey)
  164. # 把redis中的字符串转回list
  165. redis_list = eval(res)
  166. # return JsonResponse(status=200, data={'code': 0, 'msg': "Data has been saved in redis"})
  167. if redis_list:
  168. nickname = redis_list[0]['uid_set__nickname']
  169. if not nickname:
  170. nickname = uid
  171. auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  172. bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
  173. for up in redis_list:
  174. push_type = up['push_type']
  175. # ios apns
  176. print(push_type)
  177. if push_type == 0:
  178. self.do_apns(request_dict, up, response, uid, channel, nickname)
  179. # android gcm
  180. elif push_type == 1:
  181. self.do_fcm(request_dict, up, response, uid, channel, nickname)
  182. # self.do_gmc(request_dict, up, response, uid, channel,nickname)
  183. # android jpush
  184. elif push_type == 2:
  185. self.do_jpush(request_dict, up, response, uid, channel, nickname)
  186. # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
  187. # 需求不一样,所以这么做的
  188. self.do_bulk_create_info(redis_list, n_time, channel, event_type, is_st, uid)
  189. if is_st == '0' or is_st == '2':
  190. return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
  191. elif is_st == '1':
  192. # Endpoint以杭州为例,其它Region请按实际情况填写。
  193. obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  194. # 设置此签名URL在60秒内有效。
  195. url = bucket.sign_url('PUT', obj, 7200)
  196. res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
  197. return JsonResponse(status=200, data=res_data)
  198. elif is_st == '3':
  199. # 人形检测带动图
  200. # Endpoint以杭州为例,其它Region请按实际情况填写。
  201. img_url_list = []
  202. for i in range(int(is_st)):
  203. obj = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  204. format(uid=uid, channel=channel, filename=n_time, st=i)
  205. # 设置此签名URL在60秒内有效。
  206. url = bucket.sign_url('PUT', obj, 7200)
  207. img_url_list.append(url)
  208. res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
  209. return JsonResponse(status=200, data=res_data)
  210. else:
  211. return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
  212. def do_jpush(self, request_dict, uaql, response, uid, channel, nickname):
  213. event_type = request_dict.get('event_type', None)
  214. n_time = request_dict.get('n_time', None)
  215. appBundleId = uaql['appBundleId']
  216. token_val = uaql['token_val']
  217. lang = uaql['lang']
  218. tz = uaql['tz']
  219. response = ResponseObject()
  220. app_key = JPUSH_CONFIG[appBundleId]['Key']
  221. master_secret = JPUSH_CONFIG[appBundleId]['Secret']
  222. # 此处换成各自的app_key和master_secre
  223. _jpush = jpush.JPush(app_key, master_secret)
  224. push = _jpush.create_push()
  225. # if you set the logging level to "DEBUG",it will show the debug logging.
  226. _jpush.set_logging("DEBUG")
  227. # push.audience = jpush.all_
  228. push.audience = jpush.registration_id(token_val)
  229. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  230. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  231. message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
  232. send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz, event_type=event_type)
  233. android = jpush.android(alert=send_text, priority=1, style=1, alert_type=7,
  234. big_text=send_text, title=message_title,
  235. extras=push_data)
  236. push.notification = jpush.notification(android=android)
  237. push.platform = jpush.all_
  238. try:
  239. res = push.send()
  240. print(res)
  241. except Exception as e:
  242. print("Exception")
  243. print(repr(e))
  244. return response.json(10, repr(e))
  245. else:
  246. return response.json(0)
  247. def get_message_title(self, appBundleId, nickname):
  248. package_title_config = {
  249. 'com.ansjer.customizedd_a': 'DVS',
  250. 'com.ansjer.zccloud_a': 'ZosiSmart',
  251. 'com.ansjer.zccloud_ab': '周视',
  252. 'com.ansjer.adcloud_a': 'ADCloud',
  253. 'com.ansjer.adcloud_ab': 'ADCloud',
  254. 'com.ansjer.accloud_a': 'ACCloud',
  255. 'com.ansjer.loocamccloud_a': 'Loocam',
  256. 'com.ansjer.loocamdcloud_a': 'Anlapus',
  257. 'com.ansjer.customizedb_a': 'COCOONHD',
  258. 'com.ansjer.customizeda_a': 'Guardian365',
  259. 'com.ansjer.customizedc_a': 'PatrolSecure',
  260. }
  261. if appBundleId in package_title_config.keys():
  262. return package_title_config[appBundleId] + '(' + nickname + ')'
  263. else:
  264. return nickname
  265. def get_send_text(self, channel, n_time, lang, tz, event_type):
  266. n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
  267. msg_type = ''
  268. if int(event_type) == 704:
  269. msg_type = 'battery is too low'
  270. if lang == 'cn':
  271. msg_type = '电池电量过低'
  272. send_text = '{msg_type}channel:{channel} date:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  273. if lang == 'cn':
  274. send_text = '{msg_type}通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  275. return send_text
  276. def do_fcm(self, request_dict, uaql, response, uid, channel, nickname):
  277. n_time = request_dict.get('n_time')
  278. appBundleId = uaql['appBundleId']
  279. token_val = uaql['token_val']
  280. lang = uaql['lang']
  281. tz = uaql['tz']
  282. try:
  283. serverKey = FCM_CONFIG[appBundleId]
  284. except Exception as e:
  285. return response.json(404)
  286. event_type = request_dict.get('event_type', None)
  287. push_service = FCMNotification(api_key=serverKey)
  288. registration_id = token_val
  289. message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
  290. send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz, event_type=event_type)
  291. data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  292. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  293. result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title,
  294. message_body=send_text, data_message=data,
  295. extra_kwargs={
  296. 'default_vibrate_timings': True,
  297. 'default_sound': True,
  298. 'default_light_settings': True
  299. })
  300. response = ResponseObject()
  301. return response.json(0, result)
  302. def do_apns(self, request_dict, uaql, response, uid, channel, nickname):
  303. event_type = request_dict.get('event_type', None)
  304. token_val = uaql['token_val']
  305. lang = uaql['lang']
  306. n_time = request_dict.get('n_time')
  307. appBundleId = uaql['appBundleId']
  308. tz = uaql['tz']
  309. message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
  310. send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz, event_type=event_type)
  311. try:
  312. print('---')
  313. cli = apns2.APNSClient(mode=APNS_MODE,
  314. client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  315. # password=APNS_CONFIG[appBundleId]['password'])
  316. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  317. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  318. # body = json.dumps(push_data)
  319. alert = apns2.PayloadAlert(body=send_text, title=message_title)
  320. payload = apns2.Payload(alert=alert, custom=push_data)
  321. n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
  322. res = cli.push(n=n, device_token=token_val, topic=appBundleId)
  323. # assert res.status_code == 200, res.reason
  324. # assert res.apns_id
  325. print('========')
  326. print(res.status_code)
  327. if res.status_code == 200:
  328. return response.json(0)
  329. else:
  330. return response.json(404, res.reason)
  331. except Exception as e:
  332. print(repr(e))
  333. return response.json(10, repr(e))
  334. def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
  335. #
  336. qs_list = []
  337. nowTime = int(time.time())
  338. # 设备昵称
  339. userID_ids = []
  340. for dv in uaqs:
  341. userID_id = dv["userID_id"]
  342. if userID_id not in userID_ids:
  343. add_data = {
  344. 'userID_id': dv["userID_id"],
  345. 'eventTime': n_time,
  346. 'eventType': event_type,
  347. 'devUid': uid,
  348. 'devNickName': uid,
  349. 'Channel': channel,
  350. 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
  351. 'is_st': int(is_st),
  352. 'receiveTime': n_time,
  353. 'addTime': nowTime
  354. }
  355. qs_list.append(Equipment_Info(**add_data))
  356. userID_ids.append(userID_id)
  357. if qs_list:
  358. print(1)
  359. Equipment_Info.objects.bulk_create(qs_list)
  360. return True
  361. else:
  362. return False
  363. # http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
  364. # 移动侦测接口
  365. class PushNotificationView(View):
  366. def get(self, request, *args, **kwargs):
  367. request.encoding = 'utf-8'
  368. # operation = kwargs.get('operation')
  369. return self.validation(request.GET)
  370. def post(self, request, *args, **kwargs):
  371. request.encoding = 'utf-8'
  372. # operation = kwargs.get('operation')
  373. return self.validation(request.POST)
  374. def validation(self, request_dict):
  375. etk = request_dict.get('etk', None)
  376. channel = request_dict.get('channel', '1')
  377. n_time = request_dict.get('n_time', None)
  378. event_type = request_dict.get('event_type', None)
  379. is_st = request_dict.get('is_st', None)
  380. eto = ETkObject(etk)
  381. uid = eto.uid
  382. if len(uid) == 20:
  383. redisObj = RedisObject(db=6)
  384. # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
  385. pkey = '{uid}_ptl'.format(uid=uid)
  386. if redisObj.get_data(key=pkey):
  387. res_data = {'code': 0, 'msg': 'success,!'}
  388. return JsonResponse(status=200, data=res_data)
  389. else:
  390. redisObj.set_data(key=pkey, val=1, expire=60)
  391. uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
  392. values('token_val', 'app_type', 'appBundleId', 'push_type',
  393. 'userID_id', 'userID__NickName', 'lang', 'tz','uid_set__nickname')
  394. if uid_push_qs.exists():
  395. auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  396. bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
  397. self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st, uid)
  398. if is_st == '0' or is_st == '2':
  399. return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
  400. elif is_st == '1':
  401. # Endpoint以杭州为例,其它Region请按实际情况填写。
  402. obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  403. # 设置此签名URL在60秒内有效。
  404. url = bucket.sign_url('PUT', obj, 7200)
  405. res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
  406. return JsonResponse(status=200, data=res_data)
  407. elif is_st == '3':
  408. # 人形检测带动图
  409. img_url_list = []
  410. for i in range(int(is_st)):
  411. obj = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  412. format(uid=uid, channel=channel, filename=n_time, st=i)
  413. # 设置此签名URL在60秒内有效。
  414. url = bucket.sign_url('PUT', obj, 7200)
  415. img_url_list.append(url)
  416. res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
  417. return JsonResponse(status=200, data=res_data)
  418. else:
  419. return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
  420. else:
  421. return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong etk'})
  422. def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
  423. #
  424. qs_list = []
  425. nowTime = int(time.time())
  426. # 设备昵称
  427. userID_ids = []
  428. for dv in uaqs:
  429. userID_id = dv["userID_id"]
  430. if userID_id not in userID_ids:
  431. uid_nickname = dv['uid_set__nickname']
  432. if not uid_nickname:
  433. uid_nickname = uid
  434. add_data = {
  435. 'userID_id': dv["userID_id"],
  436. 'eventTime': n_time,
  437. 'eventType': event_type,
  438. 'devUid': uid,
  439. 'devNickName': uid_nickname,
  440. 'Channel': channel,
  441. 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
  442. 'is_st': int(is_st),
  443. 'receiveTime': n_time,
  444. 'addTime': nowTime
  445. }
  446. qs_list.append(Equipment_Info(**add_data))
  447. userID_ids.append(userID_id)
  448. if qs_list:
  449. print(1)
  450. Equipment_Info.objects.bulk_create(qs_list)
  451. return True
  452. else:
  453. return False