Example #1
0
	def post(self, request, format=None):
		serializer = ProductSerializer(data=request.data)
		if serializer.is_valid():
			serializer.save()
			return JsonResponse(data=serializer.data, code=status.HTTP_200_OK, message='')
			#return Response(serializer.data, status=status.HTTP_201_CREATED)
		return JsonResponse(data=serializer.errors, code=status.HTTP_400_BAD_REQUEST, message='')
Example #2
0
	def post(self, request, format=None):
		print '6'
		serializer = UserSerializer(data=request.data)
		password = self.request.POST.get('password')
		if serializer.is_valid():
			serializer.save(password = make_password(password))
			return JsonResponse(data=serializer.data, code=status.HTTP_200_OK, message='')
			#return Response(serializer.data, status=status.HTTP_201_CREATED)
		return JsonResponse(data=serializer.errors, code=status.HTTP_400_BAD_REQUEST, message='')
Example #3
0
	def post(self, request,TbName,format=None):
		#try:
			m1 =importlib.import_module('api.serializers')
			SeClass = getattr(m1,TbName + 'Serializer')
			serializer = SeClass(data=request.data)
			#print request.data
			if serializer.is_valid():
				serializer.save()
				return JsonResponse(data=serializer.data, code=status.HTTP_200_OK, message='')
				#return Response(serializer.data, status=status.HTTP_201_CREATED)
			return JsonResponse(data=serializer.errors, code=status.HTTP_400_BAD_REQUEST, message='')
Example #4
0
	def put(self, request, TbName,pk, format=None):
		user = self.get_object(TbName,pk)
		print request.data
		m1 =importlib.import_module('api.serializers')
		SeClass = getattr(m1,TbName + 'Serializer')
		serializer = SeClass(user, data=request.data)
		if serializer.is_valid():
			serializer.save()
			#return Response(serializer.data)
			return JsonResponse(data=serializer.data, code=status.HTTP_200_OK, message='')
		#return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
		return JsonResponse(data=serializer.errors, code=status.HTTP_400_BAD_REQUEST, message='')
Example #5
0
	def put(self, request, pk, format=None):
		print '2'
		user = self.get_object(pk)
		print request
		serializer = UserSerializer(user, data=request.data)
		if serializer.is_valid():
			if 'password' in self.request.POST:
				uquery = User.objects.get(name = self.request.POST.get('name'))
				password = self.request.POST.get('password')
				uquery.set_password = password
			serializer.save()
			#return Response(serializer.data)
			return JsonResponse(data=serializer.data, code=status.HTTP_200_OK, message='')
		#return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
		return JsonResponse(data=serializer.errors, code=status.HTTP_400_BAD_REQUEST, message='')
Example #6
0
	def get(self,request,cmd):
		print cmd,request.data
		cmd_out=os.popen(cmd)
		result =  cmd_out.read().rstrip('\n')
		data = result.decode('gb2312')
		#return HttpResponse(data)
		return JsonResponse(data='%s'%data, code=status.HTTP_200_OK, message='') 
Example #7
0
	def get(self, request,TbName,product_id):
		try:
			m0 =importlib.import_module('p1.tables')
			TbClass = getattr(m0,TbName)
			m1 =importlib.import_module('api.serializers')
			SeClass = getattr(m1,TbName + 'Serializer')
			TbObjects = TbClass.objects.filter(product_id = product_id)
			o = User.objects.get(name=request.user)
			#if TbName == 'Product':
				#print TbName,request.user,User.objects.get(name = request.user).AccountID
			#	TbObjects = TbClass.objects.filter(owner_id = User.objects.get(name = request.user).AccountID)
			#	print TbObjects
			serializer = SeClass(TbObjects, many=True)
			return JsonResponse(data=serializer.data, code=status.HTTP_200_OK, message='') 
		except:
			return JsonResponse(data='', code='0', message='不存在') 
Example #8
0
	def get(self, request, TbName,pk, format=None):
		user = self.get_object(TbName,pk)
		m1 =importlib.import_module('api.serializers')
		SeClass = getattr(m1,TbName + 'Serializer')
		serializer = SeClass(user)
		#return Response(serializer.data)
		return JsonResponse(data=serializer.data, code=status.HTTP_200_OK, message='')
Example #9
0
	def get(self,request):
		#cmd_out=os.popen(cmd)
		#result =  cmd_out.read().rstrip('\n')
		#data = result.decode('gb2312')
		#print request.data
		cmd = request.GET.get('cmd')
		cmd_argv = request.GET.get('argv')
		print cmd,cmd_argv
		result = os.popen('%s %s'%(cmd,cmd_argv))
		print 'cmd_result',result
		data = result.read().decode('gb2312')
		print 'response',data
		#return HttpResponse(data)
		return JsonResponse(data='%s'%data, code=status.HTTP_200_OK, message='') 
Example #10
0
	def get(self, request, pk, format=None):
		user = self.get_object(pk)
		serializer = UserSerializer(user)
		#return Response(serializer.data)
		return JsonResponse(data=serializer.data, code=status.HTTP_200_OK, message='')
Example #11
0
	def get(self, request,format=None):
		users = User.objects.all()
		serializer = UserSerializer(users, many=True)
		return JsonResponse(data=serializer.data, code=status.HTTP_200_OK, message='') 
Example #12
0
	def delete(self, request, TbName,pk, format=None):
		user = self.get_object(TbName,pk)
		user.delete()
		return JsonResponse(data='delete ok', code=status.HTTP_200_OK, message='')