address model

15 views
Skip to first unread message

cristi

unread,
Jan 14, 2009, 5:26:04 PM1/14/09
to Tryton
I started to look over address.py in order to understand how models
are build so:

1) is there a way to find out exactly one method of a class where is
used (it's references in the whole project). As an example where is
used name_get from address.py or name_search ,or get_full_address ?

2)I tried to use print for debug (i know is not professional but for
learning purpose is ok)
and i noticed a strange behaviour
i put a print "step1" in write function of the address.py.
then i started the server,started the client,upgraded the party module
and created a new address but
on the server console i did not noticed anything,second time when i
added a new item i saw the "step1"
very easy to reproduce ,have any ideea why ?

3)i noticed this twice in address.py
if isinstance(ids, (int, long)):
ids = [ids]

what this means ?

Regards Cristian.

cristi

unread,
Jan 15, 2009, 2:52:57 AM1/15/09
to Tryton

3)i noticed this twice in address.py
if isinstance(ids, (int, long)):
ids = [ids]


what this means and why is used this?

Carlos Perelló Marín

unread,
Jan 15, 2009, 3:12:14 AM1/15/09
to try...@googlegroups.com
El mié, 14-01-2009 a las 23:52 -0800, cristi escribió:
>

Hi,

> 3)i noticed this twice in address.py
> if isinstance(ids, (int, long)):
> ids = [ids]
>
>
> what this means and why is used this?

It checks whether ids type is int or long, and if that's the case, it
converts it in a list containing such int or long value.

I guess it's used because ids is supposed to be a list of integers, but
in that case, the system only got a single integer.

Cheers.

>
>
>
> On 15 Ian, 00:26, cristi <cristian.chiov...@gmail.com> wrote:
> > I started to look over address.py in order to understand how models
> > are build so:
> >
> > 1) is there a way to find out exactly one method of a class where is
> > used (it's references in the whole project). As an example where is
> > used name_get from address.py or name_search ,or get_full_address ?
> >
> > 2)I tried to use print for debug (i know is not professional but for
> > learning purpose is ok)
> > and i noticed a strange behaviour
> > i put a print "step1" in write function of the address.py.
> > then i started the server,started the client,upgraded the party module
> > and created a new address but
> > on the server console i did not noticed anything,second time when i
> > added a new item i saw the "step1"
> > very easy to reproduce ,have any ideea why ?
> >
> > 3)i noticed this twice in address.py
> > if isinstance(ids, (int, long)):
> > ids = [ids]
> >
> > what this means ?
> >
> > Regards Cristian.
>
--
Carlos Perelló Marín
[P+] SERVICIOS PROFESIONALES
http://www.pemas.es
mailto:car...@pemas.es || mailto:car...@gnome.org

Cédric Krier

unread,
Jan 15, 2009, 5:42:57 AM1/15/09
to try...@googlegroups.com
On 14/01/09 14:26 -0800, cristi wrote:
>
> I started to look over address.py in order to understand how models
> are build so:
>
> 1) is there a way to find out exactly one method of a class where is
> used (it's references in the whole project). As an example where is
> used name_get from address.py or name_search ,or get_full_address ?

Not from tryton. But you can use grep [1] or ack [2]

>
> 2)I tried to use print for debug (i know is not professional but for
> learning purpose is ok)

I use that for debug also and it is professional and even faster then
any debuger :-)

> and i noticed a strange behaviour
> i put a print "step1" in write function of the address.py.
> then i started the server,started the client,upgraded the party module
> and created a new address but
> on the server console i did not noticed anything,second time when i
> added a new item i saw the "step1"
> very easy to reproduce ,have any ideea why ?

You must save the party to have the addresses saved.


[1] http://unixhelp.ed.ac.uk/CGI/man-cgi?grep
[2] http://petdance.com/ack/


--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email: cedric...@b2ck.com
Jabber: cedric...@b2ck.com
Website: http://www.b2ck.com/

