# coding=utf-8

from django.utils import timezone
from utils.custom_modelviewset import CustomModelViewSet
from utils.permission import isLogin
from .serializers import NoticesSerializer
from .models import Notices
from .filters import NoticesFilter


class NoticesViewSet(CustomModelViewSet):
    permission_classes = [isLogin, ]
    serializer_class = NoticesSerializer
    queryset = Notices.objects.filter()

    def filter_queryset(self, queryset):
        queryset = queryset.filter()
        f = NoticesFilter(self.request.GET, queryset=queryset)
        return f.qs

class WXNoticesViewSet(CustomModelViewSet):
    permission_classes = [ ]
    serializer_class = NoticesSerializer
    queryset = Notices.objects.filter()

    def filter_queryset(self, queryset):
        today = timezone.now().date()
        queryset = queryset.filter(end_time__gte=today)
        f = NoticesFilter(self.request.GET, queryset=queryset)
        return f.qs
