# coding=utf-8

from rest_framework import generics

from util.permission import IsCustomerUser
from apps.customer.coupon.serializers import MemberCouponSerializer
from apps.activity.models import MemberCoupon
from apps.activity.filters import MemberCouponFilter


class CouponListView(generics.ListAPIView):
    '''
    小程序显示我的卡券--显示用户所有优惠券信息
    '''
    permission_classes = [IsCustomerUser, ]
    queryset = MemberCoupon.objects.filter()
    serializer_class = MemberCouponSerializer

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