コード例 #1
0
class ExportDestinationSerializer(serializers.HyperlinkedModelSerializer):
    """
    Serializer class for the
    :class:`~accounts.models.export_destination.ExportDestination` model.
    """

    users = UserSerializer(many=True, read_only=True)
    user_ids = serializers.PrimaryKeyRelatedField(
        write_only=True,
        required=False,
        allow_null=True,
        source="users",
        label="User IDs",
        help_text="Sets users access using primary keys.",
        many=True,
        queryset=User.objects.all(),
    )

    class Meta:
        model = ExportDestination
        fields = (
            "id",
            "title",
            "description",
            "ip",
            "username",
            "password",
            "destination",
            "users",
            "user_ids",
            "port",
            "socket_timeout",
            "negotiation_timeout",
            "banner_timeout",
        )
コード例 #2
0
ファイル: user.py プロジェクト: quangsen/vataxia_dev
 def post(self, request):
     serializer = UserSerializerCreate(data=request.data, context={'request': request})
     if serializer.is_valid():
         user = serializer.save()
         user.set_password(serializer.validated_data['password'])
         user.save()
         Profile(user=user).save()
         return Response(UserSerializer(user).data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #3
0
ファイル: api.py プロジェクト: JeffersonBC/calendarium
def user_create(request):
    serialized = UserSerializer(data=request.data)
    if serialized.is_valid():
        serialized.save()
        return Response(
            {
                'success': True,
                'msg': 'Usuário criado com sucesso.',
            },
            status=status.HTTP_201_CREATED
        )

    else:
        return Response(
            {
                'success': False,
                'msg': serialized.errors,
            },
            status=status.HTTP_400_BAD_REQUEST
        )
コード例 #4
0
ファイル: post.py プロジェクト: quangsen/vataxia_dev
class PostSerializer(serializers.ModelSerializer):
    post_reply_count = serializers.SerializerMethodField()
    tracks = PostReplySerializer(many=True, read_only=True)
    user = UserSerializer()

    class Meta:
        model = Post
        fields = '__all__'

    def get_post_reply_count(self, post):
        return PostReply.objects.filter(post=post).count()
コード例 #5
0
ファイル: api.py プロジェクト: JeffersonBC/calendarium
def current_user(request):
    if not request.auth:
        return Response(
            status=status.HTTP_401_UNAUTHORIZED
        )

    return Response(
        {
            'success': True,
            'msg': UserSerializer(request.user).data,
        },
        status=status.HTTP_200_OK
    )
コード例 #6
0
ファイル: profile.py プロジェクト: Avielyo10/pylabber
class ProfileSerializer(serializers.HyperlinkedModelSerializer):
    """
    `Serializer <https://www.django-rest-framework.org/api-guide/serializers/>`_
    class for the :class:`~accounts.models.profile.Profile` model.
    
    """

    url = serializers.HyperlinkedIdentityField(
        view_name="accounts:profile-detail")
    user = UserSerializer()

    class Meta:
        model = Profile
        fields = "__all__"
コード例 #7
0
    def setUp(self):
        self.user_attributes = {
            "first_name": "Sprint",
            "last_name": "Fast",
            "email": "*****@*****.**",
        }

        self.serialized_data = {
            "first_name": "Sprint",
            "last_name": "Fast",
            "email": "*****@*****.**",
        }

        self.user = UserModel.objects.create(**self.user_attributes)
        self.serializer = UserSerializer(instance=self.user)
コード例 #8
0
ファイル: user.py プロジェクト: quangsen/vataxia_dev
 def get(self, request):
     users = User.objects.all()
     serializer = UserSerializer(users, many=True)
     return Response(serializer.data)
コード例 #9
0
class AdministratorSerializer(serializers.ModelSerializer):
    user = UserSerializer()

    class Meta:
        model = Administrator
        fields = '__all__'