[web2py] Re: math Division in web2py

2012-02-21 Thread Brian Will
This is actually just a Python quirk: In Python 2.x, the / operator always returns an integer when both operands are integers, e.g. (5 / 2) returns 2, not 2.5. The solution is to simply make one or both operands a float: percent = float(x) / y * 100 # x/y as a percentage If you want your perc

[web2py] cached values from background tasks

2012-02-21 Thread Brian Will
In parts of my app, some needed values take a long time to generate, so I'm farming the generation of these values out to Scheduled tasks and designing with the expectation that some values just won't be ready to include in a page. When ready, the generated values are then incorporated into the pag

[web2py] Re: the Set class should be deprecated

2011-12-16 Thread Brian Will
Last argument, I promise. Here's my version of your summary: 1. We have a connection object that represents a database. 2. From the Fields associated with this connection, Queries are produced with Field's overloaded operators. Queries can also be produced from combination of other Queries with

[web2py] Re: the Set class should be deprecated

2011-12-16 Thread Brian Will
Apologies for dragging this out. I don't mean to be combative, but... @pbreit It's weird if you're told OR if you think about it (especially if you aren't already very fluent in Python). If no one tells you, and if you don't think about it, it's probably fine. Also, the query already encapsulates

[web2py] Re: the Set class should be deprecated

2011-12-16 Thread Brian Will
@pbreit > Can't you just explain to people that this is how you query the db: > >       rows = db(db.item.id==1).select() > > How much is gained by dropping the "db"? Programming is all about taking comprehensible pieces and piecing them together for your own purposes. A rote formula of syntax tha

[web2py] Re: the Set class should be deprecated

2011-12-15 Thread Brian Will
Something like: (db.mytable.id == 3).ignore_common_filters().select() Or: (db.mytable.id == 3).select(ignore_common_filters=True) 'One way of doing it' is an argument for fixing it and officially deprecating the old way. I'd sympathize with the objections more if it meant actual legac

[web2py] Re: the Set class should be deprecated

2011-12-15 Thread Brian Will
@Massimo So I'm not crazy, at least. Perhaps you can just add the Query and Table methods, leaving Set "deprecated" but never removed. Isn't this the current policy anyway? New learners would have a more sensical API while existing users could stick with what they know. Learnability is one of web2p

[web2py] the Set class should be deprecated

2011-12-14 Thread Brian Will
The problem is that Set is superfluous, oddly named, and thereby makes the whole DAL confusing to learners. I experienced this confusion myself when learning web2py, and now I find it's a problem when teaching web2py to others. A Query is not, as some web2py docs claim, just a WHERE clause. It sup

[web2py] cache block of content in template rather than codebehind

2011-05-25 Thread Brian Will
I'd like to use cache.ram with some chunks of content in my templates, and I'd rather not have to translate the chunks into the helper equivalents, e.g. to DIV(). Is there something like {{cacheblock}}stuff{{end}}? Should there be?