cristi

unread,
Jan 15, 2009, 5:56:27 AM1/15/09
to Tryton

1) Why that is not possible from tryton ?
grep and ack how good are for this purpose.


2) I spoke with Carlos and he told me that is not good to use print
since there are some buffers
and the print is not show imeddiately only when the buffers are empty
and for emptying them some specila coding is needed.
He recommended to me to use import pdb and pdb.set_trace() then i get
the console.

3) ids may be something like [1,2,3,4,5,6] ? or it may be simple 1 so
it is converted to [1]
Now why this is not handled before calling the method ?
How come is possible to get only a number and not a list ?

That is why i would like to knwo where methods are used to be able to
identify such things.

THX
> Email: cedric.kr...@b2ck.com
> Jabber: cedric.kr...@b2ck.com
> Website:http://www.b2ck.com/
>
>  application_pgp-signature_part
> < 1 KVedeţiDescărcaţi

Cédric Krier

unread,
Jan 15, 2009, 6:04:32 AM1/15/09
to try...@googlegroups.com
On 15/01/09 02:56 -0800, cristi wrote:
>
>
> 1) Why that is not possible from tryton ?
> grep and ack how good are for this purpose.
>

Because it is not the purpose of the application.

>
> 2) I spoke with Carlos and he told me that is not good to use print
> since there are some buffers
> and the print is not show imeddiately only when the buffers are empty
> and for emptying them some specila coding is needed.
> He recommended to me to use import pdb and pdb.set_trace() then i get
> the console.

I never had any issue to use print statement.

>
> 3) ids may be something like [1,2,3,4,5,6] ? or it may be simple 1 so
> it is converted to [1]
> Now why this is not handled before calling the method ?

Because anybody can call this function.

> How come is possible to get only a number and not a list ?

This make it more generic.


--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59

cristi

unread,
Jan 15, 2009, 6:20:07 AM1/15/09
to Tryton
Oki thx...

2,3) clear

1) repeat "is there a way to find out exactly one method of a class
where is
used (it's references in the whole project). As an example where is
used name_get from address.py or name_search ,or get_full_address ?
"

you told finally "Because it is not the purpose of the application."

i know the purpose of the application ,it's an erp :)

what i asked is on 1) has nothing to do with the purpose of the
application.

it would be very very useful for me to be able to find a mehtod where
is used


THX

Cédric Krier

unread,
Jan 15, 2009, 6:26:10 AM1/15/09
to try...@googlegroups.com
On 15/01/09 03:20 -0800, cristi wrote:
>
> Oki thx...
>
> 2,3) clear
>
> 1) repeat "is there a way to find out exactly one method of a class
> where is
> used (it's references in the whole project). As an example where is
> used name_get from address.py or name_search ,or get_full_address ?
> "
>
> you told finally "Because it is not the purpose of the application."
>
> i know the purpose of the application ,it's an erp :)
>
> what i asked is on 1) has nothing to do with the purpose of the
> application.
>
> it would be very very useful for me to be able to find a mehtod where
> is used
>

But you can not. There is some tools to search for the function string
in the code like grep, ack.

--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59

Carlos Perelló Marín

unread,
Jan 15, 2009, 6:29:01 AM1/15/09
to try...@googlegroups.com
El jue, 15-01-2009 a las 03:20 -0800, cristi escribió:
> Oki thx...
>
> 2,3) clear
>
> 1) repeat "is there a way to find out exactly one method of a class
> where is
> used (it's references in the whole project). As an example where is
> used name_get from address.py or name_search ,or get_full_address ?
> "
>
> you told finally "Because it is not the purpose of the application."
>
> i know the purpose of the application ,it's an erp :)
>
> what i asked is on 1) has nothing to do with the purpose of the
> application.
>
> it would be very very useful for me to be able to find a mehtod where
> is used

