Explorar o código

Merge remote-tracking branch 'remotes/origin/Bin' into dev

# Conflicts:
#	Ansjer/urls.py
tanghongbin %!s(int64=5) %!d(string=hai) anos
pai
achega
5c3c5e1d18
Modificáronse 2 ficheiros con 92 adicións e 1 borrados
  1. 4 1
      Ansjer/urls.py
  2. 88 0
      Controller/FAQController.py

+ 4 - 1
Ansjer/urls.py

@@ -10,7 +10,7 @@ from Controller import FeedBack, EquipmentOTA, EquipmentInfo, AdminManage, AppIn
     StsOssController, UIDPreview, OssCrd, SysMsg, UidUser, EquipmentManagerV2, EquipmentManagerV3, PushDeploy, \
     AppSetController, \
     ApplicationController, UserExController, CloudStorage, TestApi, UserBrandControllerV2, \
-    StatisticsController, Alexa
+    StatisticsController, Alexa, FAQController
 
 urlpatterns = [
     url(r'^testApi/(?P<operation>.*)$', TestApi.testView.as_view()),
@@ -222,6 +222,9 @@ urlpatterns = [
     #统计alexa连接数
     url(r'^alexa/(?P<operation>.*)$', Alexa.AlexaConnectNum.as_view()),
 
+    # FAQ
+    url(r'^faq/upload', FAQController.FAQUploadView.as_view()),
+
     # app 设备消息模板
     # 路由加参数参考
     # url(r'^(?P<path>.*)/(?P<UID>.*)/lls$', Test.Test.as_view(), name=u'gg'),

+ 88 - 0
Controller/FAQController.py

@@ -0,0 +1,88 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+import os
+import traceback
+
+from django.utils.decorators import method_decorator
+from django.views.decorators.csrf import csrf_exempt
+from django.views.generic.base import View
+
+from Ansjer.config import BASE_DIR
+from Object.ResponseObject import ResponseObject
+from Object.TokenObject import TokenObject
+
+
+class FAQUploadView(View):
+    @method_decorator(csrf_exempt)
+    def dispatch(self, request, *args, **kwargs):
+        return super(FAQUploadView, self).dispatch(request, *args, **kwargs)
+
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        request_dict = request.GET
+        fileName = request.FILES.get('fileName', None)
+        return self.validate(fileName, request_dict)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        request_dict = request.POST
+        fileName = request.FILES.get('fileName', None)
+        return self.validate(fileName, request_dict)
+
+    def validate(self, fileName, request_dict):
+        token = TokenObject(request_dict.get('token', None))
+
+        response = ResponseObject()
+        if token.code != 0:
+            return response.json(token.code)
+
+        try:
+            path = '/'.join((BASE_DIR, 'static/FAQImages')).replace('\\', '/') + '/'
+            if not os.path.exists(path):
+                os.makedirs(path)
+                file_name = path + str(fileName)
+                if os.path.exists(file_name):
+                    os.remove(file_name)
+                destination = open(file_name, 'wb+')
+                for chunk in fileName.chunks():
+                    destination.write(chunk)
+                destination.close()
+            else:
+                file_name = path + str(fileName)
+                if os.path.exists(file_name):
+                    os.remove(file_name)
+
+                destination = open(file_name, 'wb+')
+                for chunk in fileName.chunks():
+                    destination.write(chunk)
+                destination.close()
+        except Exception as e:
+            errorInfo = traceback.format_exc()
+            print('上传文件错误: %s' % errorInfo)
+            return response.json(700, {'details': repr(e)})
+        else:
+            index = file_name.find('static/')
+            filePath = file_name[index:]
+            return response.json(0, {'filePath': filePath})
+
+
+class FAQView(View):
+
+    @method_decorator(csrf_exempt)
+    def dispatch(self, *args, **kwargs):
+        return super(FAQView, self).dispatch(*args, **kwargs)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        request_dict = request.POST
+        operation = kwargs.get('operation', None)
+        return self.validate(request_dict, operation)
+
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        request_dict = request.GET
+        operation = kwargs.get('operation', None)
+        return self.validate(request_dict, operation)
+
+    def validate(self, request_dict, operation):
+        return