|
@@ -105,32 +105,33 @@ class perfectUserInfoView(TemplateView):
|
|
userID = tko.userID
|
|
userID = tko.userID
|
|
if not userID:
|
|
if not userID:
|
|
return response.json(309)
|
|
return response.json(309)
|
|
- if userIcon != None:
|
|
|
|
- location = 'static/User/Images/' + userID + '/'
|
|
|
|
- fss = FileSystemStorage(location=location)
|
|
|
|
- if fss.exists(userIcon.name):
|
|
|
|
- fss.delete(userIcon.name)
|
|
|
|
- filename = fss.save(userIcon.name, userIcon)
|
|
|
|
- # userIconUrl = fss.url(filename)
|
|
|
|
- userIconPath = fss.path(filename).replace('\\', '/')
|
|
|
|
- else:
|
|
|
|
- userIconPath = None
|
|
|
|
- if userContent != None:
|
|
|
|
|
|
+ userIconPath = ''
|
|
|
|
+ if userIcon:
|
|
|
|
+ # 上传头像到aws s3
|
|
|
|
+ aws_s3_client = boto3.client(
|
|
|
|
+ 's3',
|
|
|
|
+ region_name=REGION_NAME,
|
|
|
|
+ aws_access_key_id=ACCESS_KEY_ID,
|
|
|
|
+ aws_secret_access_key=SECRET_ACCESS_KEY,
|
|
|
|
+ config=botocore.client.Config(signature_version='s3v4'),
|
|
|
|
+ )
|
|
|
|
+ Key = userID + '/' + userIcon.name
|
|
|
|
+ aws_s3_client.put_object(Bucket=AVATAR_BUCKET, Key=Key, Body=userIcon)
|
|
|
|
+ userIconPath = userID + '/' + userIcon.name
|
|
|
|
+ if userContent:
|
|
dataValid = json.loads(userContent)
|
|
dataValid = json.loads(userContent)
|
|
if 'userID' and 'password' and 'is_superuser' in dataValid.keys():
|
|
if 'userID' and 'password' and 'is_superuser' in dataValid.keys():
|
|
return response.json(444)
|
|
return response.json(444)
|
|
- if userIconPath == None and userContent == None:
|
|
|
|
|
|
+ if not userIconPath and not userContent:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
- elif userIconPath == None and userContent != None:
|
|
|
|
|
|
+ elif not userIconPath and userContent:
|
|
return self.perfectUserInfoUpdate(userID, response, userContent=userContent)
|
|
return self.perfectUserInfoUpdate(userID, response, userContent=userContent)
|
|
- elif userIconPath != None and userContent == None:
|
|
|
|
|
|
+ elif userIconPath and not userContent:
|
|
return self.perfectUserInfoUpdate(userID, response, userIconPath=userIconPath)
|
|
return self.perfectUserInfoUpdate(userID, response, userIconPath=userIconPath)
|
|
else:
|
|
else:
|
|
- return self.perfectUserInfoUpdate(userID, response, userIconPath=userIconPath,
|
|
|
|
- userContent=userContent)
|
|
|
|
|
|
+ return self.perfectUserInfoUpdate(userID, response, userIconPath=userIconPath, userContent=userContent)
|
|
|
|
|
|
- def perfectUserInfoUpdate(slef, userID, response, *args,
|
|
|
|
- **kwargs):
|
|
|
|
|
|
+ def perfectUserInfoUpdate(slef, userID, response, **kwargs):
|
|
"""
|
|
"""
|
|
:param username:
|
|
:param username:
|
|
:param userContent:
|
|
:param userContent:
|
|
@@ -143,24 +144,21 @@ class perfectUserInfoView(TemplateView):
|
|
return response.json(104)
|
|
return response.json(104)
|
|
userIconPath = kwargs.get('userIconPath', None)
|
|
userIconPath = kwargs.get('userIconPath', None)
|
|
userContent = kwargs.get('userContent', None)
|
|
userContent = kwargs.get('userContent', None)
|
|
- if userIconPath is not None:
|
|
|
|
- userIconPath = userIconPath[userIconPath.find('static/'):]
|
|
|
|
- userIconUrl = SERVER_DOMAIN + 'account/getAvatar/' + userIconPath[7:]
|
|
|
|
- if userContent != None:
|
|
|
|
|
|
+ if userIconPath:
|
|
|
|
+ userIconUrl = SERVER_DOMAIN + 'account/getAvatar/' + userIconPath
|
|
|
|
+ if userContent:
|
|
try:
|
|
try:
|
|
UserData = json.loads(userContent)
|
|
UserData = json.loads(userContent)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(444, repr(e))
|
|
return response.json(444, repr(e))
|
|
try:
|
|
try:
|
|
- if userIconPath is not None and userContent is not None:
|
|
|
|
|
|
+ if userIconPath and userContent:
|
|
User.update(userIconPath=userIconPath, userIconUrl=userIconUrl, **UserData)
|
|
User.update(userIconPath=userIconPath, userIconUrl=userIconUrl, **UserData)
|
|
- elif userIconPath is None and userContent is not None:
|
|
|
|
|
|
+ elif not userIconPath and userContent:
|
|
User.update(**UserData)
|
|
User.update(**UserData)
|
|
- elif userIconPath is not None and userContent is None:
|
|
|
|
|
|
+ elif userIconPath and not userContent:
|
|
User.update(userIconPath=userIconPath, userIconUrl=userIconUrl)
|
|
User.update(userIconPath=userIconPath, userIconUrl=userIconUrl)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- errorInfo = traceback.format_exc()
|
|
|
|
- print('修改设备信息错误: %s ' % errorInfo)
|
|
|
|
return response.json(117, repr(e))
|
|
return response.json(117, repr(e))
|
|
else:
|
|
else:
|
|
res = CommonService.qs_to_dict(User)
|
|
res = CommonService.qs_to_dict(User)
|
|
@@ -168,10 +166,7 @@ class perfectUserInfoView(TemplateView):
|
|
res['datas'][k]['fields'].pop('password')
|
|
res['datas'][k]['fields'].pop('password')
|
|
userIconPath = res['datas'][k]['fields']['userIconPath']
|
|
userIconPath = res['datas'][k]['fields']['userIconPath']
|
|
if userIconPath:
|
|
if userIconPath:
|
|
- if userIconPath.find('static/') != -1:
|
|
|
|
- userIconPath = userIconPath.replace('static/', '').replace('\\', '/')
|
|
|
|
- userIconUrl = SERVER_DOMAIN + 'account/getAvatar/' + userIconPath
|
|
|
|
- res['datas'][k]['fields']['userIconUrl'] = userIconUrl
|
|
|
|
|
|
+ res['datas'][k]['fields']['userIconUrl'] = userIconUrl
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
|
|
|
|
|
|
|
|
@@ -200,10 +195,10 @@ class getAvatarView(TemplateView):
|
|
try:
|
|
try:
|
|
aws_s3_client = boto3.client(
|
|
aws_s3_client = boto3.client(
|
|
's3',
|
|
's3',
|
|
|
|
+ region_name=REGION_NAME,
|
|
aws_access_key_id=ACCESS_KEY_ID,
|
|
aws_access_key_id=ACCESS_KEY_ID,
|
|
aws_secret_access_key=SECRET_ACCESS_KEY,
|
|
aws_secret_access_key=SECRET_ACCESS_KEY,
|
|
config=botocore.client.Config(signature_version='s3v4'),
|
|
config=botocore.client.Config(signature_version='s3v4'),
|
|
- region_name=REGION_NAME,
|
|
|
|
)
|
|
)
|
|
get_object_response = aws_s3_client.get_object(Bucket=AVATAR_BUCKET, Key='default/default.png')
|
|
get_object_response = aws_s3_client.get_object(Bucket=AVATAR_BUCKET, Key='default/default.png')
|
|
return HttpResponse(get_object_response['Body'], content_type="image/jpeg")
|
|
return HttpResponse(get_object_response['Body'], content_type="image/jpeg")
|