As I told you on IRC, what you look for is a functionality in your
development environment so you should check whatever you are using (vim,
emacs, eclipse, etc...) for the way to do cross code indexing. That
applies to any C/C++/Java/Python/etc... development you work with.

You can read more about vim + ctags at
http://jjinux.blogspot.com/2008/12/vim-ctags.html


Cheers.

cristi

unread,
Jan 15, 2009, 6:32:47 AM1/15/09
to Tryton
But how can you live without that ?

Especially when you do debug ....

Imagine you have a huge project...like trytond may be.

I take as example methe name_get this method may be an many other
classes defined so i search only for name_get i get a lot of false
alarms since i might be interested in name_get from address.py.

is this a python issue ?

Cris
> Email: cedric.kr...@b2ck.com
> Jabber: cedric.kr...@b2ck.com
> Website:http://www.b2ck.com/
>
>  application_pgp-signature_part
> < 1 KVedeţiDescărcaţi- Ascunde citatul -
>
> - Afişare text în citat -

cristi

unread,
Jan 15, 2009, 6:45:26 AM1/15/09
to Tryton
YESSSS Carlos

i did not doubt for a second that this is a functionality that is
related to my development environment.

it ;s crystal clear

but cedk said that this is not suported in tryton and i was surprised
or missundersood since i knew that is an issue that
is not related to a secific project it is more like a python issue.


On 15 Ian, 13:29, Carlos Perelló Marín <car...@pemas.es> wrote:
> El jue, 15-01-2009 a las 03:20 -0800, cristi escribió:
>
>
>
>
>
> > Oki thx...
>
> > 2,3) clear
>
> > 1) repeat "is there a way to find out exactly one method of a class
> > where is
> > used (it's references in the whole project). As an example where is
> > used name_get from address.py or name_search ,or get_full_address ?
> > "
>
> > you told finally "Because it is not the purpose of the application."
>
> > i know the purpose of the application ,it's an erp :)
>
> > what i asked is on 1) has nothing to do with the purpose of the
> > application.
>
> > it would be very very useful for me to be able to find a mehtod where
> > is used
>
> As I told you on IRC, what you look for is a functionality in your
> development environment so you should check whatever you are using (vim,
> emacs, eclipse, etc...) for the way to do cross code indexing. That
> applies to any C/C++/Java/Python/etc... development you work with.
>
> You can read more about vim + ctags athttp://jjinux.blogspot.com/2008/12/vim-ctags.html
> mailto:car...@pemas.es || mailto:car...@gnome.org- Ascunde citatul -
>
> - Afişare text în citat -- Ascunde citatul -

Carlos Perelló Marín

unread,
Jan 15, 2009, 6:58:40 AM1/15/09
to try...@googlegroups.com
El jue, 15-01-2009 a las 03:45 -0800, cristi escribió:
> YESSSS Carlos
>
> i did not doubt for a second that this is a functionality that is
> related to my development environment.
>
> it ;s crystal clear
>
> but cedk said that this is not suported in tryton and i was surprised
> or missundersood since i knew that is an issue that
> is not related to a secific project it is more like a python issue.

Dude, what cedk means with 'is not supported in tryton' is that you
cannot do such code browsing in Tryton itself. An application cannot
impose rules to the language it uses, so you can use that functionality
just like in other projects, but with the right tools.

Cheers.

cristi

unread,
Jan 15, 2009, 7:06:38 AM1/15/09
to Tryton
Thx dude ..

what i exepected from you was somethign this :

such code browsing is not possible in python (implied in tryton as
well) since this is the nature of python. (dynamic type)

so for such thing you neeed runtime in pythons.....

that was magic word missing from all this discussion and the confusion
that is not possible on tryton .


saying that is not possible on tryton does not mean is not possible on
python.

but saying is not possible on python mean is not possilbe on tryton :)

cristi

unread,
Jan 15, 2009, 9:04:40 AM1/15/09
to Tryton


