From: Thierry Parmentelat Date: Tue, 21 Nov 2006 10:22:05 +0000 (+0000) Subject: support for negation with fields starting with ~ X-Git-Tag: pycurl-7_13_1~274 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=7abe61ddbeb47ced44f58073bb1a9af5a7adc31c;p=plcapi.git support for negation with fields starting with ~ --- diff --git a/PLC/Filter.py b/PLC/Filter.py index a7c14ce5..139da580 100644 --- a/PLC/Filter.py +++ b/PLC/Filter.py @@ -53,6 +53,12 @@ class Filter(Parameter, dict): assert join_with in ("AND", "OR") for field, value in self.iteritems(): + # provide for negation with a field starting with ~ + negation=False + if field[0]=='~': + negation=True + field=field[1:] + if field not in self.fields: raise PLCInvalidArgument, "Invalid filter field '%s'" % field @@ -72,6 +78,10 @@ class Filter(Parameter, dict): operator = "=" value = str(api.db.quote(value)) - conditionals.append("%s %s %s" % (field, operator, value)) + clause = "%s %s %s" % (field, operator, value) + if negation: + clause = " ( NOT %s ) "%clause + + conditionals.append(clause) return (" %s " % join_with).join(conditionals)