python-odata icon indicating copy to clipboard operation
python-odata copied to clipboard

Support for "contains" filter string function

Open attieretief opened this issue 5 years ago • 2 comments

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

attieretief avatar May 04 '20 19:05 attieretief

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) 

tpow avatar Jul 08 '20 17:07 tpow

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.

eblis avatar Mar 16 '23 12:03 eblis