Re: [web2py] please help me test new form API

2011-08-14 Thread pbreit
I'm not totally clear on the gain here. Is it that flash messages get 
automatically set? Is this going to splinter implementations (ie some will 
use .accepts, some will use .process, others will use .validate)? Is that a 
good thing?


[web2py] new Reference.get (polymorphic with Row.get)

2011-08-14 Thread Carlos
Hi Massimo,

Can you please include the following in trunk for Reference?:

def get(self, key):
return self.__getattr__(key)

This way, Reference and Row both respond to the 'get' method, polymorphism.

I believe this does not break anything else.

Thanks,

   Carlos



[web2py] Re: MySQL query not reflecting actual state of db

2011-08-14 Thread G
What you say makes sense in cases where the databse is being modified
(update/insert/delete, etc). But in this case, the query in the loop
of side1() does not change the database state, it's simply looking for
a change in the database, so I wouldn't think it would require a
db.commit.

On Aug 14, 2:44 pm, Jay  wrote:
> This is required because you are using the DAL outside web2py
> framework,
>
> """
> from gluon import *
> import time
> db = DAL('mysql://web2py:web2p ...
> """
>
> When used like above, you have to call db.commit to complete the
> transaction.
>
> Normally all database insert/updates/deletes are committed at the end
> of each action by the framework.


[web2py] Re: Problem using MySQL with scheduler.py

2011-08-14 Thread G
Hi Massimo,
The new code you offered causes a compaint about bad MySQL syntax.

_mysql_exceptions.ProgrammingError: (1064, "You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near ';))' at line 1")

Changing update to _update, the SQL generated is:

UPDATE task_scheduled SET
status='running',assigned_worker_name='crabby#9d4d2ad8-0d56-4191-
b241-3894ef45a2c2',last_run_time='2011-08-15 00:27:25' WHERE
(task_scheduled.id = (SELECT  task_scheduled.id FROM task_scheduled
WHERE (task_scheduled.enabled = 'T') AND (task_scheduled.status =
'queued')) AND (task_scheduled.group_name IN ('status','main'))) AND
(task_scheduled.next_run_time < '2011-08-15 00:27:25')) AND
(((task_scheduled.assigned_worker_name = '') OR
(task_scheduled.assigned_worker_name IS NULL)) OR
(task_scheduled.assigned_worker_name = 'crabby#9d4d2ad8-0d56-4191-
b241-3894ef45a2c2'))) ORDER BY task_scheduled.next_run_time LIMIT 1
OFFSET 0;));

It looks like the raw command is producing a semicolon at the end.

However, I also tried running the same command directly with MySQL
Query Broswer except without the extra semicolon so the end was:
LIMIT 1 OFFSET 0));

This resulted in an error number 1093: "You can't specify target table
'task_scheduled' for update in FROM clause"

So it looks like this command also run's into a MySQL limitation...

G


On Aug 14, 10:49 pm, Massimo Di Pierro 
wrote:
> Can you help me test if replaceing this:
>
>         subselect = db(query)._select(
>             db.task_scheduled.id,limitby=(0,1),
>             orderby=db.task_scheduled.next_run_time)
>         db(db.task_scheduled.id.belongs(subselect)).update(
>             status=RUNNING,
>             assigned_worker_name=self.worker_name,
>             last_run_time=datetime.now)
>
> with this
>
>         from gluon.dal import raw
>         subselect = db(query)._select(
>             db.task_scheduled.id,limitby=(0,1),
>             orderby=db.task_scheduled.next_run_time)
>         db(db.task_scheduled.id == raw(subselect)).update(
>             status=RUNNING,
>             assigned_worker_name=self.worker_name,
>             last_run_time=datetime.now)
>
> works and fixed the problem with mysql?
>
> On Aug 13, 4:56 am, G  wrote:
>
> > Hello,
> > I just tried to use scheduler.py with MySQL instead of SQLite and ran
> > into this error:
>
> > NotSupportedError: (1235, "This version of MySQL doesn't yet support
> > 'LIMIT & IN/ALL/ANY/SOME subquery'")
>
> > The MySQL server version is 5.0.77. Searching on the web, it seems
> > this limitation is common. Is there a way to work around the issue?
> > The offending SQL looks like this:
>
> > UPDATE task_scheduled SET
> > status='running',assigned_worker_name='crabby#237cf3f0-89e7-4db5-
> > b514-56db27a700d5',last_run_time='2011-08-13 09:33:01' WHERE
> > (task_scheduled.id IN (SELECT  task_scheduled.id FROM task_scheduled
> > WHERE (task_scheduled.enabled = 'T') AND (task_scheduled.status =
> > 'queued')) AND (task_scheduled.group_name IN ('command','main'))) AND
> > (task_scheduled.next_run_time < '2011-08-13 09:33:01')) AND
> > (((task_scheduled.assigned_worker_name = '') OR
> > (task_scheduled.assigned_worker_name IS NULL)) OR
> > (task_scheduled.assigned_worker_name = 'crabby#237cf3f0-89e7-4db5-
> > b514-56db27a700d5'))) ORDER BY task_scheduled.next_run_time LIMIT 1
> > OFFSET 0));
>
> > I'm pretty sure this is coming from the massively complex query in
> > assign_next_task.
>
> > Thanks,
> > G
>
>


[web2py] Re: Virtual Fields. Strange behavior when saving db result sets Build in types

2011-08-14 Thread Michael Toomim
I don't have a direct solution, but FYI I added this info to a bug
report on a related topic. http://code.google.com/p/web2py/issues/detail?id=374

Thanks for pointing out the problem.

