123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- from django.db.models import Max
- from django.shortcuts import render
- from django.forms.models import model_to_dict
- # Create your views here.
- from rest_framework import status,filters
- from rest_framework.authentication import SessionAuthentication, BasicAuthentication
- from rest_framework.permissions import IsAuthenticated,AllowAny
- from rest_framework.response import Response
- from rest_framework.views import APIView
- from rest_framework.viewsets import ModelViewSet
- from rest_framework_jwt.authentication import JSONWebTokenAuthentication
- from utils import elmentList
- from bsdata.models import Company, Navigation, Slideshow, Hmwe, Hmart, Column, Hmcase, Hmgroup, Hmaddress, \
- WnComponentCssModel, WnComponentModel, WnComponentKeyModel
- from bsdata.serializer import WnComponentCssSerializer, WnComponentSerializer, WnComponentKeyModelSerializer
- # 查看公司
- class WbCompany(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self,request):
- id__max = Company.objects.aggregate(Max('id'))
- data = Company.objects.get(id=id__max['id__max'])
- data = {'id':data.id,'name':data.name}
- return Response(data, status=status.HTTP_200_OK)
- # 查看导航
- class WbNavigation(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self,request):
- data = Navigation.objects.all().values('id', 'name','path')
- data = list(data)
- return Response(data, status=status.HTTP_200_OK)
- # 获取轮播
- class WbSlideshow(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self,request):
- data = Slideshow.objects.all().values('id', 'imgurl','url','sort').order_by('sort')
- data = list(data)
- return Response(data, status=status.HTTP_200_OK)
- # 关于我们
- class WbHmwe(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self,request):
- data = Hmwe.objects.all().values('id', 'title','content')
- data = list(data)
- return Response(data, status=status.HTTP_200_OK)
- # 技术与服务
- class WbHmart(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self,request):
- data = Hmart.objects.all().values('id', 'title','content','icon')
- data = list(data)
- return Response(data, status=status.HTTP_200_OK)
- # 栏目标签
- class WbColumn(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self,request):
- data = Column.objects.all().values('id', 'title','content')
- data = list(data)
- return Response(data, status=status.HTTP_200_OK)
- # 成功案例
- class WbHmcase(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self,request):
- data = Hmcase.objects.all().values('id', 'company','artisan','signatory','satisfaction','words','signatory_time')
- data = list(data)
- return Response(data, status=status.HTTP_200_OK)
- # 团队介绍
- class WbHmgroup(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self,request):
- data = Hmgroup.objects.all().values('id', 'name','imgurl','intro')
- data = list(data)
- return Response(data, status=status.HTTP_200_OK)
- class WbHmaddress(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self,request):
- data = Hmaddress.objects.all().values('id', 'content','add','tel')
- data = list(data)
- return Response(data, status=status.HTTP_200_OK)
- # 获取组件使用中的组件
- class WnComponentkeyView(ModelViewSet):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- # 1,提供通用的序列化器
- serializer_class = WnComponentKeyModelSerializer
- # filter_backends = (filters.OrderingFilter,) # 固定写法
- filter_backends = (filters.OrderingFilter,) # 固定写法
- filterset_fields = ('id', 'sort')
- ordering_fields = ('id','sort',)
- # 2,提供通用的数据集
- queryset = WnComponentKeyModel.objects.all()
- import ast
- # 获取组件样式
- class WnComponentCssView(APIView):
- # 1,设置局部认证
- authentication_classes = [SessionAuthentication, BasicAuthentication]
- # 2,设置局部权限
- permission_classes = (AllowAny,)
- def get(self, request):
- params = request.query_params.get("componentkey")
- result = WnComponentCssModel.objects.filter(componentkey = params)
- field_list = elmentList.field_list
- # field_list = []
- if len(result) == 0 :
- return Response('没有查询到样式', status=status.HTTP_203_NON_AUTHORITATIVE_INFORMATION)
- data = model_to_dict(result[0]) # 取第一条记录,转换为字典
- new_data = {}
- for key,value in data.items():
- new_data[key] = value
- if key in field_list:
- data[key] = ast.literal_eval(value)
- return Response(data, status=status.HTTP_200_OK)
|