# Path: apps/core/models.py
# class Notice(models.Model):
#     """
#     denotes single notice
#     - title:      notice title
#     - valid_from: display start time
#     - valid_to:   display end time
#     - text:       notice content; html
#     """
#     title = models.CharField(max_length=100)
#     valid_from = models.DateTimeField()
#     valid_to = models.DateTimeField()
#     text = models.TextField()
# 
#     def to_dict(self):
#         return {
#             'valid_from': self.valid_from.isoformat(),
#             'valid_to': self.valid_to.isoformat(),
#             'title': self.title,
#             'text': self.text,
#         }
# 
#     def __str__(self):
#         return self.title
# 
# Path: apps/web/serializers/notice.py
# class NoticeSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Notice
#         fields = ['title', 'text']


from django.utils import timezone
from rest_framework import decorators, viewsets
from rest_framework.response import Response
from apps.core.models import Notice
from apps.web.serializers.notice import NoticeSerializer



class NoticeViewSet(viewsets.ViewSet):
    queryset = Notice.objects
    serializer_class = NoticeSerializer

    def list(self, request):
        current_time = timezone.now()
        notices = self.queryset.queryset.filter(
            valid_from__lte=current_time,
            valid_to__gt=current_time,
        ).order_by('-valid_from')

# Path: apps/core/models.py
# class Notice(models.Model):
#     """
#     denotes single notice
#     - title:      notice title
#     - valid_from: display start time
#     - valid_to:   display end time
#     - text:       notice content; html
#     """
#     title = models.CharField(max_length=100)
#     valid_from = models.DateTimeField()
#     valid_to = models.DateTimeField()
#     text = models.TextField()
# 
#     def to_dict(self):
#         return {
#             'valid_from': self.valid_from.isoformat(),
#             'valid_to': self.valid_to.isoformat(),
#             'title': self.title,
#             'text': self.text,
#         }
# 
#     def __str__(self):
#         return self.title
# 
# Path: apps/web/serializers/notice.py
# class NoticeSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Notice
#         fields = ['title', 'text']


# Path: apps/web/views/notice.py
from django.utils import timezone
from rest_framework import decorators, viewsets
from rest_framework.response import Response
from apps.core.models import Notice
from apps.web.serializers.notice import NoticeSerializer




class NoticeViewSet(viewsets.ViewSet):
    queryset = Notice.objects
    serializer_class = NoticeSerializer

    def list(self, request):
        current_time = timezone.now()
        notices = self.queryset.queryset.filter(
            valid_from__lte=current_time,
            valid_to__gt=current_time,
        ).order_by('-valid_from')

        serializer = self.serializer_class(notices, many=True)