|
@@ -24,7 +24,9 @@ from django.contrib import auth
|
|
|
import time,json
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
# http://192.168.136.39:8000/login/oauth/authorize
|
|
|
-class ApplicationView(View):
|
|
|
+
|
|
|
+# http://192.168.136.39:8000/application/query
|
|
|
+class AuthView(View):
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
operation = kwargs.get('operation', None)
|
|
@@ -39,7 +41,7 @@ class ApplicationView(View):
|
|
|
response = ResponseObject()
|
|
|
token = request_dict.get('token', None)
|
|
|
tko = TokenObject(token)
|
|
|
- if tko.code != 0:
|
|
|
+ if tko.code == 0:
|
|
|
userID = tko.userID
|
|
|
if operation == 'authorize':
|
|
|
return self.do_authorize(request_dict, userID, response)
|
|
@@ -116,4 +118,98 @@ class ApplicationView(View):
|
|
|
"updated_at": "2008-01-14T04:33:35Z"
|
|
|
}
|
|
|
print(res_json)
|
|
|
- return JsonResponse(res_json)
|
|
|
+ return JsonResponse(res_json)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class ApplicationView(View):
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation', None)
|
|
|
+ return self.validation(request.GET, operation)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation', None)
|
|
|
+ return self.validation(request.POST, operation)
|
|
|
+
|
|
|
+ def validation(self, request_dict, operation):
|
|
|
+ response = ResponseObject()
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ if tko.code == 0:
|
|
|
+ userID = tko.userID
|
|
|
+ if operation == 'query':
|
|
|
+ return self.query(request_dict, userID, response)
|
|
|
+ elif operation == 'add':
|
|
|
+ return self.add(request_dict, userID, response)
|
|
|
+ elif operation == 'update':
|
|
|
+ return self.update(request_dict, userID, response)
|
|
|
+ elif operation == 'delete':
|
|
|
+ return self.delete(request_dict, userID, response)
|
|
|
+ else:
|
|
|
+ return response.json(414)
|
|
|
+
|
|
|
+ def query(self, request_dict, userID, response):
|
|
|
+ page = int(request_dict.get('page', 0))
|
|
|
+ line = int(request_dict.get('line', 0))
|
|
|
+ if page == 0:
|
|
|
+ page=1
|
|
|
+ if line == 0:
|
|
|
+ line=10
|
|
|
+ qs = ApplicationModel.objects.all()
|
|
|
+ if qs.exists():
|
|
|
+ count = qs.count()
|
|
|
+ res = qs[(page - 1) * line:page * line]
|
|
|
+ send_json = CommonService.qs_to_dict(res)
|
|
|
+ send_json['count'] = count
|
|
|
+ return response.json(0, send_json)
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+
|
|
|
+ # 管理员的编辑
|
|
|
+ def update(self, request_dict, userID, response):
|
|
|
+ own_perm = ModelService.check_perm(userID=userID, permID=50)
|
|
|
+ if own_perm is not True:
|
|
|
+ return response.json(404)
|
|
|
+ deviceContent = request_dict.get('content', None)
|
|
|
+ id = request_dict.get('id', None)
|
|
|
+ if not deviceContent or not id:
|
|
|
+ return response.json(444, 'content,id')
|
|
|
+ try:
|
|
|
+ timestamp = int(time.time())
|
|
|
+ deviceData = json.loads(deviceContent)
|
|
|
+ uid_set = ApplicationModel.objects.filter(id=id)
|
|
|
+ if uid_set.exists():
|
|
|
+ uid_set.update(updTime=timestamp, **deviceData)
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
+ except Exception:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(500, {'details': errorInfo})
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def delete(self, request_dict, userID, response):
|
|
|
+ own_perm = ModelService.check_perm(userID=userID, permID=10)
|
|
|
+ if own_perm is not True:
|
|
|
+ return response.json(404)
|
|
|
+ id_list = request_dict.getlist('id', None)
|
|
|
+ if not id_list:
|
|
|
+ return response.json(444, 'id must list')
|
|
|
+ try:
|
|
|
+ for id in id_list:
|
|
|
+ ApplicationModel.objects.filter(id=id).delete()
|
|
|
+ except Exception as e:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(424, {'details': repr(e)})
|
|
|
+ else:
|
|
|
+ return response.json(0)
|
|
|
+
|