def write(self, cursor, user, ids, vals,
context=None):
if 'party' in vals:
if isinstance(ids, (int, long)):
ids = [ids]
for address in self.browse(cursor, user, ids,
context=context):
if address.party.id != vals['party']:
self.raise_user_error(cursor, 'write_party',
context=context)
return super(Address, self).write(cursor, user, ids, vals,
context=context)



is necesarry to do the if isinstance(ids, (int, long)): ?

just to undersand better : in what use case ids=[ids] is executed as
and when not ?

when id is a int and when id is a list ?

from client what do i have to do to have secnario1 when id is an int

and what do i have to do to have the scenario2 when id is a list

Thx (also for patince)









Cédric Krier

unread,
Jan 15, 2009, 9:44:04 AM1/15/09
to try...@googlegroups.com
On 15/01/09 06:04 -0800, cristi wrote:
>
>
>
> def write(self, cursor, user, ids, vals,
> context=None):
> if 'party' in vals:
> if isinstance(ids, (int, long)):
> ids = [ids]
> for address in self.browse(cursor, user, ids,
> context=context):
> if address.party.id != vals['party']:
> self.raise_user_error(cursor, 'write_party',
> context=context)
> return super(Address, self).write(cursor, user, ids, vals,
> context=context)
>
>
>
> is necesarry to do the if isinstance(ids, (int, long)): ?

Yes, otherwise you can not loop on the browse because you will receive
only one BrowseRecord instead of BrowseRecordList

>
> just to undersand better : in what use case ids=[ids] is executed as
> and when not ?
>
> when id is a int and when id is a list ?
>
> from client what do i have to do to have secnario1 when id is an int
>
> and what do i have to do to have the scenario2 when id is a list
>

It is a coding guidelines, function that use ids must handle both case
single int or list of int.


--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59

cristi

unread,
Jan 15, 2009, 9:50:43 AM1/15/09
to Tryton
Ok i got it.

Now the final question i hope related to this issue:


when ids is a list in this particular case of write on address.py.

So what do i have to do in order to get a list of ids like [1,2,3,4] ?

where do i have to go in the client and what to do in order to have a
list not a single int
?

thx
> Email: cedric.kr...@b2ck.com
> Jabber: cedric.kr...@b2ck.com
> Website:http://www.b2ck.com/
>
>  application_pgp-signature_part
> < 1 KVedeţiDescărcaţi- Ascunde citatul -

Igor Támara

unread,
Jan 15, 2009, 10:45:16 AM1/15/09
to try...@googlegroups.com
Hi cristi, I guess is better you to read some more on grep ack and
vim+ctypes or emacs+ctypes to find it not just on this case but also
in following the code on many other future situations...

