Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "contains" filter string function #43

Open
attieretief opened this issue May 4, 2020 · 2 comments
Open

Support for "contains" filter string function #43

attieretief opened this issue May 4, 2020 · 2 comments

Comments

@attieretief
Copy link

attieretief commented May 4, 2020

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
Copy link

tpow commented Jul 8, 2020

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
Copy link

eblis commented Mar 16, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants