tanghongbin пре 5 година
родитељ
комит
82d060ce30
2 измењених фајлова са 93 додато и 1 уклоњено
  1. 5 1
      Ansjer/urls.py
  2. 88 0
      Controller/FAQController.py

+ 5 - 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
+    StatisticsController, FAQController
 
 urlpatterns = [
     url(r'^testApi/(?P<operation>.*)$', TestApi.testView.as_view()),
@@ -218,6 +218,10 @@ urlpatterns = [
     url(r'^v2/userbrand/(?P<operation>.*)$', UserBrandControllerV2.UserBrandV2.as_view()),
     url(r'^statistcs/appFrequencyMonth$', StatisticsController.statistcsAppFrequency),
     url(r'^statistcs/appFrequencyYear$', StatisticsController.statistcsAppFrequencyYear),
+
+    # 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