Re: [web2py] Re: Number of records
Why can' t you use the already pre-defined id field? You don't need to define a new one, every table already has and and id field with name id. Fabiano. On Sat, Jan 15, 2011 at 6:37 AM, Rick sababa.sab...@gmail.com wrote: So the problem was that the controller file line creates an error when I add the 'id' field and 'migrate=False' to the day table. Here is some more code: ===in the model file=== import datetime now = datetime.date.today() db.define_table('day', Field('the_id', 'id'), Field('thedate','date', default=request.now), Field('value', 'integer'), migrate=False) ===in the controller file=== records = db().select(db.day.ALL, orderby=db.day.thedate) On Jan 15, 8:16 am, Kenneth Lundström kenneth.t.lundst...@gmail.com wrote: Could you shows us the relevant part of your models file, where the table is defined and then also the error ticket. Kenneth Thanks for the suggestion! The 'id' field looks like a smart solution. But there seem to be a problem -- This line creates an error when I add the 'id' field and 'migrate=False' to the day table: records = db().select(db.day.ALL, orderby=db.day.thedate) Any ideas? On Jan 4, 4:03 am, Fabianofabianoeng...@gmail.com wrote: What stops you from using 'id' field?
Re: [web2py] Re: IS_IN_DB() argument
On Tue, Jan 4, 2011 at 9:45 AM, mdipierro mdipie...@cs.depaul.edu wrote: ok, in trunk. Wow, don't you sleep? =) As I am using and learning web2py, I've been reading its source-code to understand the magic under the hood and to make a better use of it. I am not confident yet to write my own patches, but I hope I can start to contribute with something soon. Fabiano. On Tue, Jan 4, 2011 at 9:45 AM, mdipierro mdipie...@cs.depaul.edu wrote: ok, in trunk. On Jan 3, 8:34 pm, Fabiano fabianoeng...@gmail.com wrote: Ok. By the way, If I may suggest, it would be a nice feature, and backward compatible. As the id is an implied column and you must specify it explicit when making references, I think it it would be even more consistent to specify a table, the id would be implicit in both cases. Regards, On Monday, January 3, 2011 11:23:46 PM UTC-2, mdipierro wrote: The error is in the example. IS_IN_DB *never* accepted a table as second argument. Sorry for the confusion. Will fix the example. Massimo On Jan 3, 6:25 pm, Fabiano - deStilaDo fabian...@gmail.com wrote: Hi, from validators.py: 342 class IS_IN_DB(Validator): 343 344 example:: 345 346 INPUT(_type='text', _name='name', 347 requires=IS_IN_DB(db, db.table, zero='')) 348 349 used for reference fields, rendered as a dropbox 350 But I can't use the documented syntax: IS_IN_DB(db, db.table). I had to use explicit db.table.id as argument. It looks like the current code (1.91.6) does not accept a table as argument. Apparently, it cannot figure out that when you specify a table instead of a field it should use the table's id field. It relies on the field representation as string to extract the field name, splitting it by dots, as shows line 371 from the class' constructor: 370 self.field = field 371 (ktable, kfield) = str(self.field).split('.') Wouldn't be better to test the argument with something like isinstance() first? Sorry if I misunderstood something, but I think that if this is not a bug, then the documentation should be updated. I also didn't check the code for IS_NOT_IN_DB(), but I guess this class may have the same issue. Regards, Fabiano.
[web2py] Temporary changing default values of a Form
Hi, I have a default value for a field defined on the table definition, along with its validators. I want to create a form with a different initial value for some fields, based on the link the user clicked. Something like add new item for this category and the new item form come with that category pre-filled. The way I found to do this was: form = SQLFORM(db.mytable) form.custom.widget['myfield']['value'] = request.args(0) form.custom.widget['myfield']._postprocessing() the _postprocessing() call was necessary in case of multiple options widget (like Selects), else the selected option wouldn't be updated. It works fine, but I believe I am messing with the inners of the object, a bad programming practice, as the internal implementation may change and break my app. Is there a proper way of doing this? Kind regards, Fabiano.
[web2py] IS_IN_DB() argument
Hi, from validators.py: 342 class IS_IN_DB(Validator): 343 344 example:: 345 346 INPUT(_type='text', _name='name', 347 requires=IS_IN_DB(db, db.table, zero='')) 348 349 used for reference fields, rendered as a dropbox 350 But I can't use the documented syntax: IS_IN_DB(db, db.table). I had to use explicit db.table.id as argument. It looks like the current code (1.91.6) does not accept a table as argument. Apparently, it cannot figure out that when you specify a table instead of a field it should use the table's id field. It relies on the field representation as string to extract the field name, splitting it by dots, as shows line 371 from the class' constructor: 370 self.field = field 371 (ktable, kfield) = str(self.field).split('.') Wouldn't be better to test the argument with something like isinstance() first? Sorry if I misunderstood something, but I think that if this is not a bug, then the documentation should be updated. I also didn't check the code for IS_NOT_IN_DB(), but I guess this class may have the same issue. Regards, Fabiano.