Beispiel #1
0
 def activity_self_rank(self, request):
     if request.user.is_anonymous:
         raise exceptions.PermissionDenied(u'用户未登录或并非小鹿妈妈')
     mama = request.user.customer.getXiaolumm()
     if not mama:
         raise exceptions.ValidationError(u'用户未登录或并非小鹿妈妈')
     myteam = MamaTeamCarryTotal.get_by_mama_id(mama.id)
     return Response(ActivityMamaTeamCarryTotalSerializer(myteam).data)
Beispiel #2
0
 def carry_total_rank(self, request):
     top = MamaTeamCarryTotal.get_ranking_list()[0:10]
     top = list(top)
     i = 1
     for t in top:
         t._rank_ = i
         i += 1
     return Response(self.get_serializer(top, many=True).data)
Beispiel #3
0
 def activity_carry_total_rank(self, request):
     top = MamaTeamCarryTotal.get_activity_ranking_list()[0:100]
     res = ActivityMamaTeamCarryTotalSerializer(top, many=True).data
     # 前台html已经提交了 只好适应一下补两句代码
     top = list(top)
     for t in top:
         res[top.index(t)]['rank'] = t.activite_rank
         res[top.index(t)]['duration_num'] = t.expect_num
         res[top.index(t)]['duration_total'] = t.expect_total
         res[top.index(t)]['duration_total_display'] = float(
             '%.2f' % (t.expect_total * 0.01))
     return Response(res)
Beispiel #4
0
 def get_team_award_realtime(self, request):
     res = []
     for m in MamaTeamCarryTotal.get_activity_ranking_list()[:50]:
         try:
             item = {
                 'mama_id': m.mama_id,
                 'income': m.expect_total,
                 'mama_nick': m.mama_nick,
                 'thumbnail': m.thumbnail
             }
             res.append(item)
         except Exception, e:
             logger.error('mama no customer' + str(m.mama_id) + '|' +
                          str(e.message))
Beispiel #5
0
 def activity(self, request, pk):
     res = ActivityMamaTeamCarryTotalSerializer(
         MamaTeamCarryTotal.get_by_mama_id(pk)).data
     return Response(res)
Beispiel #6
0
 def carry_duration_total_rank(self, request):
     top = MamaTeamCarryTotal.get_duration_ranking_list()[0:100]
     return Response(
         MamaTeamCarryTotalDurationSerializer(top, many=True).data)
Beispiel #7
0
 def get_team_members(self, request, pk):
     team = MamaTeamCarryTotal.get_by_mama_id(pk)
     records = MamaCarryTotal.objects.filter(mama_id__in=team.mama_ids)
     return Response(self.get_serializer(records, many=True).data)
Beispiel #8
0
 def retrieve(self, request, pk):
     res = self.get_serializer(MamaTeamCarryTotal.get_by_mama_id(pk)).data
     return Response(res)
Beispiel #9
0
class MamaTeamCarryTotalViewSet(viewsets.GenericViewSet,
                                viewsets.mixins.RetrieveModelMixin,
                                viewsets.mixins.ListModelMixin):
    """
        妈妈团队收益排行榜
    """
    queryset = MamaTeamCarryTotal.get_ranking_list()
    serializer_class = MamaTeamCarryTotalSerializer
    authentication_classes = (authentication.SessionAuthentication,
                              authentication.BasicAuthentication)
    permission_classes = (permissions.IsAuthenticatedOrReadOnly, )

    @list_route(methods=['GET'])
    def self_rank(self, request):
        if request.user.is_anonymous:
            raise exceptions.PermissionDenied(u'用户未登录或并非小鹿妈妈')
        mama = request.user.customer.getXiaolumm()
        if not mama:
            raise exceptions.ValidationError(u'用户未登录或并非小鹿妈妈')
        myteam = MamaTeamCarryTotal.get_by_mama_id(mama.id)
        return Response(self.get_serializer(myteam).data)

    @list_route(methods=['GET'])
    def carry_total_rank(self, request):
        top = MamaTeamCarryTotal.get_ranking_list()[0:10]
        top = list(top)
        i = 1
        for t in top:
            t._rank_ = i
            i += 1
        return Response(self.get_serializer(top, many=True).data)

    @list_route(methods=['GET'])
    def carry_duration_total_rank(self, request):
        top = MamaTeamCarryTotal.get_duration_ranking_list()[0:100]
        return Response(
            MamaTeamCarryTotalDurationSerializer(top, many=True).data)

    def retrieve(self, request, pk):
        res = self.get_serializer(MamaTeamCarryTotal.get_by_mama_id(pk)).data
        return Response(res)

    @detail_route(methods=['GET'])
    def activity(self, request, pk):
        res = ActivityMamaTeamCarryTotalSerializer(
            MamaTeamCarryTotal.get_by_mama_id(pk)).data
        return Response(res)

    @list_route(methods=['GET'])
    def activity_self_rank(self, request):
        if request.user.is_anonymous:
            raise exceptions.PermissionDenied(u'用户未登录或并非小鹿妈妈')
        mama = request.user.customer.getXiaolumm()
        if not mama:
            raise exceptions.ValidationError(u'用户未登录或并非小鹿妈妈')
        myteam = MamaTeamCarryTotal.get_by_mama_id(mama.id)
        return Response(ActivityMamaTeamCarryTotalSerializer(myteam).data)

    @list_route(methods=['GET'])
    def activity_carry_total_rank(self, request):
        top = MamaTeamCarryTotal.get_activity_ranking_list()[0:100]
        res = ActivityMamaTeamCarryTotalSerializer(top, many=True).data
        # 前台html已经提交了 只好适应一下补两句代码
        top = list(top)
        for t in top:
            res[top.index(t)]['rank'] = t.activite_rank
            res[top.index(t)]['duration_num'] = t.expect_num
            res[top.index(t)]['duration_total'] = t.expect_total
            res[top.index(t)]['duration_total_display'] = float(
                '%.2f' % (t.expect_total * 0.01))
        return Response(res)