def retrieve(self, request, username): """ GET /api/user/v1/accounts/{username}/ """ try: account_settings = get_account_settings( request, [username], view=request.query_params.get('view')) except UserNotFound: return Response(status=status.HTTP_403_FORBIDDEN if request.user.is_staff else status.HTTP_404_NOT_FOUND) # Update VIP info for elite if settings.FEATURES.get('ENABLE_MEMBERSHIP_INTEGRATION'): NOT_PURCHASED = 1 BOUGHT = 2 EXPIRED = 3 try: from membership.models import VIPInfo vip_info = VIPInfo.get_vip_info_for_mobile(request.user) vip_info_emb = {} if vip_info['is_vip']: vip_info_emb['vip_status'] = BOUGHT else: if VIPInfo.get_vipinfo_for_user(request.user): vip_info_emb['vip_status'] = EXPIRED else: vip_info_emb['vip_status'] = NOT_PURCHASED vip_info_emb['vip_remain_days'] = vip_info['vip_remain_days'] account_settings[0].update(vip_info_emb) except Exception as exc: log.exception('Unable to get user:{} VIP info'.format(request.user.username)) return Response(account_settings[0])
def list(self, request, *args, **kwargs): vip_info = VIPInfo.get_vip_info_for_mobile(self.request.user) queryset = self.filter_queryset(self.get_queryset()) page = self.paginate_queryset(queryset) if page is not None: serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data, extra=vip_info) serializer = self.get_serializer(queryset, many=True) return Response(serializer.data)
def get(self, request, *args, **kwargs): vip_info = VIPInfo.get_vip_info_for_mobile(self.request.user) return Response(vip_info)