Thursday, August 14, 2008

New new domain notation

Last week, I told you about the new domain notation. After a little peer reviewing, it appears that this notation is not as good as it seems. The inability to negate an expression (and not just a leaf) is more problematic that I have imagined. Thus, after a tiny discussion with Fabien, we decided to implement a (nearly) true polish notation for the domains. From now, the domains look more like the older ones that in the last week notation. This means there is no more extra parenthesis.
In addition of the classic leafs, you can add operators.

« Wait... what do you name leafs? »
A leaf, is a tuple of 3 elements composed of:
  1. a field name
  2. an operator (as string)
  3. a value
Example:

('active', '=', True)
('foo', '!=', 'bar')
('id', 'in', [7, 13, 42, 666])
('id', '=', False)
('name', 'like', 'tiny')


« And which operators are allowed? »
Like the last week notation, the AND ('&') and OR ('|') operators are allowed . Unlike the last week notation, the arity of these operators is fixed to 2.
And yes, the one you have all been waiting for is now in: The NOT ('!') operator. This one has an arity of 1.
For compatibility with existing domains, the AND operator is applied by default.

« So, what looks like this new new notation? »
Some examples:

['&', ('active', '=', True), ('value', '!=', 'foo')]
['|', ('active', '=', True), ('state', 'in', ['open', 'draft'])
['&', ('active', '=', True), '|', '!', ('state', '=', 'closed'), ('state', '=', 'draft')]
['|', '|', ('state', '=', 'open'), ('state', '=', 'closed'), ('state', '=', 'draft')]
['!', '&', '!', ('id', 'in', [42, 666]), ('active', '=', False)]


PS: Tanks to Najlâa and Olivier for the review.

8 comments:

Ovnicraft said...

really great work, i am reading your code in expression.py and i want to know if is posible support BETWEEN command there, so i am debbuging that, but if you can help me with any info, thanks

regards,

Anonymous said...

did not understand.
I need to invert the expression of 2 and

(
( 'mmt_rev', '=' , 1) , ('state', '=', 'd')
)

Please help

Priyanka said...
This comment has been removed by the author.
Priyanka said...

Please give me a sample for company -> division -> department

go through more posts & samples.but unable to implement that yet

thanks friend..

Vivek Rajan said...

Hi,

I have a problem on specifying the domain condition. Please help me.

[([1,2,3],'?',[1])]

1) [1,2,3] is a many2many field
2) '?' want to know which operator to use
3)[1] is one of the values in the many2many feild

Please help me in this

james brownn said...

Wow i can say that this is another great article as expected of this blog.Bookmarked this site..
best web hosting

Maria John said...
This comment has been removed by the author.
jimu jee said...

Many blogs like this cover subjects that just aren’t covered by magazines.
offshoreservers.net