[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Brian Will
Done. Thanks Massimo, and for all your hard work. On Apr 14, 7:29 am, Massimo Di Pierro wrote: > Please open an issue in google code and I will fix this asap. > > On Apr 14, 8:56 am, Brian Will wrote: > > > > > > > > > No, form.vars and request.vars bo

[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Brian Will
rors.terms = 'You must agree to the terms.' > > must be > > def validateTerms(form): >             if request.vars.terms != 'agree': >                 form.errors.terms = 'You must agree to the terms.' > > as the request.vars has not yet been co

[web2py] form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Brian Will
I'm trying to add a checkbox that must be ticked to an update SQLFORM, but I'm getting an internal error. Here's the create form that works fine with an added checkbox: form = SQLFORM(db.job_post, submit_button='Post Job', formstyle='table2cols', fields=['poster_name', 'poster_email'

[web2py] Re: 'check exists' option for reseting password

2011-04-11 Thread Brian Will
That seems to do it. On Apr 11, 1:42 am, Brian Will wrote: > I'd rather my password reset form not check the db for the existence > of the email and just blindly give an 'an email has been sent' message > regardless of what email address is entered. > > In Auth.

[web2py] 'check exists' option for reseting password

2011-04-11 Thread Brian Will
I'd rather my password reset form not check the db for the existence of the email and just blindly give an 'an email has been sent' message regardless of what email address is entered. In Auth.request_reset_password(), this should require simply making the second validator conditional upon an opti

[web2py] Re: passing data as post params rather than URL vars/args

2011-04-05 Thread Brian Will
our data available even after a > redirect. POST won't have that, so you should either store it on the > session, with cookies or with the database. If it's just temporary I > would suggest using session variables. > > Regards, > Arbie > > On Apr 5, 3:38 pm, Bria

[web2py] Re: passing data as post params rather than URL vars/args

2011-04-05 Thread Brian Will
odd. So I guess my question is: I want some way to redirect to another action in the app and pass it data, but I don't want to pass it as URL vars/args. On Apr 5, 12:38 am, Brian Will wrote: > I assumed there would simply be a Storage in the response object I > could just stuff thing

[web2py] passing data as post params rather than URL vars/args

2011-04-05 Thread Brian Will
I assumed there would simply be a Storage in the response object I could just stuff things into, but it seems not. So my question is what's the easiest way to append POST data to a response (for both cases: a redirect and a non-redirect)? Maybe I'm going about this the wrong way. I have a simple '

[web2py] Re: import csv not respecting unique?

2011-03-28 Thread Brian Will
Just tried it with Postgres and now import_from_csv_file() is throwing an exception with message "duplicate key value violates unique constraint "region_subdomain_key", so I guess this is a sqlite specific thing. On Mar 28, 5:33 pm, Brian Will wrote: > I should also make clea

[web2py] Re: import csv not respecting unique?

2011-03-28 Thread Brian Will
I should also make clear that I'm talking about db.export_to_csv_file() and db.import_from_csv_file() On Mar 28, 5:27 pm, Brian Will wrote: > I should add that I'm seeing this with SQLite. Haven't tried it with > Postgres yet. > > On Mar 28, 5:25 pm, Brian Will wrot

[web2py] Re: import csv not respecting unique?

2011-03-28 Thread Brian Will
I should add that I'm seeing this with SQLite. Haven't tried it with Postgres yet. On Mar 28, 5:25 pm, Brian Will wrote: > I have this table: > > db.define_table('region', >     Field('name'), >     Field('longname'), >     Field(&#

[web2py] import csv not respecting unique?

2011-03-28 Thread Brian Will
I have this table: db.define_table('region', Field('name'), Field('longname'), Field('subdomain', unique=True), Field('status_', 'reference region_status') ) The unique constraint is preventing me in the appadmin from adding regions with the same subdomain, as intended. However, i

[web2py] Re: add single pseudo-field to SQLFORM

2011-03-27 Thread Brian Will
be deprecate 'value' in favor of 'prechecked' for this purpose to avoid the confusion. On Mar 27, 2:28 pm, Brian Will wrote: > Thanks, everyone. That's what I was looking for. > > On Mar 27, 9:50 am, villas wrote: > > > > > > > > > Thanks

[web2py] Re: add single pseudo-field to SQLFORM

2011-03-27 Thread Brian Will
of the checkbox, > > which you probably would check using onvalidation. > > > Where do I collect my bonus points? ;) > > > On Mar 27, 6:43 am, Brian Will wrote: > > > > I have an insert SQLFORM of 8 fields, to which I'd like to add a > > > s

[web2py] add single pseudo-field to SQLFORM

2011-03-27 Thread Brian Will
I have an insert SQLFORM of 8 fields, to which I'd like to add a single "I agree to terms" checkbox at the bottom. There are probably tons of ways to do this, but I'm hoping someone has a really simple method that doesn't require resorting to a manual FORM? Can I simply tack on another INPUT to the

[web2py] Re: getting fields created by SQLFORM but which are not in the form

2011-03-26 Thread Brian Will
n=get_uuid): vars['poster_name'] = form.vars.poster_name vars['poster_email'] = form.vars.poster_email redirect(URL('post_email', vars=vars)) On Mar 26, 6:01 pm, Brian Will wrote: > Thanks, that's a start, but how now do I get 'uuid&

[web2py] Re: getting fields created by SQLFORM but which are not in the form

2011-03-26 Thread Brian Will
esL wrote: > The new record id will be in form.vars.id after the accepts. > > On Mar 26, 7:46 pm, Brian Will wrote: > > > > > > > > > When using SQLFORM, I'd like to get the default/computed values of > > fields not included in the form. Can

[web2py] getting fields created by SQLFORM but which are not in the form

2011-03-26 Thread Brian Will
When using SQLFORM, I'd like to get the default/computed values of fields not included in the form. Can I do this without making another query? Can I get, say, the autogen'd id of the new record? For example: form = SQLFORM(db.job_post, submit_button='Post Job', formstyle='table2cols', fie

[web2py] Ubuntu 10.10 install fix

2011-03-08 Thread Brian Will
After running http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh on ubuntu 10.10 and setting up a postgres db for an app, I was getting "global name 'psycopg2' is not defined". Fixed it with: apt-get install python-psycopg2 sudo /etc/init.d/apache2 restart For 10.10, the line