# Pyson syntax for 'states' attribut in a view

**URL:** https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942
**Category:** Developer
**Created:** [December 7, 2018, 10:45am UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942 "2018-12-07T10:45:27Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)
#### Post date: [December 7, 2018, 10:45am UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/1 "2018-12-07T10:45:27Z")

</div>

Hi,  
Is there somewhere a sample of the syntax that i must used in the attribut state in a view ?

I try:

> states=“{‘invisible’: Not(Eval(‘template.is\_wine’))}”

it don’t work (but wihout error)

> states=“{‘invisible’: 1}”

I have the following error:

`Expecting property name enclosed in double quotes: line 1 column 2 (char 1)`

Regards

---

<div class="post-metadata">

### Author: ![albert](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/albert/32/21_2.png) [@albert](https://discuss.tryton.org/u/albert)
#### Post date: [December 7, 2018, 11:10am UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/2 "2018-12-07T11:10:23Z")

</div>

Which tryton version are you using?

Newer versions don’t accept the states attribute but you should use: “view\_attributes()” method.

For example:

[http://hg.tryton.org/modules/commission/file/tip/invoice.py#l192](http://hg.tryton.org/modules/commission/file/tip/invoice.py#l192)

---

<div class="post-metadata">

### Author: ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)
#### Post date: [December 7, 2018, 12:27pm UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/3 "2018-12-07T12:27:15Z")

</div>

> [@albert](#):
>
> Which tryton version are you using?

Tryton 5.0.3

> [@albert](#):
>
> Newer versions don’t accept the states attribute but you should use: “view\_attributes()” method.

Ok, thanks for the info, I read that in the doc, but it must not be up to date.

---

<div class="post-metadata">

### Author: ![albert](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/albert/32/21_2.png) [@albert](https://discuss.tryton.org/u/albert)
#### Post date: [December 8, 2018, 10:29am UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/4 "2018-12-08T10:29:28Z")

</div>

> [@2cadz](#):
>
> Ok, thanks for the info, I read that in the doc, but it must not be up to date.

It is, indeed:

[http://docs.tryton.org/projects/server/en/latest/ref/models/models.html?highlight=view\_attributes#trytond.model.ModelView.view\_attributes](http://docs.tryton.org/projects/server/en/latest/ref/models/models.html?highlight=view_attributes#trytond.model.ModelView.view_attributes)

---

<div class="post-metadata">

### Author: ![xar](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/x/977dab/32.png) [@xar](https://discuss.tryton.org/u/xar)
#### Post date: [December 12, 2018, 9:26am UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/5 "2018-12-12T09:26:27Z")

</div>

I think 2cadz talked about the ‘states’ attribute as described in the views docs : [http://docs.tryton.org/projects/server/en/latest/topics/views/index.html#xml-description](http://docs.tryton.org/projects/server/en/latest/topics/views/index.html#xml-description). Not obvious that the Pyson expression can’t be stated direcly in the view’s xml.

BTW, view\_attributes works for the client, but doesn’t seems to be supported by Sao (at least, for the ‘invisible’ attribute).

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [December 12, 2018, 9:58am UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/6 "2018-12-12T09:58:35Z")

</div>

> [@xar](#):
>
> I think 2cadz talked about the ‘states’ attribute as described in the views docs : [Views — Tryton server](http://docs.tryton.org/projects/server/en/latest/topics/views/index.html#xml-description). Not obvious that the Pyson expression can’t be stated direcly in the view’s xml.

Probably this is for historical reasons as on previous versions it was possible to define the PYSON Expresion on the view directly. It will be great if you can [contribute](http://www.tryton.org/contribute) to improve it.

> [@xar](#):
>
> BTW, view\_attributes works for the client, but doesn’t seems to be supported by Sao (at least, for the ‘invisible’ attribute).

The behaviour should be the same for both clients, it sounds like a sao bug. Could you please [fill an issue](https://bugs.tryton.org/issue?@template=item) with some sample code in order to reproduce it?

Thank you so much!

---

<div class="post-metadata">

### Author: ![xar](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/x/977dab/32.png) [@xar](https://discuss.tryton.org/u/xar)
#### Post date: [December 12, 2018, 11:26am UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/7 "2018-12-12T11:26:00Z")

</div>

Fine, i’d be glad to be of any help.

Not sure how to contribute to the docs…

Nevertheless, I’m trying to write some code for testing the clients behavior.  
But I can’t manage to access fields with xpath. I tried to use : ‘//field[@id=“field\_id”]’ but doesn’t seems to work by any mean…  
How to do so (could find any example in modules source code, exepted for the above widgets).

---

<div class="post-metadata">

### Author: ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)
#### Post date: [December 12, 2018, 11:47am UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/8 "2018-12-12T11:47:01Z")

</div>

> [@xar](#):
>
> But I can’t manage to access fields with xpath. I tried to use : ‘//field[@id=“field\_id”]’ but doesn’t seems to work by any mean…

Normally replacing a field by its name (id attribute does not exist it seems to me)

`//field[@name=“field_name”]`

---

<div class="post-metadata">

### Author: ![xar](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/x/977dab/32.png) [@xar](https://discuss.tryton.org/u/xar)
#### Post date: [December 12, 2018, 12:54pm UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/9 "2018-12-12T12:54:36Z")

</div>

I must be lame but fields can’t be selected, even with ‘//field’…

---

<div class="post-metadata">

### Author: ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)
#### Post date: [December 12, 2018, 1:19pm UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/10 "2018-12-12T13:19:46Z")

</div>

Here a sample : [hg.tryton.org/modules/account\_invoice\_line\_standalone/file/5.0/view/invoice\_line\_tree\_sequence.xml](http://hg.tryton.org/modules/account_invoice_line_standalone/file/5.0/view/invoice_line_tree_sequence.xml)

---

<div class="post-metadata">

### Author: ![xar](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/x/977dab/32.png) [@xar](https://discuss.tryton.org/u/xar)
#### Post date: [December 12, 2018, 2:19pm UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/11 "2018-12-12T14:19:22Z")

</div>

OK, It seems that sao doesn’t update the class attribute ‘active’ of the content div when the page is set to invisibility. I filled a bug report : [https://bugs.tryton.org/issue7923](https://bugs.tryton.org/issue7923).

I still can’t select any field with view\_attributes. I’ll investigate later.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [December 12, 2018, 3:03pm UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/12 "2018-12-12T15:03:35Z")

</div>

> [@xar](#):
>
> Not sure how to contribute to the docs…

You should [submit a patch](http://www.tryton.org/develop) against the [doc folder of the trytond repository](http://hg.tryton.org/trytond/file/6571df5d8026/doc). The docs are build using [Sphinx](http://www.sphinx-doc.org/en/master/)

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [January 11, 2019, 3:03pm UTC](https://discuss.tryton.org/t/pyson-syntax-for-states-attribut-in-a-view/942/13 "2019-01-11T15:03:45Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
