Example #1
0
class UserInfoSerializer(serializers.ModelSerializer):
    languages = CreatableSlugRelatedField(many=True,
                                          slug_field='name',
                                          read_only=True)

    skills = CreatableSlugRelatedField(many=True,
                                       slug_field='name',
                                       read_only=True)

    class Meta:
        model = User
        exclude = (
            'id',
            'nonce',
            'profile_touched_manually',
            'categories',
            'settings',
        )
class DraftBountyWriteSerializer(serializers.ModelSerializer):
    # In general try and not have all this logic in a serializer
    categories = CreatableSlugRelatedField(many=True,
                                           slug_field='name',
                                           queryset=Category.objects.all())
    token_contract = serializers.CharField(required=False, allow_blank=True)
    token_symbol = serializers.CharField(read_only=True)
    token_decimals = serializers.IntegerField(read_only=True)
    arbiter = serializers.CharField(allow_blank=True, required=False)
    usd_price = serializers.FloatField(read_only=True)
    on_chain = serializers.BooleanField(read_only=True)
    # current_market_token_data = TokenSerializer(read_only=True, source='token')
    attached_url = serializers.CharField(required=False, allow_blank=True)
    uid = serializers.CharField(read_only=True)
    calculated_fulfillment_amount = serializers.DecimalField(decimal_places=30,
                                                             max_digits=70,
                                                             read_only=True)
    user = UserSerializer(read_only=True)
    issuer = serializers.CharField(read_only=True)

    class Meta:
        model = DraftBounty
        exclude = ('token', )

    @transaction.atomic
    def create(self, validated_data):
        instance = super(DraftBountyWriteSerializer,
                         self).create(validated_data)
        request = self.context.get('request')
        user = request.current_user
        instance.user = user
        token_data = map_token_data(str(instance.token_version),
                                    validated_data.get('token_contract'),
                                    validated_data.get('fulfillment_amount'))
        instance.token_symbol = token_data.get('token_symbol')
        instance.token_decimals = token_data.get('token_decimals')
        instance.token_contract = token_data.get('token_contract')
        instance.usd_price = token_data.get('usd_price')
        instance.issuer = user.public_address
        # instance.attached_url = validated_data.get('attached_url')
        instance.save()
        return instance

    @transaction.atomic
    def update(self, instance, validated_data):
        super(DraftBountyWriteSerializer, self).update(instance,
                                                       validated_data)
        token_data = map_token_data(str(instance.token_version),
                                    validated_data.get('token_contract'),
                                    validated_data.get('fulfillment_amount'))
        instance.token_symbol = token_data.get('token_symbol')
        instance.token_decimals = token_data.get('token_decimals')
        instance.token_contract = token_data.get('token_contract')
        instance.usd_price = token_data.get('usd_price')
        instance.save()
        return instance
Example #3
0
class UserSerializer(serializers.ModelSerializer):
    categories = CreatableSlugRelatedField(many=True,
                                           slug_field='name',
                                           read_only=True)

    languages = CreatableSlugRelatedField(many=True,
                                          slug_field='name',
                                          read_only=True)

    skills = CreatableSlugRelatedField(many=True,
                                       slug_field='name',
                                       read_only=True)

    page_preview = serializers.CharField(max_length=256, read_only=True)

    settings = SettingsSerializer()

    class Meta:
        model = User
        exclude = (
            'nonce',
            'profile_touched_manually',
        )