Пример #1
0
    def post(self, request, format=None):
        _name = request.user.customer.name
        _avatar_url = request.user.customer.avatar_url
        if 'condition' in request.data:
            required_fields = [
                'age_range', 'height_range', 'profession', 'education',
                'income', 'marital_status', 'child_status', 'years_to_marry'
            ]
            for key in required_fields:
                if key not in json.loads(request.data.get('condition')):
                    return Response(data={'detail': 'condition缺少字段或格式错误'},
                                    status=status.HTTP_400_BAD_REQUEST)

        serializer = CustomerSerializer(request.user.customer,
                                        data=request.data,
                                        partial=True)
        if serializer.is_valid(raise_exception=True):
            if 'avatar_url' in serializer.validated_data:
                serializer.validated_data[
                    'avatar_url'] = serializer.validated_data['avatar_url']
                avatar_url = serializer.validated_data.pop('avatar_url')
                serializer.validated_data['avatar_status'] = 0
                mm_Picture.add_picture(request.user.customer.id, avatar_url)
            serializer.save()
            if any([
                    not _name == serializer.data['name'],
                    not _avatar_url == serializer.data['avatar_url']
            ]):
                IMServe.refresh_token(request.user.customer.id,
                                      request.user.customer.name,
                                      request.user.customer.avatar_url)
            return Response(Tool.format_data(serializer.data))
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
def make_verified(modeladmin, request, queryset):
    for picture in queryset:
        picture.customer.avatar_url = picture.url
        picture.customer.avatar_status = 1
        picture.customer.save()
        picture.is_verified = True
        picture.save()
        IMServe.refresh_token(picture.customer.id, picture.customer.name, picture.url)