On Aug 14, 8:57 am, Santiago Gilabert 
wrote:
> anyone?
>
> I found that someone else asked about the same issue 5 month ago but there
> are no comments about it.
>
> http://groups.google.com/group/web2py/browse_thread/thread/845e6cdef5...
>
> Thanks
> Santiago
>
> On Sat, Aug 13, 2011 at 7:07 PM, Santiago wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > I have the following definitions in db.py
>
> > class ElectionVirtualField(object):
> >  ...
> >  def is_presidential(self):
> >    def lazy(self=self):
> >      return self.election.category == 'P'
> >    return lazy
> >  ...
>
> > db.define_table('election',
> >  ...
> >  Field('category', length=1, label=T('Category')
> >  ...
>
> > The problem I have is that when I add a bunch of elections in dict()
> > (key = election.id, value = election row) and then traverse the dict,
> > I get wrong values from is_presidential()
>
> > Example:
>
> >    elections = dict()
> >    for election in db(db.election).select():
> >       elections[election.id] = election
>
> >    for (k, v) in elections.items():
> >      print k , ' ', v.category, ' ', v.is_presidential()
>
> >    Output:
> >    81   D   True
> >    79   P   True
>
> > As you can see, it returns True for both, but for the first one, it
> > should return False.
>
> > If I change the code to reload the election from the database, the
> > output is different:
>
> > Example:
>
> >    elections = dict()
> >    for election in db(db.election).select():
> >       elections[election.id] = election
>
> >    for (k, v) in elections.items():
> >      reloaded_election = db.election(k)
> >      print k , ' ', v.category, ' ', v.is_presidential()
>
> >    Output:
>
> >    81   D   False
> >    79   P   True
>
> > Does this mean that we can't save rows from DB on Build in types ?
>
> > Thanks in advance,
> > Santiago


[web2py] can I turn off the auto back-references?

2011-08-14 Thread Carlos
Hi Massimo,

Is it possible to turn off back-references (reference fields from other 
tables back to my table as Set objects)?.

I need the following to work:

   myrow.get('fieldname', 'othervalue')

But if 'fieldname' happens to be the same as the tablename of one of such 
back-references, then it incorrectly returns a Set object (instead of 
'othervalue').

I know I can use something like [ if 'fieldname' in table.fields ] but I 
would rather have the convenience of the 'get' method.

Note that I do not really need these auto back-references.

Please let me know if it's doable to accomplish this with a switch or so 
(without breaking backward compatibility).

Thanks,

   Carlos



[web2py] Re: I keep getting the error: invalid literal for int() with base 10: 'Plumber'

2011-08-14 Thread Anthony
On Sunday, August 14, 2011 7:05:17 PM UTC-4, Jarrod Cugley wrote:
>
> Woohoo it's now working! Thank you Anthony!!!
>
> 2 questions:
>
> 1. When I have
>
> listing.title.requires = [IS_IN_DB(db, db.title.id, '%(name)s')]
>
> as a list (which is how I want it, it doesn't seem to let me register,
> it still expects an int, how can I make it expect a string that's
> equal to an id? Cause obviously people can't just guess the id of
> their title hahaha

If you want to enforce the requirement that titles are existing titles in 
the 'title' table, why not stick with the dropdown widget instead of 
allowing users to enter whatever title they want (which presumably will lead 
to more errors)? Another option may be the autocomplete widget (
http://web2py.com/book/default/chapter/07#Autocomplete-Widget), though it 
seems to have problems in IE (I hope to come up with a fix for that soon).
Otherwise, I suppose you could write a custom validator that takes the name, 
looks up the matching title.id, and changes the value to that id (or returns 
an error if not found). See 
http://web2py.com/book/default/chapter/07#Custom-Validators.

>
> 2. I'm running a little test on index to figure out how to display the
> first names that have the reference id '36' using this code:
>
> def index():
> painters = db(db.listing.title == 36).select()
> items = []
> for painter in painters:
> items.append(DIV(A(painter.first_name, _href=URL('index'
> return dict(items=items)
>
> But it's just displaying this on the index page:
>
> [,  0x9982b30>]

'items' is a list of HTML helpers, not a single HTML helper. If your view 
does {{=items}}, it won't serialize the separate DIV objects because they're 
part of a list. Instead, you'll need to unpack the list somehow. For 
example:
{{for item in items:}}
{{=item}}
{{pass}}
 
 

> P.S Are you the Anthony that was helping me on Stack Overflow too? If 
> so thanks, your help is awesome, hopefully I can pay it back one 
> day :) 

 
Yes, same Anthony. No problem, happy to help. Enjoy web2py. :-)
 
Anthony


Re: [web2py] please help me test new form API

2011-08-14 Thread Bruno Rocha
You can also do.

def action():
return dict(form=SQLFORM(db.table).process())

Or.

def action():
form = SQLFORM(...)
form.validate() # as shortcut to if form.accepts...
return dict(form=form)

http://zerp.ly/rochacbruno
Em 14/08/2011 19:14, "Massimo Di Pierro" 
escreveu:
> We used to do form.accepts(...), later Bruno added form.validate(...)
> and form.process(...). Now we extended this to work with both FORMs
> and SQLFORMs so instead of:
>
> form = SQLFORM(...)
> if form.accepts(request,session):
> # success
> elif form.errors:
> # failure
> else:
> # nothing happened
>
> now you can do
>
>
> form = SQLFORM(...).process()
> if form.accepted:
> # success
> elif form.errors:
> # failure
> else:
> # nothing happened
>
> process takes the same arguments as accepts but does not need to be
> passed request.vars and session. It also takes additional parameters:
> - onsuccess (lambda form: ...)
> - onfailure (lambda form:...)
> - message_onsuccess
> - message_onfailure
> - next (url to redirect in case of success)
>
> Give it a try. This may replace form.accepts(...) as my favorite API.
> It makes the code more compact.


[web2py] Re: I keep getting the error: invalid literal for int() with base 10: 'Plumber'

2011-08-14 Thread Jarrod Cugley
Woohoo it's now working! Thank you Anthony!!!

2 questions:

1. When I have

 listing.title.requires = [IS_IN_DB(db, db.title.id, '%(name)s')]

as a list (which is how I want it, it doesn't seem to let me register,
it still expects an int, how can I make it expect a string that's
equal to an id? Cause obviously people can't just guess the id of
their title hahaha


2. I'm running a little test on index to figure out how to display the
first names that have the reference id '36' using this code:

 def index():
painters = db(db.listing.title == 36).select()
items = []
for painter in painters:
items.append(DIV(A(painter.first_name, _href=URL('index'
return dict(items=items)

But it's just displaying this on the index page:

[, ]

Which is good in a way because it's picking up the 2 points in memory
that I have linked to 'Painter' but it's not displaying them right? I
think it's to do with my returning of a dictionary, but I'm not sure
how to fix it, or even find an answer to this.

P.S Are you the Anthony that was helping me on Stack Overflow too? If
so thanks, your help is awesome, hopefully I can pay it back one
day :)


On Aug 14, 9:56 pm, Anthony  wrote:
> Is "Plumber" being entered in the 'title' field of the user table? If so,
> that field is expecting an integer because it is a reference to the 'id'
> field of the 'title' table (which is an integer field).
>
> listing.title.requires = [IS_IN_DB(db, db.title.name)]
>
> Your validator, on the other hand, is requiring a string that is one of the
> names stored in db.title.name. So, your form/validator wants a string, but
> the database wants an integer. You can change your validator to:
>
> listing.title.requires = [IS_IN_DB(db, db.title.id, '%(name)s')]
>
> Note, because the validator is inside a list, it will not display the
> typical dropdown for an IS_IN_DB validator. If you want the dropdown, take
> it out of the list. Also, if you simply add format='%(name)s' to your
> 'title' table definition, you don't have to bother specifying the validator
> for the listing.title field at all because the default validator will be the
> above IS_IN_DB validator anyway.
> Seehttp://web2py.com/book/default/chapter/07#Database-Validatorsandhttp://web2py.com/book/default/chapter/06#Record-Representation.
>
> Anthony
>
>
>
>
>
>
>
>
>
> On Sunday, August 14, 2011 5:39:27 AM UTC-4, Jarrod Cugley wrote:
> > Hi guys this is my first post so just let me know if I'm doing
> > anything wrong :) (Massimo recommended I ask questions here about
> > web2py rather than on Stack Overflow)
>
> > As the title says: I keep getting the error: invalid literal for int()
> > with base 10: 'Plumber'
> > I've done searching and it seems to be a common error, but I can't
> > figure out how to fix it from the answers I've already read, here is
> > my code (that I think is the needed code to solve the error):
>
> > ___DB.PY___: (model)
>
> > db.define_table('title',
> >                 Field('name'),
> >                )
>
> > db.define_table(auth.settings.table_user_name,
> >                 Field('first_name'),
> >                 Field('last_name'),
> >                 Field('email'),
> >                 Field('password','password', length=512,
> > readable=False, label='Password'),
> >                 Field('title', db.title),
> >                 Field('bio','text'),
> >                 Field('phone'),
> >                 Field('website'),
> >                 Field('address'),
> >                 Field('registration_key', length=512,  
>
>                     writable=False, readable=False, default=''),
>
>
>
>
>
>
>
> >                 Field('reset_password_key', length=512,
> >                     writable=False, readable=False, default=''),
> >                 Field('registration_id', length=512,
> >                     writable=False, readable=False, default=''),
> >                 )
>
> > listing = db[auth.settings.table_user_name]
> > listing.title.requires = [
> >      IS_IN_DB(db, db.title.name)]
>
> > ___DEFAULT.PY___: (controller)
>
> > def index():
> >     painters = db(db.listing.title == 23).select()
> >     items = []
> >     for painter in painters:
> >         items.append(A(painter.first_name, _href=URL('index')))
> >     return dict(items=items)
>
> > In my view I just have {{=items}}
>
> > On top of this I can't create new users from the registration form or
> > the appadmin, because it brings up the same error when I submit both
> > registration forms.
>
> > I'm so confused (because I'm an obvious newbie :P) any help would be
> > greatly appreciated! :)


[web2py] Re: Problem using MySQL with scheduler.py

2011-08-14 Thread Massimo Di Pierro
Can you help me test if replaceing this:

subselect = db(query)._select(
db.task_scheduled.id,limitby=(0,1),
orderby=db.task_scheduled.next_run_time)
db(db.task_scheduled.id.belongs(subselect)).update(
status=RUNNING,
assigned_worker_name=self.worker_name,
last_run_time=datetime.now)


with this

from gluon.dal import raw
subselect = db(query)._select(
db.task_scheduled.id,limitby=(0,1),
orderby=db.task_scheduled.next_run_time)
db(db.task_scheduled.id == raw(subselect)).update(
status=RUNNING,
assigned_worker_name=self.worker_name,
last_run_time=datetime.now)

works and fixed the problem with mysql?

On Aug 13, 4:56 am, G  wrote:
> Hello,
> I just tried to use scheduler.py with MySQL instead of SQLite and ran
> into this error:
>
> NotSupportedError: (1235, "This version of MySQL doesn't yet support
> 'LIMIT & IN/ALL/ANY/SOME subquery'")
>
> The MySQL server version is 5.0.77. Searching on the web, it seems
> this limitation is common. Is there a way to work around the issue?
> The offending SQL looks like this:
>
> UPDATE task_scheduled SET
> status='running',assigned_worker_name='crabby#237cf3f0-89e7-4db5-
> b514-56db27a700d5',last_run_time='2011-08-13 09:33:01' WHERE
> (task_scheduled.id IN (SELECT  task_scheduled.id FROM task_scheduled
> WHERE (task_scheduled.enabled = 'T') AND (task_scheduled.status =
> 'queued')) AND (task_scheduled.group_name IN ('command','main'))) AND
> (task_scheduled.next_run_time < '2011-08-13 09:33:01')) AND
> (((task_scheduled.assigned_worker_name = '') OR
> (task_scheduled.assigned_worker_name IS NULL)) OR
> (task_scheduled.assigned_worker_name = 'crabby#237cf3f0-89e7-4db5-
> b514-56db27a700d5'))) ORDER BY task_scheduled.next_run_time LIMIT 1
> OFFSET 0));
>
> I'm pretty sure this is coming from the massively complex query in
> assign_next_task.
>
> Thanks,
> G


[web2py] please help me test new form API

2011-08-14 Thread Massimo Di Pierro
We used to do form.accepts(...), later Bruno added form.validate(...)
and form.process(...). Now we extended this to work with both FORMs
and SQLFORMs so instead of:

form = SQLFORM(...)
if form.accepts(request,session):
   # success
elif form.errors:
   # failure
else:
   # nothing happened

now you can do


form = SQLFORM(...).process()
if form.accepted:
   # success
elif form.errors:
   # failure
else:
   # nothing happened

process takes the same arguments as accepts but does not need to be
passed request.vars and session. It also takes additional parameters:
- onsuccess (lambda form: ...)
- onfailure (lambda form:...)
- message_onsuccess
- message_onfailure
- next (url to redirect in case of success)

Give it a try. This may replace form.accepts(...) as my favorite API.
It makes the code more compact.


[web2py] Re: Problem using MySQL with scheduler.py

2011-08-14 Thread Massimo Di Pierro
If this is not done in one line, it is not atomic and results into the
problems.

On 13 Ago, 13:00, G  wrote:
> As a quick workaround, this change in assign_next_task seems to do the
> trick:
>
>         subselect = db(query).select(
>             db.task_scheduled.id,limitby=(0,1),
>             orderby=db.task_scheduled.next_run_time)
>         for row in subselect:
>             db(db.task_scheduled.id == row.id).update(
>                 status=RUNNING,
>                 assigned_worker_name=self.worker_name,
>                 last_run_time=datetime.now)
>
> On Aug 13, 11:47 am, Massimo Di Pierro 
> wrote:
>
>
>
>
>
>
>
> > I have MySQL, it is full of caveats like this. Can somebody check
> > postgresql?
> > If this is just a mysql issue, we'll deal with it as an exception and
> > find a workaround.
>
> > On 13 Ago, 04:56, G  wrote:
>
> > > Hello,
> > > I just tried to use scheduler.py with MySQL instead of SQLite and ran
> > > into this error:
>
> > > NotSupportedError: (1235, "This version of MySQL doesn't yet support
> > > 'LIMIT & IN/ALL/ANY/SOME subquery'")
>
> > > The MySQL server version is 5.0.77. Searching on the web, it seems
> > > this limitation is common. Is there a way to work around the issue?
> > > The offending SQL looks like this:
>
> > > UPDATE task_scheduled SET
> > > status='running',assigned_worker_name='crabby#237cf3f0-89e7-4db5-
> > > b514-56db27a700d5',last_run_time='2011-08-13 09:33:01' WHERE
> > > (task_scheduled.id IN (SELECT  task_scheduled.id FROM task_scheduled
> > > WHERE (task_scheduled.enabled = 'T') AND (task_scheduled.status =
> > > 'queued')) AND (task_scheduled.group_name IN ('command','main'))) AND
> > > (task_scheduled.next_run_time < '2011-08-13 09:33:01')) AND
> > > (((task_scheduled.assigned_worker_name = '') OR
> > > (task_scheduled.assigned_worker_name IS NULL)) OR
> > > (task_scheduled.assigned_worker_name = 'crabby#237cf3f0-89e7-4db5-
> > > b514-56db27a700d5'))) ORDER BY task_scheduled.next_run_time LIMIT 1
> > > OFFSET 0));
>
> > > I'm pretty sure this is coming from the massively complex query in
> > > assign_next_task.
>
> > > Thanks,
> > > G


[web2py] Re: component-generated field not getting accepted first time

2011-08-14 Thread Massimo Di Pierro
in your models add a

print request.env.path_info

you may find somehow you have one more call than you think which
resets the session. This may be due to a broken link in the view.

On 14 Ago, 14:01, weheh  wrote:
> As you can see, nothing really fancy here.
>
> def my_action():
>     form=SQLFORM.factory(
>             Field('text_field','text',
>                 length=10 if auth.user_id else 50,
>                 default=T("default text") if not auth.user_id else '',
>                 requires=IS_NOT_EMPTY()),
>                 _id='text-form')
>
>     if form.accepts(request.vars,session):
>         # the body of this won't be executed the first time the form
>         # is loaded, but it does get executed every time thereafter
>         # so this is not where the problem is
>     elif form.errors:
>         # this condition is tested the first time the form is
>         # submitted, but not thereafter because the form
>         # accepts properly the second and subsequent times
>
>     return dict(form=form)
>
> The view is down below some widgets and stuff. It always displays
> properly.
> Here's the actual LOAD statement:
>
>         {{=LOAD('my_controller','my_action.load',ajax=True)}}
>
> On Aug 14, 2:36 pm, Anthony  wrote:
>
>
>
>
>
>
>
> > Can you show your controller and view code?
>
> > On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote:
> > > I have a componentized form that is behaving very strangely. The form
> > > is very simple -- just a text field.
>
> > >   form=SQLFORM.factory(Field('text_in','text'))
>
> > >   if form.accepts(request.vars, session):
> > >     do stuff ...
>
> > > The first time I load the form, it loads fine. I traced it in Eclipse
> > > and saw the form getting created with SQLFORM.factory. When I fill in
> > > text, however, the form does not accept, nor does it generate any
> > > error. Inspecting in Eclipse shows form.vars is empty.
>
> > > OK, so now the form is still visible since it was reloaded. I enter
> > > the same text again and click submit. This time, the form.accepts(...)
> > > accepts the form and processes it.
>
> > > I upgraded to the latest and greatest version but still get this
> > > strange behavior. Anybody have an idea what's going on?


[web2py] Re: MySQL query not reflecting actual state of db

2011-08-14 Thread Jay
This is required because you are using the DAL outside web2py
framework,

"""
from gluon import *
import time
db = DAL('mysql://web2py:web2p ...
"""

When used like above, you have to call db.commit to complete the
transaction.

Normally all database insert/updates/deletes are committed at the end
of each action by the framework.


[web2py] Re: component-generated field not getting accepted first time

2011-08-14 Thread Anthony
Hmm, I tried your exact code, and it works for me (whether or not I'm logged 
in). When you first submit, are the appropriate variables coming through in 
request.vars? Can you use the browser developer tools to check the HTML of 
the form when it is first loaded?
 
Anthony

On Sunday, August 14, 2011 3:01:24 PM UTC-4, weheh wrote:

> As you can see, nothing really fancy here. 
>
> def my_action(): 
> form=SQLFORM.factory( 
> Field('text_field','text', 
> length=10 if auth.user_id else 50, 
> default=T("default text") if not auth.user_id else '', 
> requires=IS_NOT_EMPTY()), 
> _id='text-form') 
>
> if form.accepts(request.vars,session): 
> # the body of this won't be executed the first time the form 
> # is loaded, but it does get executed every time thereafter 
> # so this is not where the problem is 
> elif form.errors: 
> # this condition is tested the first time the form is 
> # submitted, but not thereafter because the form 
> # accepts properly the second and subsequent times 
>
> return dict(form=form) 
>
>
> The view is down below some widgets and stuff. It always displays 
> properly. 
> Here's the actual LOAD statement: 
>
> {{=LOAD('my_controller','my_action.load',ajax=True)}} 
>
>
>
> On Aug 14, 2:36 pm, Anthony  wrote: 
> > Can you show your controller and view code? 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote: 
> > > I have a componentized form that is behaving very strangely. The form 
> > > is very simple -- just a text field. 
> > 
> > >   form=SQLFORM.factory(Field('text_in','text')) 
> > 
> > >   if form.accepts(request.vars, session): 
> > > do stuff ... 
> > 
> > > The first time I load the form, it loads fine. I traced it in Eclipse 
> > > and saw the form getting created with SQLFORM.factory. When I fill in 
> > > text, however, the form does not accept, nor does it generate any 
> > > error. Inspecting in Eclipse shows form.vars is empty. 
> > 
> > > OK, so now the form is still visible since it was reloaded. I enter 
> > > the same text again and click submit. This time, the form.accepts(...) 
> > > accepts the form and processes it. 
> > 
> > > I upgraded to the latest and greatest version but still get this 
> > > strange behavior. Anybody have an idea what's going on?



[web2py] Re: w2p on ubuntu

2011-08-14 Thread pbreit
It's difficult to make scripts that work for every situation. One thing you 
can try is instead of running the script, just careful run each command 
manually, picking and choosing which ones you think you need.

I've also put up some other scripts here:
https://bitbucket.org/pbreit/web2py-automation/overview

However, per your #3, this is probably the easiest way to get up and running 
and works fine for development. Either download the tar/zip or (better) hg 
clone the source code.

Then, I think these are the instructions you might want to follow:
http://web2py.com/book/default/chapter/04#Command-Line-Options


Re: [web2py] Re: infoworld put web2py in the top of python frameworks

2011-08-14 Thread António Ramos
Of course. :P

2011/8/14 weheh 

> Yaay! But then, we knew this all along, right?
>
> On Aug 14, 2:40 pm, Anthony  wrote:
> > On Sunday, August 14, 2011 11:55:11 AM UTC-4, Ramos wrote:
> >
> > > No, i just logged in and only see 3 pages.
> >
> > On the third page of the overview article, there is a table listing the 6
> > frameworks -- if you click on the name of a framework in that table, it
> > takes you to the more detailed article for that framework. Above that
> table,
> > it says:
> >
> > "Naturally, the current discussion paints only an overview. For the finer
> > details, follow the links in the table below and plunge into the
> individual
> > reviews."
> >
> > Anthony
>


[web2py] Re: infoworld put web2py in the top of python frameworks

2011-08-14 Thread weheh
Yaay! But then, we knew this all along, right?

On Aug 14, 2:40 pm, Anthony  wrote:
> On Sunday, August 14, 2011 11:55:11 AM UTC-4, Ramos wrote:
>
> > No, i just logged in and only see 3 pages.
>
> On the third page of the overview article, there is a table listing the 6
> frameworks -- if you click on the name of a framework in that table, it
> takes you to the more detailed article for that framework. Above that table,
> it says:
>
> "Naturally, the current discussion paints only an overview. For the finer
> details, follow the links in the table below and plunge into the individual
> reviews."
>
> Anthony


[web2py] Re: component-generated field not getting accepted first time

2011-08-14 Thread weheh
As you can see, nothing really fancy here.

def my_action():
form=SQLFORM.factory(
Field('text_field','text',
length=10 if auth.user_id else 50,
default=T("default text") if not auth.user_id else '',
requires=IS_NOT_EMPTY()),
_id='text-form')

if form.accepts(request.vars,session):
# the body of this won't be executed the first time the form
# is loaded, but it does get executed every time thereafter
# so this is not where the problem is
elif form.errors:
# this condition is tested the first time the form is
# submitted, but not thereafter because the form
# accepts properly the second and subsequent times

return dict(form=form)


The view is down below some widgets and stuff. It always displays
properly.
Here's the actual LOAD statement:

{{=LOAD('my_controller','my_action.load',ajax=True)}}



On Aug 14, 2:36 pm, Anthony  wrote:
> Can you show your controller and view code?
>
>
>
>
>
>
>
> On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote:
> > I have a componentized form that is behaving very strangely. The form
> > is very simple -- just a text field.
>
> >   form=SQLFORM.factory(Field('text_in','text'))
>
> >   if form.accepts(request.vars, session):
> >     do stuff ...
>
> > The first time I load the form, it loads fine. I traced it in Eclipse
> > and saw the form getting created with SQLFORM.factory. When I fill in
> > text, however, the form does not accept, nor does it generate any
> > error. Inspecting in Eclipse shows form.vars is empty.
>
> > OK, so now the form is still visible since it was reloaded. I enter
> > the same text again and click submit. This time, the form.accepts(...)
> > accepts the form and processes it.
>
> > I upgraded to the latest and greatest version but still get this
> > strange behavior. Anybody have an idea what's going on?


Re: [web2py] Re: infoworld put web2py in the top of python frameworks

2011-08-14 Thread Anthony
On Sunday, August 14, 2011 11:55:11 AM UTC-4, Ramos wrote:
>
> No, i just logged in and only see 3 pages.
>
On the third page of the overview article, there is a table listing the 6 
frameworks -- if you click on the name of a framework in that table, it 
takes you to the more detailed article for that framework. Above that table, 
it says:
 

"Naturally, the current discussion paints only an overview. For the finer 
details, follow the links in the table below and plunge into the individual 
reviews."

 
Anthony


[web2py] Re: component-generated field not getting accepted first time

2011-08-14 Thread Anthony
Can you show your controller and view code?

On Sunday, August 14, 2011 2:14:19 PM UTC-4, weheh wrote:

> I have a componentized form that is behaving very strangely. The form 
> is very simple -- just a text field. 
>
>   form=SQLFORM.factory(Field('text_in','text')) 
>
>   if form.accepts(request.vars, session): 
> do stuff ... 
>
>
> The first time I load the form, it loads fine. I traced it in Eclipse 
> and saw the form getting created with SQLFORM.factory. When I fill in 
> text, however, the form does not accept, nor does it generate any 
> error. Inspecting in Eclipse shows form.vars is empty. 
>
> OK, so now the form is still visible since it was reloaded. I enter 
> the same text again and click submit. This time, the form.accepts(...) 
> accepts the form and processes it. 
>
> I upgraded to the latest and greatest version but still get this 
> strange behavior. Anybody have an idea what's going on?



[web2py] component-generated field not getting accepted first time

2011-08-14 Thread weheh
I have a componentized form that is behaving very strangely. The form
is very simple -- just a text field.

  form=SQLFORM.factory(Field('text_in','text'))

  if form.accepts(request.vars, session):
    do stuff ...


The first time I load the form, it loads fine. I traced it in Eclipse
and saw the form getting created with SQLFORM.factory. When I fill in
text, however, the form does not accept, nor does it generate any
error. Inspecting in Eclipse shows form.vars is empty.

OK, so now the form is still visible since it was reloaded. I enter
the same text again and click submit. This time, the form.accepts(...)
accepts the form and processes it.

I upgraded to the latest and greatest version but still get this
strange behavior. Anybody have an idea what's going on?


Re: [web2py] how to generate PDF (with data) using PDF static forms?

2011-08-14 Thread Carlos
Thanks for your suggestion Mariano.

   Carlos



Re: [web2py] routes.py and rewriting URLs

2011-08-14 Thread Jonathan Lundell
On Aug 14, 2011, at 3:26 AM, fishwebby wrote:

> I'm struggling with the routing in web2py and I'm hoping someone can
> point me in the right direction (I'm a web2py newbie).
> 
> I want to change this (which works):
> 
> http://127.0.0.1:8000/init/admin_courses/index
> 
> to this:
> 
> http://127.0.0.1:8000/admin/courses

You could probably figure out how to do this eventually using the 
pattern-matching router (the parametric router won't do it for you), but it's 
going to be a lot easier if you start out without the need to rename/split 
controller items.

It's hard to say what would work best without knowing more about the patterns 
you'd see and the controllers and functions you have.

> 
> but I can't get it to work with the various routes.py files. I've
> followed the suggestions here:
> http://wiki.web2py.com/URL_Re_writing
> and here:
> http://www.web2py.com/book/default/chapter/04#URL-Rewrite
> 
> and various others from this forum but I can't get anything other than
> "invalid request".
> 
> I want to do this for various controllers, for example:
> 
> http://127.0.0.1:8000/admin/users
> http://127.0.0.1:8000/admin/users/3/assignments
> 
> (I'm coming from Rails / Symfony / Kohana so perhaps I'm trying to do
> something that isn't the web2py way?)
> 
> If anyone can point me in the right direction it would be greatly
> appreciated!




[web2py] Re: Virtual Fields. Strange behavior when saving db result sets Build in types

2011-08-14 Thread Santiago Gilabert
anyone?

I found that someone else asked about the same issue 5 month ago but there
are no comments about it.

http://groups.google.com/group/web2py/browse_thread/thread/845e6cdef5de4e92/4ace7b81d9e239c3?lnk=gst&q=Virtual+fields&pli=1

Thanks
Santiago



On Sat, Aug 13, 2011 at 7:07 PM, Santiago wrote:

> Hello,
>
> I have the following definitions in db.py
>
> class ElectionVirtualField(object):
>  ...
>  def is_presidential(self):
>def lazy(self=self):
>  return self.election.category == 'P'
>return lazy
>  ...
>
> db.define_table('election',
>  ...
>  Field('category', length=1, label=T('Category')
>  ...
>
> The problem I have is that when I add a bunch of elections in dict()
> (key = election.id, value = election row) and then traverse the dict,
> I get wrong values from is_presidential()
>
> Example:
>
>elections = dict()
>for election in db(db.election).select():
>   elections[election.id] = election
>
>for (k, v) in elections.items():
>  print k , ' ', v.category, ' ', v.is_presidential()
>
>Output:
>81   D   True
>79   P   True
>
> As you can see, it returns True for both, but for the first one, it
> should return False.
>
> If I change the code to reload the election from the database, the
> output is different:
>
> Example:
>
>elections = dict()
>for election in db(db.election).select():
>   elections[election.id] = election
>
>for (k, v) in elections.items():
>  reloaded_election = db.election(k)
>  print k , ' ', v.category, ' ', v.is_presidential()
>
>Output:
>
>81   D   False
>79   P   True
>
> Does this mean that we can't save rows from DB on Build in types ?
>
> Thanks in advance,
> Santiago
>


Re: [web2py] Re: infoworld put web2py in the top of python frameworks

2011-08-14 Thread António Ramos
No, i just logged in and only see 3 pages.
Can you make a pdf out of the 21 pages you said?

thank you

António

2011/8/11 Massimo Di Pierro 

> Did you see only the 3 summary pages or the 21 pages of with more
> detailed comments about each of the framework?
>
> You need to login and you need to click on the links. technically
> there are 7 articles, each of them of about 3 pages (if you login):
>
>
> http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442
>
> http://www.infoworld.com/d/application-development/pillars-python-cubicweb-web-framework-169105
>
> http://www.infoworld.com/d/application-development/pillars-python-django-web-framework-168643
>
> http://www.infoworld.com/d/application-development/pillars-python-pyramid-web-framework-168661
>
> http://www.infoworld.com/d/application-development/pillars-python-webpy-web-framework-169072
>
> http://www.infoworld.com/d/application-development/pillars-python-web2py-web-framework-168920
>
> http://www.infoworld.com/d/application-development/pillars-python-zope-2-web-framework-168935
>
> I can add the author emailed in March and since then, he tells me, he
> has tried all of the framework and he has been asking around a lot of
> questions. He certainly asked me many questions.
>
> Massimo
>
> On Aug 11, 10:38 am, António Ramos  wrote:
> > Yes but it seems very vague dont it?
> >
> > What does Capability means ?
> >
> > Is Capability composed of many or none sub criteria?
> >
> > 2011/8/11 Richard Vézina 
> >
> >
> >
> >
> >
> >
> >
> > > hurray!
> > > yippee!
> >
> > > Congrats to everyone and Thank to Massimo... It's not the same when he
> is
> > > away from his mailbox ;-)
> >
> > > Richard
> >
> > > On Thu, Aug 11, 2011 at 8:12 AM, Massimo Di Pierro <
> > > massimo.dipie...@gmail.com> wrote:
> >
> > >> We made it to slashdot
> >
> > >>http://developers.slashdot.org/story/11/08/10/2111203/Six-Python-Web-.
> ..
> >
> > >> Traffic (total http requests/day):
> > >> 04/Aug/2011 68450
> > >> 05/Aug/2011 60450
> > >> 06/Aug/2011 50180
> > >> 07/Aug/2011 52327
> > >> 08/Aug/2011 68275
> > >> 09/Aug/2011 75787
> > >> 10/Aug/2011 101568
> > >> 11/Aug/2011 160868 <- new record (only 13hrs out of 24)
> >
> > >> Traffic (distinct users):
> > >> 05/Aug/2011 1854
> > >> 06/Aug/2011 1638
> > >> 07/Aug/2011 1459
> > >> 08/Aug/2011 1972
> > >> 09/Aug/2011 2102
> > >> 10/Aug/2011 2496
> > >> 11/Aug/2011 3367  <- new record (only 13hrs out of 24)
>


[web2py] routes.py and rewriting URLs

2011-08-14 Thread fishwebby
Hi,

I'm struggling with the routing in web2py and I'm hoping someone can
point me in the right direction (I'm a web2py newbie).

I want to change this (which works):

http://127.0.0.1:8000/init/admin_courses/index

to this:

http://127.0.0.1:8000/admin/courses

but I can't get it to work with the various routes.py files. I've
followed the suggestions here:
http://wiki.web2py.com/URL_Re_writing
and here:
http://www.web2py.com/book/default/chapter/04#URL-Rewrite

and various others from this forum but I can't get anything other than
"invalid request".

I want to do this for various controllers, for example:

http://127.0.0.1:8000/admin/users
http://127.0.0.1:8000/admin/users/3/assignments

(I'm coming from Rails / Symfony / Kohana so perhaps I'm trying to do
something that isn't the web2py way?)

If anyone can point me in the right direction it would be greatly
appreciated!

Many thanks
Dave


[web2py] segmentation fault using rocket

2011-08-14 Thread MojaveKid
Hi.

Lately, Ive been encountering segmentation fault using the rocket web
server.

I tried:
python web2py.py
python anyserver.py -s rocket

and encountered the seg faults

However, the faults are not occuring when i use tornado.

I was unsuccessful in locating the seg faults. Im using web2py v1.98.2

Maybe you have encountered them too.



[web2py] Re: I keep getting the error: invalid literal for int() with base 10: 'Plumber'

2011-08-14 Thread Anthony
Is "Plumber" being entered in the 'title' field of the user table? If so, 
that field is expecting an integer because it is a reference to the 'id' 
field of the 'title' table (which is an integer field).
 
listing.title.requires = [IS_IN_DB(db, db.title.name)]
 
Your validator, on the other hand, is requiring a string that is one of the 
names stored in db.title.name. So, your form/validator wants a string, but 
the database wants an integer. You can change your validator to:
 
listing.title.requires = [IS_IN_DB(db, db.title.id, '%(name)s')]
 
Note, because the validator is inside a list, it will not display the 
typical dropdown for an IS_IN_DB validator. If you want the dropdown, take 
it out of the list. Also, if you simply add format='%(name)s' to your 
'title' table definition, you don't have to bother specifying the validator 
for the listing.title field at all because the default validator will be the 
above IS_IN_DB validator anyway.
See http://web2py.com/book/default/chapter/07#Database-Validators and 
http://web2py.com/book/default/chapter/06#Record-Representation.
 
Anthony
 

On Sunday, August 14, 2011 5:39:27 AM UTC-4, Jarrod Cugley wrote:

> Hi guys this is my first post so just let me know if I'm doing 
> anything wrong :) (Massimo recommended I ask questions here about 
> web2py rather than on Stack Overflow) 
>
>
> As the title says: I keep getting the error: invalid literal for int() 
> with base 10: 'Plumber' 
> I've done searching and it seems to be a common error, but I can't 
> figure out how to fix it from the answers I've already read, here is 
> my code (that I think is the needed code to solve the error): 
>
> ___DB.PY___: (model) 
>
> db.define_table('title', 
> Field('name'), 
>) 
>
> db.define_table(auth.settings.table_user_name, 
> Field('first_name'), 
> Field('last_name'), 
> Field('email'), 
> Field('password','password', length=512, 
> readable=False, label='Password'), 
> Field('title', db.title), 
> Field('bio','text'), 
> Field('phone'), 
> Field('website'), 
> Field('address'), 
> Field('registration_key', length=512,  

writable=False, readable=False, default=''), 
> Field('reset_password_key', length=512, 
> writable=False, readable=False, default=''), 
> Field('registration_id', length=512, 
> writable=False, readable=False, default=''), 
> ) 
>
> listing = db[auth.settings.table_user_name] 
> listing.title.requires = [
>  IS_IN_DB(db, db.title.name)]
>
>
>
> ___DEFAULT.PY___: (controller) 
>
> def index(): 
> painters = db(db.listing.title == 23).select() 
> items = [] 
> for painter in painters: 
> items.append(A(painter.first_name, _href=URL('index'))) 
> return dict(items=items) 
>
>
> In my view I just have {{=items}} 
>
> On top of this I can't create new users from the registration form or 
> the appadmin, because it brings up the same error when I submit both 
> registration forms. 
>
> I'm so confused (because I'm an obvious newbie :P) any help would be 
> greatly appreciated! :)



Re: [web2py] Table creation in GAE

2011-08-14 Thread Martín Mulone
yes

2011/8/13 ram 

> Is the following statement correct?
> A Table is created in  GAE only when the first record is inserted.




-- 
 http://martin.tecnodoc.com.ar


Re: [web2py] Noob question - Choices definition in Field - DAL

2011-08-14 Thread Martín Mulone
Field ('gender',
requires=IS_IN_SET
(['Male',
'Female', 'Other'])),


2011/8/13 ram 

> Is it possible to this using DAL, using Field definition?
>
> role = db.StringProperty(required=True, choices=set(["executive",
> "manager", "producer"]))
>
> Best regards
> Ram




-- 
 http://martin.tecnodoc.com.ar


[web2py] I keep getting the error: invalid literal for int() with base 10: 'Plumber'

2011-08-14 Thread Jarrod Cugley
Hi guys this is my first post so just let me know if I'm doing
anything wrong :) (Massimo recommended I ask questions here about
web2py rather than on Stack Overflow)


As the title says: I keep getting the error: invalid literal for int()
with base 10: 'Plumber'
I've done searching and it seems to be a common error, but I can't
figure out how to fix it from the answers I've already read, here is
my code (that I think is the needed code to solve the error):

___DB.PY___: (model)

db.define_table('title',
Field('name'),
   )

db.define_table(auth.settings.table_user_name,
Field('first_name'),
Field('last_name'),
Field('email'),
Field('password','password', length=512,
readable=False, label='Password'),
Field('title', db.title),
Field('bio','text'),
Field('phone'),
Field('website'),
Field('address'),
Field('registration_key', length=512,
writable=False, readable=False, default=''),
Field('reset_password_key', length=512,
writable=False, readable=False, default=''),
Field('registration_id', length=512,
writable=False, readable=False, default=''),
)

listing = db[auth.settings.table_user_name]
listing.title.requires = [
IS_IN_DB(db, db.title.name)]


___DEFAULT.PY___: (controller)

def index():
painters = db(db.listing.title == 23).select()
items = []
for painter in painters:
items.append(A(painter.first_name, _href=URL('index')))
return dict(items=items)


In my view I just have {{=items}}

On top of this I can't create new users from the registration form or
the appadmin, because it brings up the same error when I submit both
registration forms.

I'm so confused (because I'm an obvious newbie :P) any help would be
greatly appreciated! :)


[web2py] bulkloader & web2py

2011-08-14 Thread Amnon Khen
Dear web2py community,

I was wondering if anyone figured out how to upload data to a GAE app
and getting the entity IDs right.

Here's what I try:

1. Entities creates by web2py have their ID populated to a numeric
value and the "key name" empty.
2. When I export (appcgy.py download_data) the data, the ID is
returned as the entity's key.
3. When I try to import (appcgy.py upload_data) the same data, instead
of updating the existing entities, new ones are created with an empty
ID and the original ID value is the "key name" value.
4. The configuration (in bulkloader.yaml) I use for the entity's key
is:
property_map:
  - property: __key__
external_name: ID
export_transform: transform.key_id_or_name_as_string

I saw a few posts in this group about this issue, but none with a
solution.
I followed the instructions in http://bulkloadersample.appspot.com/
but it also did not help.

Is this the correct way to upload data to a GAE/web2py app?

I would appreciate any help.

Thanks,
  Amnon Khen


[web2py] w2p on ubuntu

2011-08-14 Thread Vineet
This refers to the following thread---
https://groups.google.com/group/web2py/browse_thread/thread/4350a3b6836f9dd4/dca9c0e1f1c7540b?lnk=gst&q=ubuntu
@Preit, excellent work for preparing the script.
I'm encouraged to see that the w2p community is always active.
It is really nice to work with web2py.

Till date, I have been developing on Windows.
Now I wish to switch on Open Source OS.

I've installed Ubuntu alongside existing Win7.
Pl. consider that I am new to non-Windows OS.

My queries--

(queries related to the script by 'pbreit')
1) If I use the script written by "pbreit", it will install Nginx
0.8.54 & uWSGI 0.9.7.1.
Till date, I was using the default Rocket web server which required no
configuration.
Whether nginx will also run without any other settings? or any config
would be reqd.?

2) I use MySQL. Hence do not need PostGresql.
Can I safely comment-out the 2 lines in script related to the
installation of postgresql?
Or will it break any other dependency?

3) BTW, since pbreit has written a special script, it poses one
question in my mind ---
What thing might be missing if I just download the w2p source, unzip
it & run "> python2.5 web2py.py" from the Terminal ?

(query related to web2py in general)
4) Whether same version of w2p runs On Ubuntu 32-bit & 64-bit
versions.
I could not see different versions of w2p (32/64) on the download
page.
Is it so, that only 32 bit version of w2p is available (which runs
happily on 64 bit machine)?

Thanks,
Vineet.


Re: [web2py] Re: ANN: ide2py: editor, shell and debugger for web2py (experimental)

2011-08-14 Thread José Luis Redrejo Rodríguez
2011/8/12 Mariano Reingart :
> Thanks Jose, I've create an issue as this is important to get it
> working on most platform and versions.
>
> http://code.google.com/p/rad2py/issues/detail?id=3
>
> I've sent a mail to the wx-users mailing list, if the error persists,
> I'll change to standard toolbars.
>
> Regarding the paths, there is a ide2py.ini configuration file to adjust them.
> The idea is that the config file would be stored in the user
> directory, but beside that, I don't known what is the best approach to
> place web2py projects in the disk.
>

Not, I wasn't talking about the web2py projects, but about the paths
ide2py needs:
- a web2py installation in ../web2py
- I don't understand too much the paths in the .ini file, how the
checklist and data paths are created. I thought that having valid
paths, ide2py would create the .dat files, but I don't see it.

On the other hand: with current mercurial version, the bugs I detected
with wx have disappeared. I see this error when trying to use the
quick help, but I guess I'm trying something that's not finished yet:

Traceback (most recent call last):
  File "main.py", line 627, in OnHelp
sel = self.active_child.GetSelectedText()
AttributeError: 'NoneType' object has no attribute 'GetSelectedText'





The most important problem for me is that trying to open a project I
just get an empty window with  the list of projects (and I have
projects in the web2py installation where psp2py is symlinked). I only
see in the rocket server logs:
127.0.0.1, 2011-08-14 10:03:06, POST, /psp2py/services/call/jsonrpc,
HTTP/1.1, 200, 0.038954
So, everything looks right, but no project can be accesed.
Am I missing a configuration option?

Thanks.
José L.