浏览代码

修改新增故事征集客户信息接口

locky 2 月之前
父节点
当前提交
671577b909
共有 1 个文件被更改,包括 32 次插入29 次删除
  1. 32 29
      AdminController/EvaluationActivityController.py

+ 32 - 29
AdminController/EvaluationActivityController.py

@@ -58,7 +58,7 @@ class EvaluationActivityView(View):
         elif operation == 'editActivityUser':
         elif operation == 'editActivityUser':
             return self.edit_activity_user(request_dict, response)
             return self.edit_activity_user(request_dict, response)
         elif operation == 'addStoryCollectionUser':     # 新增故事征集客户信息
         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:
         else:
             return response.json(404)
             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)))
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
 
     @staticmethod
     @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)
         activity_id = request_dict.get('activity_id', None)
         user_name = request_dict.get('user_name', None)
         user_name = request_dict.get('user_name', None)
         phone = request_dict.get('phone', None)
         phone = request_dict.get('phone', None)
@@ -336,38 +336,35 @@ class EvaluationActivityView(View):
         age = request_dict.get('age', None)
         age = request_dict.get('age', None)
         usage_environment = request_dict.get('usage_environment', None)
         usage_environment = request_dict.get('usage_environment', None)
         story = request_dict.get('story', 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]):
         if not all([activity_id, user_name, phone, address, sex, age, usage_environment, story]):
             return response.json(404)
             return response.json(404)
         now_time = int(time.time())
         now_time = int(time.time())
         try:
         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)
             user = ActivityUser.objects.filter(user_id=user_id, activity_id=activity_id)
             if user.exists():
             if user.exists():
@@ -379,6 +376,12 @@ class EvaluationActivityView(View):
                                             sex=sex, age=age, usage_environment=usage_environment, user_name=user_name,
                                             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,
                                             story=story, file_1_name=file_1_name, file_2_name=file_2_name,
                                             created_time=now_time, update_time=now_time)
                                             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:
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))