After some django experience I tried to learn web2py. My impressions
and issues:
I cannot understand why you should write:
Field('customer', db.partner, requires=IS_IN_DB(db,
'partner.id','partner.id'))
and not just simply
Field('customer')
and on the other hand how a validator defines the appearance of a db
form? Not seems to be good design...
Also the api doc of IS_IN_DB isn't much helpful:
http://www.web2py.com/examples/static/epydoc/web2py.gluon.validators.IS_IN_DB-class.html
Generally, the documentation seems not so complete, as in django.
ps: if I find errors in comparing django and web2py, where should I
report it?
I dig up some info for IS_IN_SET, it accepts dicts, but it is not
mentioned on the site:
http://www.web2py.com/examples/static/epydoc/web2py.gluon.validators.IS_IN_SET-class.html
http://www.web2py.com/examples/global/vars/IS_IN_SET
Using an autoincrement integer called id in every db is a good
practice, but it is impossible to follow legacy databases.
For definition of a legacy database:
Suppose you have some system with existing database, and you should
create a web-based interface for that.
So, you cannot alter the tables in the legacy database (not
considering oracle, where AFAIK you should insert a sequence number
manually, so an alter table is not sufficient).
So, for this case it should be good to have arbitrary (and also multi-
field) PK support.
thanks
Gergo
Thank you very much for your email. Your prospective as a Django user
is very valuable here.
On Jan 1, 9:48 am, pihentagy <pihent...@gmail.com> wrote:
> Hi all!
>
> After some django experience I tried to learn web2py. My impressions
> and issues:
>
> I cannot understand why you should write:
> Field('customer', db.partner, requires=IS_IN_DB(db,
> 'partner.id','partner.id'))
>
> and not just simply
> Field('customer')
The sytnax is Field(name, type). The default type is a string. If you
want it to be a reference it has to said explicitly. You do the same
in Django. The validator is optional and, in fact, since 1.74 you get
that validator by default if web2py knows how to represent a partner.
For example
db.define_table('partner',Field('name'),format='%(names)s')
db.define_table('whatever',Field('partner',db.partner))
db.whatever.partner.requires is set by default to IS_IN_DB
(db,'partner.id','%(name)s')
> and on the other hand how a validator defines the appearance of a db
> form? Not seems to be good design...
>
> Also the api doc of IS_IN_DB isn't much helpful:http://www.web2py.com/examples/static/epydoc/web2py.gluon.validators....
>
> Generally, the documentation seems not so complete, as in django.
>
> ps: if I find errors in comparing django and web2py, where should I
> report it?
You can email it here so we can discuss it.
> I dig up some info for IS_IN_SET, it accepts dicts, but it is not
> mentioned on the site:http://www.web2py.com/examples/static/epydoc/web2py.gluon.validators....http://www.web2py.com/examples/global/vars/IS_IN_SET
>
> Using an autoincrement integer called id in every db is a good
> practice, but it is impossible to follow legacy databases.
> For definition of a legacy database:
> Suppose you have some system with existing database, and you should
> create a web-based interface for that.
> So, you cannot alter the tables in the legacy database (not
> considering oracle, where AFAIK you should insert a sequence number
> manually, so an alter table is not sufficient).
>
> So, for this case it should be good to have arbitrary (and also multi-
> field) PK support.
We actually support this for some databases but not all. You can find
some info here:
http://groups.google.com/group/web2py/browse_thread/thread/2b877c0b79c1af40
We are in the process of re-factoring the DAL so that it will remain
backward compatible and this issue will eventually be addressed for
all databases.
> thanks
> Gergo
On Jan 1, 6:34 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> On Jan 1, 9:48 am, pihentagy <pihent...@gmail.com> wrote:
> > I cannot understand why you should write:
> > Field('customer', db.partner, requires=IS_IN_DB(db,
> > 'partner.id','partner.id'))
>
> > and not just simply
> > Field('customer')
> The sytnax is Field(name, type). The default type is a string. If you
> want it to be a reference it has to said explicitly. You do the same
> in Django. The validator is optional and, in fact, since 1.74 you get
> that validator by default if web2py knows how to represent a partner.
> For example
>
> db.define_table('partner',Field('name'),format='%(names)s')
> db.define_table('whatever',Field('partner',db.partner))
>
> db.whatever.partner.requires is set by default to IS_IN_DB
> (db,'partner.id','%(name)s')
thanks.
Where can I find info about the exact syntax of Field (and in general
a complete up2date APIdoc?)
> > ps: if I find errors in comparing django and web2py, where should I
> > report it?
>
> You can email it here so we can discuss it.
No model validation in django (yet) (v1.1)
Django has ModelForms which is similar to SQLFORM.
>
> > I dig up some info for IS_IN_SET, it accepts dicts, but it is not
> > mentioned on the site:http://www.web2py.com/examples/static/epydoc/web2py.gluon.validators....
>
> > Using an autoincrement integer called id in every db is a good
> > practice, but it is impossible to follow legacy databases.
> > For definition of a legacy database:
> > Suppose you have some system with existing database, and you should
> > create a web-based interface for that.
> > So, you cannot alter the tables in the legacy database (not
> > considering oracle, where AFAIK you should insert a sequence number
> > manually, so an alter table is not sufficient).
>
> > So, for this case it should be good to have arbitrary (and also multi-
> > field) PK support.
>
> We actually support this for some databases but not all. You can find
> some info here:http://groups.google.com/group/web2py/browse_thread/thread/2b877c0b79...
>
> We are in the process of re-factoring the DAL so that it will remain
> backward compatible and this issue will eventually be addressed for
> all databases.
Nice, but can I find complete api doc somewhere? I still miss how the
format keyword argument works for define_table.
thanks
http://web2py.com/examples/static/epydoc/index.html
Yes, looking for something like that.
BUT
This doc is not complete. I could not find, that even there is a
keyword arg 'format' for define_table.
See
http://127.0.0.1:8000/examples/static/epydoc/web2py.gluon.dal.SQLDB-class.html
(This section of the site is down now - 503)
And sorry to say, that a framework could be superb, but if you cannot
solve problems yourself with the help of doc, it scares people away,
regardless of how kindly you are. Constantly asking in the mailing
list and waiting for hours would be unacceptable, if I would use this
tool for real business.
Gergo
Hm so getting referential integrity only when the system can _display_
some type of record? Again, I see a problem here: validator should
really care about validity, and representation should be another
thing.
And if we are representation: if web2py renders a mandatory FK as a
combobox, there is no dummy 'please select one' option.
The first valid option is selected by default. This causes serious
usability issues, because users will not pay any attention to select a
valid option, because there is something, and it validates.
Gergo
On Jan 2, 4:27 am, pihentagy <pihent...@gmail.com> wrote:
> On Jan 2, 12:04 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > I think this is what you looking for.
>
> >http://web2py.com/examples/static/epydoc/index.html
>
> Yes, looking for something like that.
>
> BUT
>
> This doc is not complete. I could not find, that even there is a
> keyword arg 'format' for define_table.
>
> Seehttp://127.0.0.1:8000/examples/static/epydoc/web2py.gluon.dal.SQLDB-c...
On Jan 2, 4:47 am, pihentagy <pihent...@gmail.com> wrote:
> On Jan 1, 6:34 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > On Jan 1, 9:48 am, pihentagy <pihent...@gmail.com> wrote:
> > The sytnax is Field(name, type). The default type is a string. If you
> > want it to be a reference it has to said explicitly. You do the same
> > in Django. The validator is optional and, in fact, since 1.74 you get
> > that validator by default if web2py knows how to represent a partner.
> > For example
>
> > db.define_table('partner',Field('name'),format='%(names)s')
> > db.define_table('whatever',Field('partner',db.partner))
>
> Hm so getting referential integrity only when the system can _display_
> some type of record? Again, I see a problem here: validator should
> really care about validity, and representation should be another
> thing.
I am not sure I understand. Field('partner',db.partner) defined a
reference field. The reference is always implemented using the Primary
Key (the ID field) and this has nothing to do with representation. The
format string is used only when building a representation of the
reference in forms. What you see (%(name)s) is not the key and is not
what is stores in the database for whatever.partner.
> And if we are representation: if web2py renders a mandatory FK as a
> combobox, there is no dummy 'please select one' option.
> The first valid option is selected by default. This causes serious
> usability issues, because users will not pay any attention to select a
> valid option, because there is something, and it validates.
Please never assume that something that is not done by default cannot
be done.
db.whatever.partner.requires.zero="Please Select One"
>
> Gergo
Ah, maybe the fact, that I use sqlite for testing purposes can explain things.
So, if I say:
db.define_table('whatever',Field('partner',db.partner))
than, using the appadmin, I can create a record with arbitrary partner
id (because no selectbox for FK selection). And since sqlite does not
handle referential integrity, it can save it fine.
>> And if we are representation: if web2py renders a mandatory FK as a
>> combobox, there is no dummy 'please select one' option.
>> The first valid option is selected by default. This causes serious
>> usability issues, because users will not pay any attention to select a
>> valid option, because there is something, and it validates.
>
> Please never assume that something that is not done by default cannot
> be done.
>
> db.whatever.partner.requires.zero="Please Select One"
Ah, thanks. (IMHO that shold be default in the appadmin).
Another feature, that django's admin knows and quite useful: where you
can select an FK, there is a link for creating that type of object
(displays in a popup). So, when you could not find the desired value
in the selectbox, you can create a new option.
> nother feature, that django's admin knows and quite useful: where you
> can select an FK, there is a link for creating that type of object
> (displays in a popup). So, when you could not find the desired value
> in the selectbox, you can create a new option.
We should have something like this. It can be done easily with a
widget but appadmin should have something like that by default.
Again, where can I find info about the zero argument?
It is mentioned at
http://www.web2py.com/examples/static/epydoc/web2py.gluon.validators.IS_IN_DB-class.html
__init__(self, dbset, field, label=None, error_message='value not in
database', orderby=None, cache=None, multiple=False, zero=None)
and nothing about the arguments :(
but searching for requires zero on the site cannot give me extra info.
see: http://www.google.hu/search?q=%2Brequires+%2Bzero+site%3Aweb2py.com
IMHO: Something, that is not documented, does not exist.
Gergo
I also agree that zero!=None should be default. I can change it.
Anybody against?
Massimo
On Jan 2, 4:28 pm, "KONTRA, Gergely" <pihent...@gmail.com> wrote:
> > Please never assume that something that is not done by default cannot
> > be done.
>
> > db.whatever.partner.requires.zero="Please Select One"
>
> Again, where can I find info about the zero argument?
>
> It is mentioned athttp://www.web2py.com/examples/static/epydoc/web2py.gluon.validators....
On Jan 2, 4:28 pm, "KONTRA, Gergely" <pihent...@gmail.com> wrote:
> > Please never assume that something that is not done by default cannot
> > be done.
>
> > db.whatever.partner.requires.zero="Please Select One"
>
> Again, where can I find info about the zero argument?
>
> It is mentioned athttp://www.web2py.com/examples/static/epydoc/web2py.gluon.validators....
Good luck!
On Jan 2, 2:28 pm, "KONTRA, Gergely" <pihent...@gmail.com> wrote:
> > Please never assume that something that is not done by default cannot
> > be done.
>
> > db.whatever.partner.requires.zero="Please Select One"
>
> Again, where can I find info about the zero argument?
>
> It is mentioned athttp://www.web2py.com/examples/static/epydoc/web2py.gluon.validators....
Gergo