|
@@ -607,52 +607,68 @@ class DeviceManagement(View):
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
if icon or iconV2:
|
|
|
- app_device_type = AppDeviceType.objects.filter(id=app_device_type_id).first()
|
|
|
bucket_name = 'ansjerfilemanager'
|
|
|
s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
- icon_path = app_device_type.icon
|
|
|
- icon_v2_path = app_device_type.iconV2
|
|
|
+ icon_path = ""
|
|
|
+ icon_v2_path = ""
|
|
|
+
|
|
|
+ # 处理 icon
|
|
|
if icon:
|
|
|
- icon_path = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_{icon.name}'
|
|
|
file_key = f'app/device_type_images/{now_time}_{icon.name}'
|
|
|
+ icon_path = f'https://{bucket_name}.s3.amazonaws.com/{file_key}'
|
|
|
s3.upload_file_obj(
|
|
|
bucket_name,
|
|
|
file_key,
|
|
|
icon,
|
|
|
- {'ContentType': icon.content_type, 'ACL': 'public-read'})
|
|
|
+ {'ContentType': icon.content_type, 'ACL': 'public-read'}
|
|
|
+ )
|
|
|
+
|
|
|
+ # 处理 iconV2
|
|
|
if iconV2:
|
|
|
- icon_v2_path = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_v2_{iconV2.name}'
|
|
|
file_v2_key = f'app/device_type_images/{now_time}_v2_{iconV2.name}'
|
|
|
+ icon_v2_path = f'https://{bucket_name}.s3.amazonaws.com/{file_v2_key}'
|
|
|
s3.upload_file_obj(
|
|
|
bucket_name,
|
|
|
file_v2_key,
|
|
|
iconV2,
|
|
|
- {'ContentType': iconV2.content_type, 'ACL': 'public-read'})
|
|
|
+ {'ContentType': iconV2.content_type, 'ACL': 'public-read'}
|
|
|
+ )
|
|
|
+ # 更新数据库
|
|
|
+ update_fields = {
|
|
|
+ 'model': model,
|
|
|
+ 'type': type,
|
|
|
+ 'app_version_number_id': version_number,
|
|
|
+ }
|
|
|
if config:
|
|
|
try:
|
|
|
config = json.loads(config)
|
|
|
- except:
|
|
|
+ update_fields['config'] = config
|
|
|
+ except ValueError:
|
|
|
return response.json(444, 'config必须是一个json数据')
|
|
|
- AppDeviceType.objects.filter(id__in=list_app_device_type_id) \
|
|
|
- .update(model=model, type=type, icon=icon_path, iconV2=icon_v2_path,
|
|
|
- app_version_number_id=version_number,
|
|
|
- config=config)
|
|
|
- else:
|
|
|
- AppDeviceType.objects.filter(id__in=list_app_device_type_id) \
|
|
|
- .update(model=model, type=type, icon=icon_path, iconV2=icon_v2_path,
|
|
|
- app_version_number_id=version_number)
|
|
|
+
|
|
|
+ if icon_path:
|
|
|
+ update_fields['icon'] = icon_path
|
|
|
+
|
|
|
+ if icon_v2_path:
|
|
|
+ update_fields['iconV2'] = icon_v2_path
|
|
|
+
|
|
|
+ AppDeviceType.objects.filter(id__in=list_app_device_type_id).update(**update_fields)
|
|
|
+
|
|
|
else:
|
|
|
+ # 没有上传文件的情况,只更新配置或基本信息
|
|
|
+ update_fields = {
|
|
|
+ 'model': model,
|
|
|
+ 'type': type,
|
|
|
+ 'app_version_number_id': version_number,
|
|
|
+ }
|
|
|
if config:
|
|
|
try:
|
|
|
config = json.loads(config)
|
|
|
- except:
|
|
|
+ update_fields['config'] = config
|
|
|
+ except ValueError:
|
|
|
return response.json(444, 'config必须是一个json数据')
|
|
|
- AppDeviceType.objects.filter(id__in=list_app_device_type_id) \
|
|
|
- .update(model=model, type=type, app_version_number_id=version_number,
|
|
|
- config=config)
|
|
|
- else:
|
|
|
- AppDeviceType.objects.filter(id__in=list_app_device_type_id) \
|
|
|
- .update(model=model, type=type, app_version_number_id=version_number)
|
|
|
+
|
|
|
+ AppDeviceType.objects.filter(id__in=list_app_device_type_id).update(**update_fields)
|
|
|
DeviceNameLanguage.objects.filter(id__in=list_device_name_language_id).update(sort=sort)
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|