cristi>
cristi> Ok i got it.
cristi>
cristi> Now the final question i hope related to this issue:
cristi>
cristi>
cristi> when ids is a list in this particular case of write on address.py.
cristi>
cristi> So what do i have to do in order to get a list of ids like [1,2,3,4] ?
cristi>
cristi> where do i have to go in the client and what to do in order to have a
cristi> list not a single int
cristi> ?
cristi>
cristi> thx
cristi> On 15 Ian, 16:44, Cédric Krier <cedric.kr...@b2ck.com> wrote:
cristi> > On 15/01/09 06:04 -0800, cristi wrote:
cristi> >
cristi> >
cristi> >
cristi> >
cristi> >
cristi> >
cristi> >
cristi> > >   def write(self, cursor, user, ids, vals,
cristi> > > context=None):
cristi> > >         if 'party' in vals:
cristi> > >             if isinstance(ids, (int, long)):
cristi> > >                 ids = [ids]
cristi> > >             for address in self.browse(cursor, user, ids,
cristi> > > context=context):
cristi> > >                 if address.party.id != vals['party']:
cristi> > >                     self.raise_user_error(cursor, 'write_party',
cristi> > >                             context=context)
cristi> > >         return super(Address, self).write(cursor, user, ids, vals,
cristi> > >                 context=context)
cristi> >
cristi> > >  is necesarry to do the  if isinstance(ids, (int, long)): ?
cristi> >
cristi> > Yes, otherwise you can not loop on the browse because you will receive
cristi> > only one BrowseRecord instead of BrowseRecordList
cristi> >
cristi> >
cristi> >
cristi> > >  just to undersand better : in what use case ids=[ids] is executed as
cristi> > > and when not ?
cristi> >
cristi> > > when id is a int and when id is a list ?
cristi> >
cristi> > > from client what do i have to do to have secnario1 when id is an int
cristi> >
cristi> > > and what do i have to do to have the scenario2 when id is a list
cristi> >
cristi> > It is a coding guidelines, function that use ids must handle both case
cristi> > single int or list of int.
cristi> >
cristi> > --
cristi> > Cédric Krier
cristi> >
cristi> > B2CK SPRL
cristi> > Rue de Rotterdam, 4
cristi> > 4000 Liège
cristi> > Belgium
cristi> > Tel: +32 472 54 46 59
cristi> > Email: cedric.kr...@b2ck.com
cristi> > Jabber: cedric.kr...@b2ck.com
cristi> > Website:http://www.b2ck.com/
cristi> >
cristi> >  application_pgp-signature_part
cristi> > < 1 KVedeţiDescărcaţi- Ascunde citatul -
cristi> >
cristi> > - Afişare text în citat -
cristi> --~--~---------~--~----~------------~-------~--~----~
cristi> try...@googlegroups.com mailing list
cristi> -~----------~----~----~----~------~----~------~--~---
cristi>

--
Recomiendo Postgresql, el sistema manejador de bases de datos
http://www.postgresql.org

signature.asc

cristi

unread,
Jan 15, 2009, 11:24:44 AM1/15/09
to Tryton
Thx to debug i was able to figure it out this.
thx.
> cristi> > cristi>
>
> --
> Recomiendo Postgresql, el sistema manejador de bases de datoshttp://www.postgresql.org
>
>  signature.asc
> < 1KViewDownload

Udono

unread,
Jan 15, 2009, 12:18:44 PM1/15/09
to try...@googlegroups.com
Hey Cristi,

Am Donnerstag, den 15.01.2009, 06:50 -0800 schrieb cristi:
> when ids is a list in this particular case of write on address.py.
> So what do i have to do in order to get a list of ids like [1,2,3,4] ?

The check if ids is a list is to be sure that all other models
which (will possibly) inherit Address later are correct programmed.
The methods in party.address model always creating a list for ids,
even if there is only one value inside.
So its just to make the use of the class Address hardened against
programming mistakes in other modules. (Hope that's correct)

One power of Python is that variable typing is 'weak' and not strong:
http://www.artima.com/intv/strongweak.html

> where do i have to go in the client and what to do in order to have a
> list not a single int
> ?

In a list view for example you can select many records. When you click
on an action button, the ids of the selected records are 'transported'
in the 'ids' variable of the caller of the action method.

Cheers Udo

Cédric Krier

unread,
Jan 15, 2009, 11:43:28 AM1/15/09
to try...@googlegroups.com
On 15/01/09 18:18 +0100, Udono wrote:
>
> Hey Cristi,
>
> Am Donnerstag, den 15.01.2009, 06:50 -0800 schrieb cristi:
> > when ids is a list in this particular case of write on address.py.
> > So what do i have to do in order to get a list of ids like [1,2,3,4] ?
> The check if ids is a list is to be sure that all other models
> which (will possibly) inherit Address later are correct programmed.
> The methods in party.address model always creating a list for ids,
> even if there is only one value inside.
> So its just to make the use of the class Address hardened against
> programming mistakes in other modules. (Hope that's correct)
>

It is more a will to be more flexible.

--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59

Reply all
Reply to author
Forward
0 new messages