0

I have Django model

class OrderItem(models.Model):
    comment = models.CharField('comment', max_length=255, blank=True)
    ..... 

and other fields which are not important.

And I have spyne models described like this

class OrderItemModel(DjangoComplexModel):
    __type_name__ = 'OrderItem'

    class Attributes(DjangoComplexModel.Attributes):
        django_model = OrderItem

and function which generate the response

@rpc(Int, _returns=Iterable(OrderItemModel)) 
def GetOrderItems(self, id):
     order = get_object(Order, pk=id)
     items = order.objects.all()
     return items

xml description is

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
       <SaveOrderItem xmlns="app.sync">
        <model>
           <comment xmlns="app.sync.models">[normalizedString]</comment>
        </model>
       </SaveOrderItem>
        </Body>
</Envelope>

The server which make request then validate response, and raise an exception when found that comment have spaces on start or end os string. As I understand the type normalizedString does not allow to use not stripped stings. So is any way to remove spaces on the fly from that type of strings. I looked in to the source and find class definition

class NormalizedString(Unicode):
    __type_name__ = 'normalizedString'
    __extends__ = Unicode

    class Attributes(Unicode.Attributes):
        white_space = "replace"

So that white_space = "replace" do that check on the client side.

Igor Kremin
  • 355
  • 4
  • 8
  • I don't get this. My interpretation of whiteSpace is that it's not a restriction but an operation. It shouldn't be the source of your problems. See: https://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#rf-whiteSpace – Burak Arslan Feb 21 '16 at 21:32
  • That type you found is for Xml Schema compatibility. You can replace all whitespace with spaces using usual methods before returning the object. – Burak Arslan Feb 21 '16 at 21:34
  • One last thing, whiteSpace="replace" and whiteSpace="collapse" are two different things. It seems to me that you're confusing them. Please read the spec in the link I gave carefully. – Burak Arslan Feb 21 '16 at 21:43
  • Yes of course I can strip all fileds manualy, and return the object inherited from ComplexModel, but I have lot's of models and this solution will make support them little difficult. And about whiteSpace I am not configure it, that is default behaviour. All string fields (models.CharField) of Django models described as normalizedString in SOAP returned objects. I think response function should strips strings in response as it set type of the filed normalizedString. – Igor Kremin Feb 22 '16 at 17:42

1 Answers1

0

I have found solution for this issue: I just replace 'CharField' in the default field mapper to Unicode by the one line

default_model_mapper.register('CharField', primitive.Unicode) instead of default ('CharField', primitive.NormalizedString)

which is described in spyne/util/django.py

Igor Kremin
  • 355
  • 4
  • 8