tuomur / python-odata

A simple library for read/write access to OData services
MIT License
79 stars 59 forks source link

Support for "contains" filter string function #43

Open attieretief opened 4 years ago

attieretief commented 4 years ago

The ODATAV4 standard supports the string function "contains"

http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc444868693

See 11.2.5.1.2 Built-in Query Functions in the following section

http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part1-protocol/odata-v4.0-errata03-os-part1-protocol-complete.html#_Toc453752288

If implemented exactly the same way as this project already implements "startswith" and "endswith", then wildcard search on specified attributes can be used.

This was achieved by modifiying property.py

    def contains(self, value):
        value = self.escape_value(value)
        return u'contains({0}, {1})'.format(self.name, value)
image
tpow commented 4 years ago

Hi @attieretief This is a great point. I also implemented this for my own use as well as a related "lacks" or "does not contain" method. I'm including it below in case you find it helpful.

   def contains(self, value):                                                   
        """Extend the StringProperty with contains method"""                     
        value = self.escape_value(value)                                         
        return u'contains({0}, {1})'.format(self.name, value)                    

    def lacks(self, value):                                                      
        """Does not contain"""                                                   
        value = self.escape_value(value)                                         
        return u'not(contains({0}, {1}))'.format(self.name, value) 
eblis commented 1 year ago

This project looks to be no longer maintained, i have forked it here and tried to add (some) of your suggested functionality. I've also published it to PyPi as python-odata, if you're interested.