json syntax to populate a model

35 views
Skip to first unread message

lists.j...@symetrie.com

unread,
Jul 18, 2017, 2:49:35 AM7/18/17
to try...@googlegroups.com
Hi,

I found in party/tests/test_party a json syntax to pass data to populate a model with proteus, but I see a « keys error » when trying to use it:

Python 2.7.13 (default, Apr 23 2017, 16:56:24)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from proteus import config, Model, Wizard
>>> def set_config(database, user, config_file=None):
... return config.set_trytond(database, user, config_file=config_file)
...
>>> config = set_config(u't44_4', u'admin', '/Users/jcm/Sites/_tryton/tryton4.4/my_local_trytond.conf')
>>> Party = Model.get('party.party')
>>> party1, = Party.create([{
... 'name': 'Party 1',
... }])
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/Users/jcm/Sites/_tryton/tryton4.4/proteus/proteus/config.py", line 169, in __call__
rpc.convert(self._object, *args)
File "/Users/jcm/Sites/_tryton/tryton4.4/trytond/trytond/rpc.py", line 36, in convert
for key in context.keys():
AttributeError: 'list' object has no attribute ‘keys'


Jean-Christophe Michel

Sergi Almacellas Abellana

unread,
Jul 18, 2017, 3:14:19 AM7/18/17
to try...@googlegroups.com
El 18/07/17 a les 08:49, lists.j...@symetrie.com ha escrit:
You should pass the proteus config as last argument as you are calling
and rpc method directly.

If you want to create a list of objects using proteus, i will recomend
using save with a list of records:

records = []
for x in range(10):
record = Model()
record.xxx = yyy
records.append(record)
Model.save(records)

Hope it helps.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Cédric Krier

unread,
Jul 18, 2017, 3:30:06 AM7/18/17
to try...@googlegroups.com
On 2017-07-18 08:49, lists.j...@symetrie.com wrote:
> Hi,
>
> I found in party/tests/test_party a json syntax to pass data to populate a model with proteus,

This is not json, it is Python dict and it does not use proteus.

> but I see a « keys error » when trying to use it:
>
> Python 2.7.13 (default, Apr 23 2017, 16:56:24)
> [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from proteus import config, Model, Wizard
> >>> def set_config(database, user, config_file=None):
> ... return config.set_trytond(database, user, config_file=config_file)
> ...
> >>> config = set_config(u't44_4', u'admin', '/Users/jcm/Sites/_tryton/tryton4.4/my_local_trytond.conf')
> >>> Party = Model.get('party.party')
> >>> party1, = Party.create([{
> ... 'name': 'Party 1',
> ... }])
> Traceback (most recent call last):
> File "<stdin>", line 2, in <module>
> File "/Users/jcm/Sites/_tryton/tryton4.4/proteus/proteus/config.py", line 169, in __call__
> rpc.convert(self._object, *args)
> File "/Users/jcm/Sites/_tryton/tryton4.4/trytond/trytond/rpc.py", line 36, in convert
> for key in context.keys():
> AttributeError: 'list' object has no attribute ‘keys'

You can call methods using proteus but then you need to pass as last
parameter the context.
But it is not the way proteus is supposed to be used, you are supposed
to instantiate Models and call .save()

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

lists.j...@symetrie.com

unread,
Jul 18, 2017, 3:33:39 AM7/18/17
to try...@googlegroups.com
Hi,


Le 18 juil. 2017 à 09:29, Cédric Krier <cedric...@b2ck.com> a écrit :
> But it is not the way proteus is supposed to be used, you are supposed
> to instantiate Models and call .save()

Thanks for your answers.

Jean-Christophe Michel

Reply all
Reply to author
Forward
0 new messages