|
@@ -58,7 +58,7 @@ class EvaluationActivityView(View):
|
|
|
elif operation == 'editActivityUser':
|
|
|
return self.edit_activity_user(request_dict, response)
|
|
|
elif operation == 'addStoryCollectionUser': # 新增故事征集客户信息
|
|
|
- return self.add_story_collection_user(user_id, request, request_dict, response)
|
|
|
+ return self.add_story_collection_user(user_id, request_dict, response)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
@@ -327,7 +327,7 @@ class EvaluationActivityView(View):
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
|
- def add_story_collection_user(user_id, request, request_dict, response):
|
|
|
+ def add_story_collection_user(user_id, request_dict, response):
|
|
|
activity_id = request_dict.get('activity_id', None)
|
|
|
user_name = request_dict.get('user_name', None)
|
|
|
phone = request_dict.get('phone', None)
|
|
@@ -336,38 +336,35 @@ class EvaluationActivityView(View):
|
|
|
age = request_dict.get('age', None)
|
|
|
usage_environment = request_dict.get('usage_environment', None)
|
|
|
story = request_dict.get('story', None)
|
|
|
- file_1 = request.FILES.get('file_1', None)
|
|
|
- file_2 = request.FILES.get('file_2', None)
|
|
|
+ file_1_name = request_dict.get('file_1_name', '')
|
|
|
+ file_2_name = request_dict.get('file_2_name', '')
|
|
|
|
|
|
if not all([activity_id, user_name, phone, address, sex, age, usage_environment, story]):
|
|
|
return response.json(404)
|
|
|
now_time = int(time.time())
|
|
|
try:
|
|
|
- file_1_name, file_2_name = '', ''
|
|
|
- if file_2:
|
|
|
- file_2_name = str(file_2)
|
|
|
- # 上传文件到华为云OBS
|
|
|
- obs_client = ObsClient(
|
|
|
- access_key_id=HUAWEICLOUD_AK,
|
|
|
- secret_access_key=HUAWEICLOUD_SK,
|
|
|
- server=HUAWEICLOUD_OBS_SERVER
|
|
|
- )
|
|
|
- if file_1:
|
|
|
- file_1_name = 'story-collection/{}/{}'.format(user_id, str(file_1))
|
|
|
- resp = obs_client.putObject(
|
|
|
- bucketName=HUAWEICLOUD_SERVER_BUKET,
|
|
|
- objectKey=file_1_name,
|
|
|
- content=file_1
|
|
|
+ signed_url = []
|
|
|
+ # 如果上传文件,生成华为云OBS上传链接
|
|
|
+ if any([file_1_name, file_2_name]):
|
|
|
+ obs_client = ObsClient(
|
|
|
+ access_key_id=HUAWEICLOUD_AK,
|
|
|
+ secret_access_key=HUAWEICLOUD_SK,
|
|
|
+ server=HUAWEICLOUD_OBS_SERVER
|
|
|
)
|
|
|
- assert resp.status < 300
|
|
|
- if file_2:
|
|
|
- file_2_name = '{}/story-collection/{}'.format(user_id, str(file_2))
|
|
|
- resp = obs_client.putObject(
|
|
|
- bucketName=HUAWEICLOUD_SERVER_BUKET,
|
|
|
- objectKey=file_2_name,
|
|
|
- content=file_2
|
|
|
- )
|
|
|
- assert resp.status < 300
|
|
|
+ key = 'story-collection/{}/'.format(user_id)
|
|
|
+ if file_1_name:
|
|
|
+ file_1_name = key + file_1_name
|
|
|
+ res = obs_client.createSignedUrl(
|
|
|
+ method='PUT', bucketName=HUAWEICLOUD_SERVER_BUKET, objectKey=file_1_name, expires=3600
|
|
|
+ )
|
|
|
+ signed_url.append(res.signedUrl)
|
|
|
+
|
|
|
+ if file_2_name:
|
|
|
+ file_2_name = key + file_2_name
|
|
|
+ res = obs_client.createSignedUrl(
|
|
|
+ method='PUT', bucketName=HUAWEICLOUD_SERVER_BUKET, objectKey=file_1_name, expires=3600
|
|
|
+ )
|
|
|
+ signed_url.append(res.signedUrl)
|
|
|
|
|
|
user = ActivityUser.objects.filter(user_id=user_id, activity_id=activity_id)
|
|
|
if user.exists():
|
|
@@ -379,6 +376,12 @@ class EvaluationActivityView(View):
|
|
|
sex=sex, age=age, usage_environment=usage_environment, user_name=user_name,
|
|
|
story=story, file_1_name=file_1_name, file_2_name=file_2_name,
|
|
|
created_time=now_time, update_time=now_time)
|
|
|
- return response.json(0)
|
|
|
+ if signed_url:
|
|
|
+ res = {
|
|
|
+ 'signed_url': signed_url
|
|
|
+ }
|
|
|
+ return response.json(0, res)
|
|
|
+ else:
|
|
|
+ return response.json(0)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|