64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
from django.shortcuts import render
|
|
from rest_framework.generics import ListAPIView
|
|
# Create your views here.
|
|
from .models import *
|
|
from rest_framework.permissions import AllowAny, IsAuthenticated
|
|
from rest_framework.response import Response
|
|
from .serializers import *
|
|
from userauth.models import *
|
|
|
|
class LinkAPIView(ListAPIView):
|
|
permission_classes = (AllowAny,)
|
|
serializer_class = LinkSerializer
|
|
|
|
|
|
def get(self, request):
|
|
|
|
queryset = Links.objects.all().order_by('order')
|
|
serializer = self.serializer_class(queryset, many=True)
|
|
return Response(serializer.data)
|
|
|
|
|
|
class NewsAPIView(ListAPIView):
|
|
permission_classes = (AllowAny,)
|
|
serializer_class = NewsSerializer
|
|
|
|
|
|
def get(self, request):
|
|
|
|
queryset = News.objects.all().order_by('cdate')[:10]
|
|
# serializer = self.serializer_class(queryset, many=True)
|
|
# print(serializer.data)
|
|
result = []
|
|
for x in queryset:
|
|
|
|
a=model_to_dict(x)
|
|
a['link']= str(x.link.url)
|
|
a['show'] = False
|
|
a['author'] = model_to_dict(DictEmployee.objects.using('user_directory').get(login=x.author.username))
|
|
result.append(a)
|
|
|
|
return Response(result)
|
|
|
|
class CarouselsAPIView(ListAPIView):
|
|
permission_classes = (AllowAny,)
|
|
serializer_class = CarouselsSerializer
|
|
|
|
|
|
def get(self, request):
|
|
|
|
queryset = Carousels.objects.filter(published=True).order_by('order')
|
|
# serializer = self.serializer_class(queryset, many=True)
|
|
# print(serializer.data)
|
|
result = []
|
|
for x in queryset:
|
|
|
|
a=model_to_dict(x)
|
|
a['link']= str(x.link.url)
|
|
a['show'] = False
|
|
a['author'] = model_to_dict(DictEmployee.objects.using('user_directory').get(login=x.author.username))
|
|
result.append(a)
|
|
|
|
return Response(result)
|
|
|