[web2py] opinion -- modal login not what it could/should be

2012-03-23 Thread weheh
After much tinkering with modal login, I'm formulating the following
opinions:
- modal login is a powerful and useful capability
- modal login is not well supported by web2py and not at all a
functionality that newbies would be able to implement easily. As per
pbreit in 
http://groups.google.com/group/web2py/browse_thread/thread/1394315562b1bba0/729729e02bdba61f#729729e02bdba61f,
if you use modal login you run into troubles elsewhere when you need
to point to a login url. For instance, if you decorate with
@auth.requires_login(), then you're going to run into trouble. That's
because you'll be redirected to a login page, which doesn't exist.
- the implementation of auth does not natively support components.
This requires a workaround -- intercepting the login completion with
auth.settings.login_onaccept and raising an HTTP call. However, it
seems as though _onaccept is not uniformly implemented throughout
auth.

I believe an experienced user can workaround these issues. However,
with the rise of components and jQuery interactivity, I think it's in
the community's interest to revisit auth and see how it can be
improved to support these new web2py and jQuery capabilities. What do
you think?


[web2py] Re: Getting started in Web2py

2012-03-23 Thread stefaan

Your mileage may vary, but for me glancing through the examples got me
started in no time:

http://www.web2py.com/examples/default/examples


[web2py] Re: infinite loop with form.process().accepted

2012-03-23 Thread bussiere adrien

>
> Thanks a lot.
>

It was obvious for me that it was an int.

Thanks again
Bussiere 


[web2py] Invalid syntax

2012-03-23 Thread bussiere adrien
# -*- coding: utf-8 -*-
def ensurefirstuser(firstname,lastname,email,password)​:
users = db(db.auth_user.email==email).​select()
if users:
user_id = users[0].id
created = False
if settings.debug_ensure_first_​user == True:
print ('found user_id so created equals %s') % created
return (user_id,created)

else:
my_crypt = CRYPT(key=auth.settings.hmac_​key)
crypt_pass = my_crypt(password)[0]
id_user= db.auth_user.insert(
  ​ first_name=firstname,
  ​ last_name=lastname,
  ​ email = email,
  ​ password = crypt_pass
  ​ )
created = True
if settings.debug_ensure_first_​user == True:
print ('creating user_id')
return (id_user,created)


Here i truly don't understand why it still say invalid syntax and i'am 
investing on it fr hours ...

Regards
Bussiere



Re: [web2py] Invalid syntax

2012-03-23 Thread Manuele Pesenti

Il 23/03/2012 10:40, bussiere adrien ha scritto:

# -*- coding: utf-8 -*-
def ensurefirstuser(firstname,lastname,email,password)​:
users = db(db.auth_user.email==email).​select()
if users:
user_id = users[0].id
created = False
if settings.debug_ensure_first_​user == True:
print ('found user_id so created equals %s') % created
return (user_id,created)

else:
my_crypt = CRYPT(key=auth.settings.hmac_​key)
crypt_pass = my_crypt(password)[0]
id_user= db.auth_user.insert(
  ​ first_name=firstname,
  ​ last_name=lastname,
  ​ email = email,
  ​ password = crypt_pass
  ​ )
created = True
if settings.debug_ensure_first_​user == True:
print ('creating user_id')
return (id_user,created)


Here i truly don't understand why it still say invalid syntax and i'am 
investing on it fr hours ...


Regards
Bussiere


Can you provide the line error or the whole ticket error?

M.


[web2py] SQLForm.grid : is it possible to delete multiple rows at once ?

2012-03-23 Thread sebsto
Hello,

Is it possible to select and delete multiple rows with one button click 
using SQLFORM.grid ?  (instead of clicking delete on each row)
I tried the "selectable" property but this doesn't help to delete.
I searched the archive of this group / mailing-list without success

Thanks for your help

Seb


[web2py] Re: auth.login() from inside a component in a dialog

2012-03-23 Thread Sebastien Stormacq
Hello Anthony,

Could you share your code for modal login ?
I am beginning with web2py and would love to learn from that example.

Thanks

Seb

On Friday, March 23, 2012 4:08:51 AM UTC+1, Anthony wrote:
>
> @anthony: actually, on closer inspection, the doc does go into some 
>> details: 
>> http://web2py.com/books/​​default/chapter/29/4#HTTP-and-​​redirect
>>  
>> but I'm still experimenting with how to get it to execute a script.
>
>
> Something like:
>
> def myonaccept(form):
> [do stuff]
> response.js = 'some JS code'
> raise HTTP(200, response.render())
>
> In that case, raise HTTP() will immediately return a response without 
> proceeding through the remainder of auth.login() (thus avoiding the 
> subsequent redirect). As long as the original request was made via an Ajax 
> component, setting response.js before calling raise HTTP() will result in 
> web2py adding the JS code as a response header before returning the 
> response.
>
> Note, response.render() can take a view argument and a context argument 
> (i.e., a dict) if needed. HTTP() can also take arbitrary keyword arguments, 
> which will be converted to response headers.
>
> Anthony
>  
>


[web2py] Re: auth.login() from inside a component in a dialog

2012-03-23 Thread weheh
Here's what I'm using:

# controller
def login():


On Mar 23, 7:30 pm, Sebastien Stormacq 
wrote:
> Hello Anthony,
>
> Could you share your code for modal login ?
> I am beginning with web2py and would love to learn from that example.
>
> Thanks
>
> Seb
>
>
>
>
>
>
>
> On Friday, March 23, 2012 4:08:51 AM UTC+1, Anthony wrote:
>
> > @anthony: actually, on closer inspection, the doc does go into some
> >> details:
> >>http://web2py.com/books/​​default/chapter/29/4#HTTP-and-​​redirect
> >> but I'm still experimenting with how to get it to execute a script.
>
> > Something like:
>
> > def myonaccept(form):
> >     [do stuff]
> >     response.js = 'some JS code'
> >     raise HTTP(200, response.render())
>
> > In that case, raise HTTP() will immediately return a response without
> > proceeding through the remainder of auth.login() (thus avoiding the
> > subsequent redirect). As long as the original request was made via an Ajax
> > component, setting response.js before calling raise HTTP() will result in
> > web2py adding the JS code as a response header before returning the
> > response.
>
> > Note, response.render() can take a view argument and a context argument
> > (i.e., a dict) if needed. HTTP() can also take arbitrary keyword arguments,
> > which will be converted to response headers.
>
> > Anthony


[web2py] Re: auth.login() from inside a component in a dialog

2012-03-23 Thread weheh
Sorry, last message got mangled somehow. Here goes again.

Sebastian, here's what I'm using:

# model
auth = Auth(db)
...
def complete_login(form):
from gluon import HTTP
# do some stuff with form as necessary
response.flash = 'You are now logged in'
response.js = 'ajax("%s",[],":eval:);' % URL(
c='user', f='cb_after_login', extension=False)
# note: Anthony does this
# raise HTTP(200, response.render())
raise HTTP(200, SCRIPT(response.js))

auth.settings.login_onaccept = [complete_login]

# controller
def login():
return dict(form=auth.login())

def cb_after_login():
return 'jQuery("#login-dialog").dialog("close");'

# view

{{=form}}



jQuery("#login-dialog").dialog({
autoOpen: false
  , width: 'auto'
  , height: 'auto'
  , modal: true
  , draggable: false
  , closeOnEscape: true
  });


# note: this method uses the jquery ui dialog box, so you need to
# install and load that javascript before running any of this

This has been transcribed from original code, so there may be a typo
in here. No warranty ;-) But I think it should be good to go.

Good luck. Note - you *WILL* get burned, as stated by pbreit, when you
try to access code that has been decorated by @auth.requires_login().
That's because you will be directed to your login page, which no
longer exists. So you will have to figure out what to do about that.
I'm in the process of figuring that out.


[web2py] Re: auth.login() from inside a component in a dialog

2012-03-23 Thread Sebastien Stormacq
Thanks !

On Friday, March 23, 2012 12:57:10 PM UTC+1, weheh wrote:
>
> Sorry, last message got mangled somehow. Here goes again. 
>
> Sebastian, here's what I'm using: 
>
>
>

[web2py] Auto Login on Google App engine

2012-03-23 Thread Sushant Taneja
Hi,

As per the source code of the auth.register(), if auto-login is enabled, 
another DAL query is executed to get the user from auth_user table. 

1958 user = self.db(table_user[username] == 
form.vars[username]).select
().first
() 

This user object is then set in the session and user is redirected to the 
page specified.

1959 user = 
Storage
(table_user._filter_fields
(user, id=True)) 1960 
session
.auth = 
Storage
(user=user, 
last_visit=request
.now, 1961 
expiration=self.settings
.expiration, 1962 hmac_key = 
web2py_uuid
()) 

But on App engine's HRD, this read (line no: 1958 as above) fails.
As per my understanding, this is because the write operation of the 
auth_user table is still not complete so the query returns None and thus 
the code in line 1959/1960 fails.

Can somebody suggest a workaround for this problem ?
I would really like to include the auto login feature in my app. 

Also what does the line of code in *line number: 1959* exactly does ?

Thanks,
Sushant


[web2py] mistake by not using db.commit ()?

2012-03-23 Thread Luis Díaz
The following code gives me error if not explicitly use db.commit ()
can someone explain why I now need to use db.commit () to something so simple?

models/home.py

##
id_user = (auth.user and auth.user.id) or None

db.define_table('home',
Field('titulo', 'string', length=64, default='titulo de prueba'),
Field('texto', 'text', length=5000, default='texto de prueba'),
Field('user', db.auth_user, default=id_user, writable=False,
readable=False),

#auditoria
Field('ip', 'string', length=64,  default=request.client,
update=request.client, writable=False, readable=False),
Field('fecha', 'date',default=request.now, update=request.now,
writable=False, readable=False),
Field('user_update', db.auth_user, default=id_user,
update=id_user, writable=False, readable=False),
)



controllers/default.py
##
def index():

if auth.is_logged_in() :
home = db.home(user=id_user)
if home is None: redirect(URL('update'))

return dict()


@auth.requires_login()
def update():

home = db.home(user=id_user)

if home is None:
home_id = db.home.insert(user=id_user)
else:
home_id = home.id

#db.commit()
form = crud.update(db.home, home_id, deletable=False, next=URL('update'))

return dict(home=home, form=form)
#


view/default/update.html

{{extend 'layout.html'}}


{{ =home.titulo }}


{{=form.custom.begin}}
{{ =form.custom.widget.titulo }}
{{ =form.custom.widget.texto }}

{{=form.custom.end}}


###


Error
#

web2py™ (1, 99, 7, datetime.datetime(2012, 3, 4, 22, 12, 8), 'stable')
Python  Python 2.6.6: /usr/bin/python
TRACEBACK

Traceback (most recent call last):
  File "/home/diazluis2007/web2py/gluon/restricted.py", line 205, in restricted
exec ccode in environment
  File "/home/diazluis2007/web2py/applications/about/views/default/update.html",
line 80, in 
AttributeError: 'NoneType' object has no attribute 'titulo'



Díaz Luis
Analista Programador Facultad de Odontología UC
http://www.about.me/diazluis
User Linux 532223


Re: [web2py] mistake by not using db.commit ()?

2012-03-23 Thread Richard Vézina
Most of the time in web2py you don't need to commit, but in particular
scenario you maybe need to commit before an other operation because you
need the database to be up to date before the and of your function.

http://web2py.com/books/default/chapter/29/6?search=db.commit%28%29

Hope it helps

On Fri, Mar 23, 2012 at 9:47 AM, Luis Díaz  wrote:

> The following code gives me error if not explicitly use db.commit ()
> can someone explain why I now need to use db.commit () to something so
> simple?
>
> models/home.py
>
> ##
> id_user = (auth.user and auth.user.id) or None
>
> db.define_table('home',
>Field('titulo', 'string', length=64, default='titulo de prueba'),
>Field('texto', 'text', length=5000, default='texto de prueba'),
>Field('user', db.auth_user, default=id_user, writable=False,
> readable=False),
>
>#auditoria
>Field('ip', 'string', length=64,  default=request.client,
> update=request.client, writable=False, readable=False),
>Field('fecha', 'date',default=request.now, update=request.now,
> writable=False, readable=False),
>Field('user_update', db.auth_user, default=id_user,
> update=id_user, writable=False, readable=False),
> )
> 
>
>
> controllers/default.py
> ##
> def index():
>
>if auth.is_logged_in() :
>home = db.home(user=id_user)
>if home is None: redirect(URL('update'))
>
>return dict()
>
>
> @auth.requires_login()
> def update():
>
>home = db.home(user=id_user)
>
>if home is None:
>home_id = db.home.insert(user=id_user)
>else:
>home_id = home.id
>
> #db.commit()
>form = crud.update(db.home, home_id, deletable=False,
> next=URL('update'))
>
>return dict(home=home, form=form)
> #
>
>
> view/default/update.html
>
> {{extend 'layout.html'}}
>
>
>{{ =home.titulo }}
>
>
>{{=form.custom.begin}}
>{{ =form.custom.widget.titulo }}
>{{ =form.custom.widget.texto }}
>
>{{=form.custom.end}}
>
>
> ###
>
>
> Error
> #
>
> web2py™ (1, 99, 7, datetime.datetime(2012, 3, 4, 22, 12, 8), 'stable')
> Python  Python 2.6.6: /usr/bin/python
> TRACEBACK
>
> Traceback (most recent call last):
>  File "/home/diazluis2007/web2py/gluon/restricted.py", line 205, in
> restricted
>exec ccode in environment
>  File
> "/home/diazluis2007/web2py/applications/about/views/default/update.html",
> line 80, in 
> AttributeError: 'NoneType' object has no attribute 'titulo'
>
>
>
> Díaz Luis
> Analista Programador Facultad de Odontología UC
> http://www.about.me/diazluis
> User Linux 532223
>


[web2py] Re: opinion -- modal login not what it could/should be

2012-03-23 Thread Anthony

>
> After much tinkering with modal login, I'm formulating the following 
> opinions: 
> - modal login is a powerful and useful capability 
> - modal login is not well supported by web2py and not at all a 
> functionality that newbies would be able to implement easily.


Sorry, I keep forgetting about 
auth.login_bare(): 
http://web2py.com/books/default/chapter/29/9#Manual-Authentication. 
That might be a better way to go when implementing something like a modal 
login. You can control all the logic regarding displaying the login form, 
submitting credentials, returning responses, etc., and just use 
auth.login_bare() to check the credentials and update auth.user upon 
successful login. Then you don't have to worry about working around the 
automatic redirects in auth.login().

 For instance, if you decorate with 
> @auth.requires_login(), then you're going to run into trouble. That's 
> because you'll be redirected to a login page, which doesn't exist. 
> - the implementation of auth does not natively support components.
>

This can get tricky. When the browser requests a URL that happens to be 
decorated with @auth.requires_login(), it may be requesting a full page 
(i.e., not just an Ajax response), so the action has to return a full page. 
If the user isn't logged in, what page should be returned in that case 
(given that there is no dedicated login page)? One option might be 
something like this:

auth.settings.login_url = URL('default', 'index', vars=dict(login='true'))

Then, on the index page, include some JS that checks the URL query string 
upon page load, and if it includes "login=true", pop up the login modal.

Another option is to have a dedicated login page in addition to the modal 
login. Use the modal when the user explicitly chooses to login, but use the 
login page when you have to redirect from a protected URL. I think that's a 
fairly common approach.

Anthony 



[web2py] Re: auth.login() from inside a component in a dialog

2012-03-23 Thread Anthony
I mentioned this in another thread 
(https://groups.google.com/d/msg/web2py/XaHiLQHQ9X0/N8J1PqUxK6YJ), but an 
entirely different approach is to skip auth.login() altogether, write all 
the login logic yourself, and use auth.login_bare() just to check the 
submitted credentials (in addition to returning True or False, it also 
updates the session and auth.user in case of successful login).

Anthony

On Thursday, March 22, 2012 11:08:51 PM UTC-4, Anthony wrote:
>
> @anthony: actually, on closer inspection, the doc does go into some 
>> details: 
>> http://web2py.com/books/​​default/chapter/29/4#HTTP-and-​​redirect
>>  
>> but I'm still experimenting with how to get it to execute a script.
>
>
> Something like:
>
> def myonaccept(form):
> [do stuff]
> response.js = 'some JS code'
> raise HTTP(200, response.render())
>
> In that case, raise HTTP() will immediately return a response without 
> proceeding through the remainder of auth.login() (thus avoiding the 
> subsequent redirect). As long as the original request was made via an Ajax 
> component, setting response.js before calling raise HTTP() will result in 
> web2py adding the JS code as a response header before returning the 
> response.
>
> Note, response.render() can take a view argument and a context argument 
> (i.e., a dict) if needed. HTTP() can also take arbitrary keyword arguments, 
> which will be converted to response headers.
>
> Anthony
>  
>


Re: [web2py] Invalid syntax

2012-03-23 Thread Jonathan Lundell
On Mar 23, 2012, at 2:40 AM, bussiere adrien wrote:
> # -*- coding: utf-8 -*-
> def ensurefirstuser(firstname,lastname,email,password)​:
> users = db(db.auth_user.email==email).​select()
> if users:
> user_id = users[0].id
> created = False
> if settings.debug_ensure_first_​user == True:
> print ('found user_id so created equals %s') % created
> return (user_id,created)
> 
> else:
> my_crypt = CRYPT(key=auth.settings.hmac_​key)
> crypt_pass = my_crypt(password)[0]
> id_user= db.auth_user.insert(
>   ​ first_name=firstname,
>   ​ last_name=lastname,
>   ​ email = email,
>   ​ password = crypt_pass
>   ​ )
> created = True
> if settings.debug_ensure_first_​user == True:
> print ('creating user_id')
> return (id_user,created)
> 
> 
> Here i truly don't understand why it still say invalid syntax and i'am 
> investing on it fr hours ...
> 
> Regards
> Bussiere
> 

You have a bunch of Unicode 200B (zero-width space) characters in it. 

Re: [web2py] DAL / connection pool leaking objects?

2012-03-23 Thread Richard Vézina
Why are you doing that?

Richard

On Fri, Mar 23, 2012 at 2:26 AM, nick name wrote:

> In one of my management scripts (which runs continuously, after setting up
> a web2py environment), I copy a complete sqlite database directory from
> another server (copied_db.sqlite, and *.table), open them with
> "DAL('sqlite://copiedfile.sqlite', auto_import=True, path='/tmp/copy_path)".
>
> I copy the files back and forth, and recreate the DAL object every 10-20
> seconds or so. Note that on linux, this means that the sqlite file opened
> every time is new (new copy replaces old one), even if it has the same name
> and same contents as before -- this use case is different than standard
> web2py use, in which the DAL always refers to the same file on disk (same
> inode, same everything).
>
> I noticed that after a few hours, memory consumption becomes huge (goes
> from 7M to 400M in less than an hour, _and_ continues to grow, despite the
> files not getting larger). At some point, the sqlite dbapi connect starts
> failing as well.
>
> Is there a pool or cache that keeps DAL objects alive behind the scenes?
>
> I have so far been unable to find what would keep the DALs alive; where
> should I look? The culprit could be anything that indirectly keeps a
> reference to the connection or the database, e.g. - a Field, a Table,
> anything like that. Any ideas where to look in web2py? my code doesn't
> store any of these objects, by maybe something in web2py does?
>
>
>


[web2py] Re: auth.login() from inside a component in a dialog

2012-03-23 Thread Anthony
On Friday, March 23, 2012 12:54:00 AM UTC-4, weheh wrote:
>
> Anthony, I tried your 
> raise HTTP(200, response.render()) 
> vs. my 
> raise HTTP(200, SCRIPT(response.js)) 
>
> I ran into a ticket complaining about my form not being defined, so 
> I'm back to my SCRIPT().
>

Well, by default response.render() renders the current view (which in this 
case is login.load). Instead, you can tell it to render a different view 
(either change  response.view, or just pass the name of the view as the 
first arg to response.render()). But if you don't actually need to render 
any view, then there's no need to include response.render() at all. In that 
case, just do:

raise HTTP(200)

Your response.js code will get added to the response headers, and the 
web2py JS code on the client will execute the response.js code when the 
Ajax response is received (this assumes the Ajax request was made via a 
web2py component). Note, when the web2py component receives the Ajax 
response, it replaces the component contents with the returned response, 
which in this case will be emtpy -- so your component will end up empty. Is 
that what you want? Shouldn't the response include some kind of "You are 
now logged in" message?

Anthony

On Friday, March 23, 2012 12:54:00 AM UTC-4, weheh wrote:
>
> Anthony, I tried your 
> raise HTTP(200, response.render()) 
> vs. my 
> raise HTTP(200, SCRIPT(response.js)) 
>
> I ran into a ticket complaining about my form not being defined, so 
> I'm back to my SCRIPT(). 
>
> Traceback (most recent call last): 
>   File "N:\web2py\gluon\restricted.​py", line 204, in restricted 
> exec ccode in environment 
>   File "N:\web2py\applications\myapp\​views\user/login.load", line 9, 
> in  
> }} 
> NameError: name 'login_form' is not defined



[web2py] Re: SQLForm.grid : is it possible to delete multiple rows at once ?

2012-03-23 Thread Anthony

>
> Is it possible to select and delete multiple rows with one button click 
> using SQLFORM.grid ?  (instead of clicking delete on each row)
> I tried the "selectable" property but this doesn't help to delete.
> I searched the archive of this group / mailing-list without success
>

Not out of the box. I suppose you could add a column (via the "links" 
argument) with "delete" checkboxes, and then add a "delete checked" button 
to the page with a Javascript event handler that identifies the checked 
records, submits a request to the server, and then possibly reloads the 
whole page or just the grid via Ajax.

Anthony 


[web2py] Re: bug in auth -- reset_password_onaccept doesn't exist ...

2012-03-23 Thread Anthony
Congratulations, it appears you are the first person to need a reset 
password callback. :-)

On Friday, March 23, 2012 2:11:13 AM UTC-4, weheh wrote:
>
> I'm doing some more of this modal stuff for my login/password routines 
> and ran into this problem. Probably an oversight in the code (lots of 
> moving parts there!) 
>
> Traceback (most recent call last): 
>   File "N:\web2py\gluon\restricted.​py", line 204, in restricted 
> exec ccode in environment 
>   File "N:/web2py/applications/myapp/​models/0_db_1_user.py", line 171, 
> in  
> auth.settings.reset_password_​onaccept = 
> [complete_request_reset_​password] 
>   File "N:\web2py\gluon\storage.py", line 196, in __setattr__ 
> raise SyntaxError, 'setting key \'%s\' does not exist' % key 
> SyntaxError: setting key 'reset_password_onaccept' does not exist



[web2py] Re: auth.login() from inside a component in a dialog

2012-03-23 Thread weheh
raise HTTP(200) works great and is cleaner. Thanks.


Re: [web2py] Invalid syntax

2012-03-23 Thread bussiere adrien
Yep that was that the encoding

thanks all i did a replace with this regexp :
/[^\x00-\x7F]/

But it was hard to understand ...

Thanks
Bussiere


Le vendredi 23 mars 2012 15:14:02 UTC+1, Jonathan Lundell a écrit :
>
> On Mar 23, 2012, at 2:40 AM, bussiere adrien wrote:
> > # -*- coding: utf-8 -*-
> > def ensurefirstuser(firstname,​lastname,email,password)​:
> > users = db(db.auth_user.email==email).​​select()
> > if users:
> > user_id = users[0].id
> > created = False
> > if settings.debug_ensure_first_​​user == True:
> > print ('found user_id so created equals %s') % created
> > return (user_id,created)
> > 
> > else:
> > my_crypt = CRYPT(key=auth.settings.hmac_​​key)
> > crypt_pass = my_crypt(password)[0]
> > id_user= db.auth_user.insert(
> >   ​ first_name=firstname,
> >   ​ last_name=lastname,
> >   ​ email = email,
> >   ​ password = crypt_pass
> >   ​ )
> > created = True
> > if settings.debug_ensure_first_​​user == True:
> > print ('creating user_id')
> > return (id_user,created)
> > 
> > 
> > Here i truly don't understand why it still say invalid syntax and i'am 
> investing on it fr hours ...
> > 
> > Regards
> > Bussiere
> > 
>
> You have a bunch of Unicode 200B (zero-width space) characters in it. 
>


[web2py] Markmin - could we use instead of ?

2012-03-23 Thread villas
I see bold is ,  so why is em rendered as  - it is inconsistent. 
 Also inconsistent with Markdown.  And  isn't even styled in the current 
web2py.js (unless I'm missing something).   Anyhow,  if it wouldn't cause a 
problem, could we please change it.  Thanks.

[web2py] Chrome extension to auto-open error tickets

2012-03-23 Thread Alexander Garden
Hi,

I am working on a project using web2py and found clicking on trouble 
tickets rather a nuisance. So I wrote a Chrome extension that watches for 
web2py error pages and, when it finds one, opens the trouble ticket in an 
iframe, thus saving me a couple clicks and a bunch of time. It's on 
github. 
Packed extension is on the download 
page
.

Alexander


Re: [web2py] DAL and schema

2012-03-23 Thread Wuwei
I agree, I can't find a way to use 2 differents schemas in mssql with DAL.
2 connections are not a solution because it seems there is no way to 
explain to DAL wich schema you want to connect to per each connection, you 
can only specify database.
How do you handle this?
Schemas, like in postgres, are logical subsets of tables in a single 
database.

This is an important limitation for DAL.
I think there should be a way in table definition to specify the schema, so 
that you can do queries that join tables of two different schemas in the 
same connection.

Any other idea?



[web2py] Re: missing FROM-clause entry

2012-03-23 Thread Wikus van de Merwe
Just a blind guess but does this work any better?
query = (comment.id > 0) & (webpage.title == 'FAQ') & (comment.page_id == 
webpage.id) & (comment.id == comment_tags.comment_id) & (tag.id == 
comment_tags.tag_id) & (tag.label == 'Agree')
db(query).select()


[web2py] Re: Getting started in Web2py

2012-03-23 Thread Wikus van de Merwe
Don't use the web admin. It's for kids :P Copy welcome or example app and 
change the files directly.

For me the selling point of web2py was the simplicity of the syntax. See 
this comparison:
http://www.web2py.com/examples/static/web2py_vs_others.pdf



Re: [web2py] mistake by not using db.commit ()?

2012-03-23 Thread www.diazluis.com
Greetings sr.
Thanks for your time.

your explanation makes sense but ...

but I find it annoying to have to be running explicitly "db.commit ()"
something as simple as what you showed you

Waste time having to revise the code to see where failure to use "db.commit 
()" and so and keep it from bouncing an error like the one mentioned.

DAL internally in each operation should execute "db.commit ()" or something 
(I have no technical knowledge to give a solution working)


I justify the use of "db.commit ()"
* If my app estubiera overloaded with queries to the database
* Tubiera a background process working with the database
* Operations on the database from a cycle "for"

but NOT in the following steps:
  1) check if a record exists
2) create the record if necessary
3) re-check the registry, to be used in crud.update

I find that something is wrong



El viernes 23 de marzo de 2012 09:24:41 UTC-4:30, Richard escribió:
>
> Most of the time in web2py you don't need to commit, but in particular 
> scenario you maybe need to commit before an other operation because you 
> need the database to be up to date before the and of your function.
>
> http://web2py.com/books/​default/chapter/29/6?search=​db.commit%28%29
>
> Hope it helps
>
>
> The following code gives me error if not explicitly use db.commit ()
>> can someone explain why I now need to use db.commit () to something so 
>> simple?
>>
>> models/home.py
>>
>> ##
>> id_user = (auth.user and auth.user.id) or None
>>
>> db.define_table('home',
>>Field('titulo', 'string', length=64, default='titulo de prueba'),
>>Field('texto', 'text', length=5000, default='texto de prueba'),
>>Field('user', db.auth_user, default=id_user, writable=False,
>> readable=False),
>>
>>#auditoria
>>Field('ip', 'string', length=64,  default=request.client,
>> update=request.client, writable=False, readable=False),
>>Field('fecha', 'date',default=request.now, update=request.now,
>> writable=False, readable=False),
>>Field('user_update', db.auth_user, default=id_user,
>> update=id_user, writable=False, readable=False),
>> )
>> 
>>
>>
>> controllers/default.py
>> ##
>> def index():
>>
>>if auth.is_logged_in() :
>>home = db.home(user=id_user)
>>if home is None: redirect(URL('update'))
>>
>>return dict()
>>
>>
>> @auth.requires_login()
>> def update():
>>
>>home = db.home(user=id_user)
>>
>>if home is None:
>>home_id = db.home.insert(user=id_user)
>>else:
>>home_id = home.id
>>
>> #db.commit()
>>form = crud.update(db.home, home_id, deletable=False, 
>> next=URL('update'))
>>
>>return dict(home=home, form=form)
>> #
>>
>>
>> view/default/update.html
>>
>> {{extend 'layout.html'}}
>>
>>
>>{{ =home.titulo }}
>>
>>
>>{{=form.custom.begin}}
>>{{ =form.custom.widget.titulo }}
>>{{ =form.custom.widget.texto }}
>>
>>{{=form.custom.end}}
>>
>>
>> ###
>>
>>
>> Error
>> #
>>
>> web2py™ (1, 99, 7, datetime.datetime(2012, 3, 4, 22, 12, 8), 'stable')
>> Python  Python 2.6.6: /usr/bin/python
>> TRACEBACK
>>
>> Traceback (most recent call last):
>>  File "/home/diazluis2007/web2py/​gluon/restricted.py", line 205, in 
>> restricted
>>exec ccode in environment
>>  File 
>> "/home/diazluis2007/web2py/​applications/about/views/​default/update.html",
>> line 80, in 
>> AttributeError: 'NoneType' object has no attribute 'titulo'
>>
>>
>>
>> Díaz Luis
>> Analista Programador Facultad de Odontología UC
>> http://www.about.me/diazluis
>> User Linux 532223
>>
>
>

Re: [web2py] mistake by not using db.commit ()?

2012-03-23 Thread Anthony
In web2py, each request is wrapped in a single database transaction -- that 
way if an error occurs somewhere in the processing of the request, any 
database changes can be rolled back automatically. It would not be 
desirable to immediately commit each change (i.e., each insert, update, 
delete, etc.) by default because when an error occurs during a request, you 
could end up with only partial (and therefore inconsistent) changes. If you 
need more fine-grained, control, though, you can call db.commit() and 
db.rollback() as necessary.

Anthony

On Friday, March 23, 2012 12:58:22 PM UTC-4, www.diazluis.com wrote:
>
> Greetings sr.
> Thanks for your time.
>
> your explanation makes sense but ...
>
> but I find it annoying to have to be running explicitly "db.commit ()"
> something as simple as what you showed you
>
> Waste time having to revise the code to see where failure to use 
> "db.commit ()" and so and keep it from bouncing an error like the one 
> mentioned.
>
> DAL internally in each operation should execute "db.commit ()" or 
> something (I have no technical knowledge to give a solution working)
>
>
> I justify the use of "db.commit ()"
> * If my app estubiera overloaded with queries to the database
> * Tubiera a background process working with the database
> * Operations on the database from a cycle "for"
>
> but NOT in the following steps:
>   1) check if a record exists
> 2) create the record if necessary
> 3) re-check the registry, to be used in crud.update
>
> I find that something is wrong
>
>
>
> El viernes 23 de marzo de 2012 09:24:41 UTC-4:30, Richard escribió:
>>
>> Most of the time in web2py you don't need to commit, but in particular 
>> scenario you maybe need to commit before an other operation because you 
>> need the database to be up to date before the and of your function.
>>
>> http://web2py.com/books/​​default/chapter/29/6?search=​​db.commit%28%29
>>
>> Hope it helps
>>
>>
>> The following code gives me error if not explicitly use db.commit ()
>>> can someone explain why I now need to use db.commit () to something so 
>>> simple?
>>>
>>> models/home.py
>>>
>>> ##
>>> id_user = (auth.user and auth.user.id) or None
>>>
>>> db.define_table('home',
>>>Field('titulo', 'string', length=64, default='titulo de prueba'),
>>>Field('texto', 'text', length=5000, default='texto de prueba'),
>>>Field('user', db.auth_user, default=id_user, writable=False,
>>> readable=False),
>>>
>>>#auditoria
>>>Field('ip', 'string', length=64,  default=request.client,
>>> update=request.client, writable=False, readable=False),
>>>Field('fecha', 'date',default=request.now, update=request.now,
>>> writable=False, readable=False),
>>>Field('user_update', db.auth_user, default=id_user,
>>> update=id_user, writable=False, readable=False),
>>> )
>>> 
>>>
>>>
>>> controllers/default.py
>>> ##
>>> def index():
>>>
>>>if auth.is_logged_in() :
>>>home = db.home(user=id_user)
>>>if home is None: redirect(URL('update'))
>>>
>>>return dict()
>>>
>>>
>>> @auth.requires_login()
>>> def update():
>>>
>>>home = db.home(user=id_user)
>>>
>>>if home is None:
>>>home_id = db.home.insert(user=id_user)
>>>else:
>>>home_id = home.id
>>>
>>> #db.commit()
>>>form = crud.update(db.home, home_id, deletable=False, 
>>> next=URL('update'))
>>>
>>>return dict(home=home, form=form)
>>> #
>>>
>>>
>>> view/default/update.html
>>>
>>> {{extend 'layout.html'}}
>>>
>>>
>>>{{ =home.titulo }}
>>>
>>>
>>>{{=form.custom.begin}}
>>>{{ =form.custom.widget.titulo }}
>>>{{ =form.custom.widget.texto }}
>>>
>>>{{=form.custom.end}}
>>>
>>>
>>> ###
>>>
>>>
>>> Error
>>> #
>>>
>>> web2py™ (1, 99, 7, datetime.datetime(2012, 3, 4, 22, 12, 8), 'stable')
>>> Python  Python 2.6.6: /usr/bin/python
>>> TRACEBACK
>>>
>>> Traceback (most recent call last):
>>>  File "/home/diazluis2007/web2py/​​gluon/restricted.py", line 205, in 
>>> restricted
>>>exec ccode in environment
>>>  File 
>>> "/home/diazluis2007/web2py/​​applications/about/views/​​default/update.html",
>>> line 80, in 
>>> AttributeError: 'NoneType' object has no attribute 'titulo'
>>>
>>>
>>>
>>> Díaz Luis
>>> Analista Programador Facultad de Odontología UC
>>> http://www.about.me/diazluis
>>> User Linux 532223
>>>
>>
>>

Re: [web2py] Re: Getting started in Web2py

2012-03-23 Thread Vasile Ermicioi
Don't use the web admin. It's for kids :P Copy welcome or example app and
> change the files directly.
>
>
may be... but I rarely code outside of it :)


Re: [web2py] Re: Cookbook - No indentation ??

2012-03-23 Thread Jake Richter
Has a solution been found to get this in an ebook format with the correct
indentation?

On Sat, Mar 17, 2012 at 2:34 PM, Jonathan Lundell wrote:

> On Mar 17, 2012, at 11:22 AM, Marcello wrote:
>
> I screwed with nobody.
> I just pointed a fact.
>
> I have many Python eBooks(ePub) and ALL of them have NO formatting
> or indentation problem.
> Even Kindle has no indentation problem in all of my Python books.
>
>
> True; I've got plenty of tech books, both ePub and mobi, that handle
> indentation just fine.
>
>
>
> Marcello
>
>
>
> On Saturday, March 17, 2012 3:04:58 PM UTC-3, AngeloC wrote:
>>
>> Kindle and other ebook readers that doesn't support pdf are useless for
>> viewing technical documents because text is reflowable, always. So blanks
>> are removed and text is full aligned.
>>
>> Please don't screw with packtpub, amazon or others, is a common problem
>> with all reflowable mobile formats.
>>
>> I have an ebook reader that supports all mobile formats (BeBook One) and
>> pdf (non digital editions) is the only readable format for tech documents.
>> I read always on my bebook one!
>>
>> Publishers never says that, because they will not sell technical ebooks
>> anymore!
>>
>
>
>


[web2py] Re: bug in auth -- reset_password_onaccept doesn't exist ...

2012-03-23 Thread weheh
It does look that way ... doesn't it!? I expect to run into the same
issue with some of the other auth routines. I'm going to put them all
into modals and see how well it works. So given the structure of auth,
they are all going to need callbacks.

On Mar 23, 10:36 pm, Anthony  wrote:
> Congratulations, it appears you are the first person to need a reset
> password callback. :-)
>
>
>
>
>
>
>
> On Friday, March 23, 2012 2:11:13 AM UTC-4, weheh wrote:
>
> > I'm doing some more of this modal stuff for my login/password routines
> > and ran into this problem. Probably an oversight in the code (lots of
> > moving parts there!)
>
> > Traceback (most recent call last):
> >   File "N:\web2py\gluon\restricted.​py", line 204, in restricted
> >     exec ccode in environment
> >   File "N:/web2py/applications/myapp/​models/0_db_1_user.py", line 171,
> > in 
> >     auth.settings.reset_password_​onaccept =
> > [complete_request_reset_​password]
> >   File "N:\web2py\gluon\storage.py", line 196, in __setattr__
> >     raise SyntaxError, 'setting key \'%s\' does not exist' % key
> > SyntaxError: setting key 'reset_password_onaccept' does not exist


[web2py] Re: opinion -- modal login not what it could/should be

2012-03-23 Thread weheh
Hmm, I wasn't aware of auth.login_bare(). Will have to check it out.
As far as decorators are concerned, I have already begun tinkering
with a method like you mention, so we are on the same wavelength about
where to do it. I just have to figure out how. If I redirect to a
URL('default','index'), and that contains a response.js='ajax(blah
blah);', will the response.js get executed or will I need to do the
HTTP(200) trick again?

On Mar 23, 10:09 pm, Anthony  wrote:
> > After much tinkering with modal login, I'm formulating the following
> > opinions:
> > - modal login is a powerful and useful capability
> > - modal login is not well supported by web2py and not at all a
> > functionality that newbies would be able to implement easily.
>
> Sorry, I keep forgetting about
> auth.login_bare():http://web2py.com/books/default/chapter/29/9#Manual-Authentication.
> That might be a better way to go when implementing something like a modal
> login. You can control all the logic regarding displaying the login form,
> submitting credentials, returning responses, etc., and just use
> auth.login_bare() to check the credentials and update auth.user upon
> successful login. Then you don't have to worry about working around the
> automatic redirects in auth.login().
>
>  For instance, if you decorate with
>
> > @auth.requires_login(), then you're going to run into trouble. That's
> > because you'll be redirected to a login page, which doesn't exist.
> > - the implementation of auth does not natively support components.
>
> This can get tricky. When the browser requests a URL that happens to be
> decorated with @auth.requires_login(), it may be requesting a full page
> (i.e., not just an Ajax response), so the action has to return a full page.
> If the user isn't logged in, what page should be returned in that case
> (given that there is no dedicated login page)? One option might be
> something like this:
>
> auth.settings.login_url = URL('default', 'index', vars=dict(login='true'))
>
> Then, on the index page, include some JS that checks the URL query string
> upon page load, and if it includes "login=true", pop up the login modal.
>
> Another option is to have a dedicated login page in addition to the modal
> login. Use the modal when the user explicitly chooses to login, but use the
> login page when you have to redirect from a protected URL. I think that's a
> fairly common approach.
>
> Anthony


Re: [web2py] Re: Spatial / GIS support in DAL

2012-03-23 Thread Fran
On Wednesday, 21 March 2012 21:35:32 UTC, Manuele wrote:
>
> For inserting geometries in database using new DAL features 
> you need WKT format and not WKB... every library I found support 
> exporting WKB (osgeo.ogr, Shapely, ppygis) but none seams to export WKT 
> format.
>

Shapely can export WKT:
http://toblerity.github.com/shapely/manual.html#well-known-formats

F 


[web2py] Re: opinion -- modal login not what it could/should be

2012-03-23 Thread Anthony

>
> If I redirect to a 
> URL('default','index'), and that contains a response.js='ajax(blah 
> blah);', will the response.js get executed or will I need to do the 
> HTTP(200) trick again?
>

Yes, if you redirect to a particular URL, once the URL is requested by the 
browser, everything should work as it would have if the URL had been 
requested directly.

Anthony


Re: [web2py] mistake by not using db.commit ()?

2012-03-23 Thread www.diazluis.com
sr. antonio has every reason
after analyzing its response, the reasons are obvious DAL designed.

the end the error of my logic (I apologize)

missing return to the query of the data, after creating the record, I mean:

if home is None:
db.home.insert home_id = (user = id_user)
db.home home = (user = id_user)
else:
home_id = home.id

and the system returns in view as follows:
return dict (home=home, form=form)



El viernes 23 de marzo de 2012 12:59:50 UTC-4:30, Anthony escribió:
>
> In web2py, each request is wrapped in a single database transaction -- 
> that way if an error occurs somewhere in the processing of the request, any 
> database changes can be rolled back automatically. It would not be 
> desirable to immediately commit each change (i.e., each insert, update, 
> delete, etc.) by default because when an error occurs during a request, you 
> could end up with only partial (and therefore inconsistent) changes. If you 
> need more fine-grained, control, though, you can call db.commit() and 
> db.rollback() as necessary.
>
> Anthony
>
> On Friday, March 23, 2012 12:58:22 PM UTC-4, www.diazluis.com wrote:
>>
>> Greetings sr.
>> Thanks for your time.
>>
>> your explanation makes sense but ...
>>
>> but I find it annoying to have to be running explicitly "db.commit ()"
>> something as simple as what you showed you
>>
>> Waste time having to revise the code to see where failure to use 
>> "db.commit ()" and so and keep it from bouncing an error like the one 
>> mentioned.
>>
>> DAL internally in each operation should execute "db.commit ()" or 
>> something (I have no technical knowledge to give a solution working)
>>
>>
>> I justify the use of "db.commit ()"
>> * If my app estubiera overloaded with queries to the database
>> * Tubiera a background process working with the database
>> * Operations on the database from a cycle "for"
>>
>> but NOT in the following steps:
>>   1) check if a record exists
>> 2) create the record if necessary
>> 3) re-check the registry, to be used in crud.update
>>
>> I find that something is wrong
>>
>>
>>
>> El viernes 23 de marzo de 2012 09:24:41 UTC-4:30, Richard escribió:
>>>
>>> Most of the time in web2py you don't need to commit, but in particular 
>>> scenario you maybe need to commit before an other operation because you 
>>> need the database to be up to date before the and of your function.
>>>
>>> http://web2py.com/books/​​​default/chapter/29/6?search=​​​db.commit%28%29
>>>
>>> Hope it helps
>>>
>>>
>>> The following code gives me error if not explicitly use db.commit ()
 can someone explain why I now need to use db.commit () to something so 
 simple?

 models/home.py

 ##
 id_user = (auth.user and auth.user.id) or None

 db.define_table('home',
Field('titulo', 'string', length=64, default='titulo de prueba'),
Field('texto', 'text', length=5000, default='texto de prueba'),
Field('user', db.auth_user, default=id_user, writable=False,
 readable=False),

#auditoria
Field('ip', 'string', length=64,  default=request.client,
 update=request.client, writable=False, readable=False),
Field('fecha', 'date',default=request.now, update=request.now,
 writable=False, readable=False),
Field('user_update', db.auth_user, default=id_user,
 update=id_user, writable=False, readable=False),
 )
 


 controllers/default.py
 ##
 def index():

if auth.is_logged_in() :
home = db.home(user=id_user)
if home is None: redirect(URL('update'))

return dict()


 @auth.requires_login()
 def update():

home = db.home(user=id_user)

if home is None:
home_id = db.home.insert(user=id_user)
else:
home_id = home.id

 #db.commit()
form = crud.update(db.home, home_id, deletable=False, 
 next=URL('update'))

return dict(home=home, form=form)
 #


 view/default/update.html

 {{extend 'layout.html'}}


{{ =home.titulo }}


{{=form.custom.begin}}
{{ =form.custom.widget.titulo }}
{{ =form.custom.widget.texto }}

{{=form.custom.end}}


 ###


 Error
 #

 web2py™ (1, 99, 7, datetime.datetime(2012, 3, 4, 22, 12, 8), 'stable')
 Python  Python 2.6.6: /usr/bin/python
 TRACEBACK

 Traceback (most recent call last):
  File "/home/diazluis2007/web2py/​​​gluon/restricted.py", line 205, in 
 restricted
exec ccode in environment
  File 
 "/home/diazluis2007/web2py/​​​applications/about/views/​​​default/update.html",
 line 80, in 
 AttributeError: 'NoneType' objec

Re: [web2py] mistake by not using db.commit ()?

2012-03-23 Thread www.diazluis.com
if home is None: 
home_id = db.home.insert(user=id_user)
home = db.home(user=id_user)
else:
home_id = home.id

I google translator flip the code :S


El viernes 23 de marzo de 2012 13:31:13 UTC-4:30, www.diazluis.com escribió:
>
> sr. antonio has every reason
> after analyzing its response, the reasons are obvious DAL designed.
>
> the end the error of my logic (I apologize)
>
> missing return to the query of the data, after creating the record, I mean:
>
> if home is None:
> db.home.insert home_id = (user = id_user)
> db.home home = (user = id_user)
> else:
> home_id = home.id
>
> and the system returns in view as follows:
> return dict (home=home, form=form)
>
>
>
> El viernes 23 de marzo de 2012 12:59:50 UTC-4:30, Anthony escribió:
>>
>> In web2py, each request is wrapped in a single database transaction -- 
>> that way if an error occurs somewhere in the processing of the request, any 
>> database changes can be rolled back automatically. It would not be 
>> desirable to immediately commit each change (i.e., each insert, update, 
>> delete, etc.) by default because when an error occurs during a request, you 
>> could end up with only partial (and therefore inconsistent) changes. If you 
>> need more fine-grained, control, though, you can call db.commit() and 
>> db.rollback() as necessary.
>>
>> Anthony
>>
>> On Friday, March 23, 2012 12:58:22 PM UTC-4, www.diazluis.com wrote:
>>>
>>> Greetings sr.
>>> Thanks for your time.
>>>
>>> your explanation makes sense but ...
>>>
>>> but I find it annoying to have to be running explicitly "db.commit ()"
>>> something as simple as what you showed you
>>>
>>> Waste time having to revise the code to see where failure to use 
>>> "db.commit ()" and so and keep it from bouncing an error like the one 
>>> mentioned.
>>>
>>> DAL internally in each operation should execute "db.commit ()" or 
>>> something (I have no technical knowledge to give a solution working)
>>>
>>>
>>> I justify the use of "db.commit ()"
>>> * If my app estubiera overloaded with queries to the database
>>> * Tubiera a background process working with the database
>>> * Operations on the database from a cycle "for"
>>>
>>> but NOT in the following steps:
>>>   1) check if a record exists
>>> 2) create the record if necessary
>>> 3) re-check the registry, to be used in crud.update
>>>
>>> I find that something is wrong
>>>
>>>
>>>
>>> El viernes 23 de marzo de 2012 09:24:41 UTC-4:30, Richard escribió:

 Most of the time in web2py you don't need to commit, but in particular 
 scenario you maybe need to commit before an other operation because you 
 need the database to be up to date before the and of your function.


 http://web2py.com/books/default/chapter/29/6?search=db.commit%28%29

 Hope it helps


 The following code gives me error if not explicitly use db.commit ()
> can someone explain why I now need to use db.commit () to something so 
> simple?
>
> models/home.py
>
> ##
> id_user = (auth.user and auth.user.id) or None
>
> db.define_table('home',
>Field('titulo', 'string', length=64, default='titulo de prueba'),
>Field('texto', 'text', length=5000, default='texto de prueba'),
>Field('user', db.auth_user, default=id_user, writable=False,
> readable=False),
>
>#auditoria
>Field('ip', 'string', length=64,  default=request.client,
> update=request.client, writable=False, readable=False),
>Field('fecha', 'date',default=request.now, update=request.now,
> writable=False, readable=False),
>Field('user_update', db.auth_user, default=id_user,
> update=id_user, writable=False, readable=False),
> )
> 
>
>
> controllers/default.py
> ##
> def index():
>
>if auth.is_logged_in() :
>home = db.home(user=id_user)
>if home is None: redirect(URL('update'))
>
>return dict()
>
>
> @auth.requires_login()
> def update():
>
>home = db.home(user=id_user)
>
>if home is None:
>home_id = db.home.insert(user=id_user)
>else:
>home_id = home.id
>
> #db.commit()
>form = crud.update(db.home, home_id, deletable=False, 
> next=URL('update'))
>
>return dict(home=home, form=form)
> #
>
>
> view/default/update.html
>
> {{extend 'layout.html'}}
>
>
>{{ =home.titulo }}
>
>
>{{=form.custom.begin}}
>{{ =form.custom.widget.titulo }}
>{{ =form.custom.widget.texto }}
>
>{{=form.custom.end}}
>
>
> ###
>
>
> Error
> #
>
> web2py™ (1, 99, 7, dat

[web2py] SQLFORM.grid many2many name of referenced table instead of id

2012-03-23 Thread jep
Is it possible to show the referenced name field, instead of the id
when showing a grid of a many2many table?


my model:

tsmadm.define_table('report_contact',
Field ('report_id', db.reports,
requires=IS_IN_DB(db, db.reports.id,'%(name)s')   ),
Field ('contact_id',   db.contacts,
requires=IS_IN_DB(db, db.contacts.id,'%(name)s')  ),
)


my controller:

def reportcontact():
gridquery=(rc.report_id==int(request.vars.rid))
grid = SQLFORM.grid(gridquery,)
return dict(grid=grid)

result looks like

idreport_id   contact_id
1 1  2view edit delete
3 1  1view edit delete


As you can see the numbers don't give me any information, i would like
to see

In other forms, taken from the model, i get drop downs based on the
name.

I would expect the default view of this grid would also show the
names, instead of the id's   -  taken from the model (requires
IS_IN_DB).


Jean-Paul



Re: [web2py] DAL / connection pool leaking objects?

2012-03-23 Thread nick name

On Friday, March 23, 2012 10:21:07 AM UTC-4, Richard wrote:
>
> Why are you doing that?
>
> Richard
>

A legacy system, which has stand-alone appservers+databases in 
geographically distributed locations, with intermittent and low bandwidth 
connections (think mobile GPRS modems for the kind and quality).

I'm building a management system that keeps a complete view of the system. 
This is done by:
1) a web2py app installed on the legacy system maintains an up-to-date 
sqlite copy of the existing legacy (postgres) database.
2) this database (.sqlite and .table definitions) is copied to the main 
management system when bandwidth and connectivity allows it, and placed in 
its own directory.
3) management system reads all independent databases, consolidates them, 
computes some data, and makes it available (.sqlite and .table) for 
standalone appservers to download when they can
4) standalone web2py appservers download updated version when they get a 
chance, open it and use the aspects of the consolidated data that they need.

*THIS IS NOT MY USE CASE*, but an essentially equivalent example is "ice 
cream truck network". Each truck runs its own inventory. Center keeps an 
updated view of all inventories, summarizes them, and sends back to trucks. 
So if you come to a truck on 20th street, and they are out of your favorite 
ice cream flavor, they can point you to the nearest truck that (as of the 
last update) had that flavour; 

All information is available on an as-available-and-possible-to-transfer 
basis.

The original version of my code exported to csv, sent with http, and 
imported at the other end. The new code is much simpler, more efficient and 
more robust -- but brought up this snag.


[web2py] breakpoints + Eclipse + Web2Py

2012-03-23 Thread web2py_tn
Hi guys- I sat up my Aptana Studio and loaded a web2py project that has 
breakpoints in it. I ran web2py.py in a debug more and for some reason, it 
doesn't stop at the breakpoints.
If I create a new python project with breakpoints, it works perfectly fine.

can you guys help?


Re: [web2py] Getting started in Web2py

2012-03-23 Thread Jim Steil

This is a nice resource as well...

http://killer-web-development.com/

-Jim

On 3/22/2012 11:15 PM, SeamusJP wrote:

Hi,
 I am developing a new project, new to python. Project is mainly for 
CRUD, display data on website, and easy management of back end. I 
started Djangobook and finished it, I felt like it was great and I 
could go in to eclipse, create my models, validate, and then make my 
forms on site..pretty simple (Although I am sure I am missing something).
 Then I came to find Web2py, initially, I am super stoked about it, 
however I can't seem to mesh with the documentation very well. Maybe I 
am missing something. I feel like djangobook held my hand and spoke 
about the main concepts of django, but in web2py, it jumps right into 
these super long pages , and don't really explain whats happening in 
the back. Also, I am running web2py on my machine, ubuntu, as well as 
another win7 machine. It feels sluggish. Anyone else experience this? 
Is this whe web based IDE causing it? Its difficult to switch through 
browser tabs / windows to make changes to things, validate errors, 
read the book..It just felt like django + eclipse + djangobook + 
terminalx was easier to manipulate. I could use terminal to quickly 
validate things and find errors, which djangobook explained thouroughly.
 I recently went on to IRC and was told to look at the Vimeo videos. 
The first one just jumped into features, and did not seem like a in 
depth tutorial. I really want to use Web2py, I think it will make my 
life easier when deploying apps, creating forms quickly, etc, but it 
just doesnt feel streamlined, I feel like alt tabbing and inputting 
code makes me wait longer than I had to in eclipse. I am having these 
weird issues getting it going. Anyone experience anything like this? 
Should I just push through it ?


[web2py] Re: SQLFORM.grid many2many name of referenced table instead of id

2012-03-23 Thread Anthony

>
> I would expect the default view of this grid would also show the 
> names, instead of the id's   -  taken from the model (requires 
> IS_IN_DB).


The IS_IN_DB validator will result in the "name" field being showing in 
select widgets, but it won't affect the field representation in 
tables/grids. For that, you have to specify the "represent" attribute of 
the field. Note, if the referenced table includes a "_format" attribute 
(set via the "format" argument to define_table), then the "represent" 
attribute of the reference field will be set automatically (in that case, 
the IS_IN_DB validator will also be set automatically). So, just do the 
following:

tsmadm.define_table('reports', ..., format='%(name)s')
tsmadm.define_table('contacts', ..., format='%(name)s')
tsmadm.define_table('report_​contact', 
Field('report_id', db.reports), 
Field('contact_id', db.contacts))

That will automatically add the IS_IN_DB validator to the two reference 
fields as well as set their "represent" attribute to display the "name" 
field of the referenced record.

I also recommend having a look at http://www.python.org/dev/peps/pep-0008/ 
regarding Python code formatting.

Anthony


[web2py] Re: missing FROM-clause entry

2012-03-23 Thread Limedrop
Thanks for your suggestion...it pointed me in the right direction.

It turns out the issue is not with the query construction, but that
DAL handles string input differently to objects.  What I am trying to
do is take a Query and then convert it to a string so it can be saved
in the session.  The string can then be pulled from the session and
converted back into a Query.  This works for simple queries, but not
for queries with implicit joins.  See the difference:


>>>from gluon.dal import Query
>>>query = (db.comment.id > 0) & (db.webpage.title == 'FAQ') & 
>>>(db.comment.page_id == db.webpage.id)
>>>query_as_string = str(query)
>>>query_from_string = Query(db, query_as_string)
>>>db(query)._select(db.comment.body)
"SELECT  comment.body FROM comment, webpage WHERE (((comment.id > 0)
AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id));"
>>>db(query_from_string)._select(db.comment.body)
"SELECT  comment.body FROM comment WHERE comment.id > 0) AND
(webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)));"

Does anyone know how to convert a Query to a string (so it can be
saved in the session) and then get it back again?


On Mar 24, 4:52 am, Wikus van de Merwe 
wrote:
> Just a blind guess but does this work any better?
> query = (comment.id > 0) & (webpage.title == 'FAQ') & (comment.page_id ==
> webpage.id) & (comment.id == comment_tags.comment_id) & (tag.id ==
> comment_tags.tag_id) & (tag.label == 'Agree')
> db(query).select()


[web2py] Cookbook Chapter 2 - Reddit clone Ajax problem

2012-03-23 Thread Omi Chiba
I was following cookbook and having a problem for the ajax part. I can 
click plus or minus to change the value for the first time, but it doesn't 
update the value next time it's clicked. Also, I don't get any flash 
message like 'you voted already' or 'vote recorded'.

What am I missing ?


Controller
---
def news_comments():
news = db.news(request.args(0)) or redirect(URL('categories'))
if auth.user:
db.comment.news.default = news.id
db.comment.posted_on.default = request.now
db.comment.posted_by.default = auth.user.id
form = crud.create(db.comment)
comments = 
db(db.comment.news==news.id).select(orderby=db.comment.posted_on)
return locals()

@auth.requires_login()
def vote():
if not request.env.request_method=='POST': raise HTTP(400)
news_id, mode = request.args(0), request.args(1)
news = db.news(id=news_id)
vote = db.vote(posted_by=auth.user.id, news=news_id)
votes = news.votes
value = (mode=='plus') and +1 or -1
if vote and value*vote.value==1:
message = 'you voted already'
else:
if vote:
votes += value - vote.value
vote.update_record(value=value)
else:
votes += value
db.vote.insert(value=value, posted_by=auth.user.id, 
posted_on=request.now, news=news.id)
news.update_record(votes=votes)
message ='vote recorded'
return "jQuery('#votes').html('%s');jQuery('.flash').\
html('%s').slideDown();" % (votes, message)

View - news_comment.html
-
{{extend 'layout.html'}}
{{=A(news.title, _href=news.link)}}
{{if auth.user:}}
{{=news.votes}}
plus
minus
{{=form}}
{{pass}}

{{for comment in comments:}}

{{=comment.posted_on}}
{{=comment.posted_by.first_name}}: 
{{=MARKMIN(comment.body)}}

{{pass}}




[web2py] Re: Getting started in Web2py

2012-03-23 Thread monotasker
I think I understand a bit what you mean about not feeling like you 
understand the "guts" of web2py at first. The book wants to walk you 
through app-building before introducing you to much of the core, even 
conceptually. I think this is actually a good pedagogical move for lots of 
people, but for those of us who are used to understanding our tools before 
we use them it can feel awkward. Because the web2py community is younger 
(and so smaller) there aren't the variety of solid books that take slightly 
different approaches. So far Massimo's tome has to try to be all things to 
all people. I think that situation is already changing but I'd encourage 
you not to let it influence your choice of framework too much.

If I were starting web2py over again, I would actually start with the 
chapter on the "core" and then read the chapter on the DAL. But I'm finding 
that the elegance and completeness of web2py makes it well worth the 
effort. And the community here on the Google group (Massimo included) is so 
responsive that I've never been stuck for long. 

On the sluggishness issue, I also find the web-ide pretty unresponsive. 
I've used pyCharm happily for a while with web2py, although it doesn't mesh 
quite as easily as WingIDE does. At the moment I'm just using favourite 
text editor (Sublime Text 2 because I'm a sucker for aesthetics, Geany when 
my open-source conscience wins out). But having the web-ide available has 
sometimes been helpful in emergencies or for small experiments.

Cheers,

Ian

On Friday, March 23, 2012 12:15:27 AM UTC-4, SeamusJP wrote:
>
> Hi,
>  I am developing a new project, new to python. Project is mainly for CRUD, 
> display data on website, and easy management of back end. I started 
> Djangobook and finished it, I felt like it was great and I could go in to 
> eclipse, create my models, validate, and then make my forms on site..pretty 
> simple (Although I am sure I am missing something).
>  Then I came to find Web2py, initially, I am super stoked about it, 
> however I can't seem to mesh with the documentation very well. Maybe I am 
> missing something. I feel like djangobook held my hand and spoke about the 
> main concepts of django, but in web2py, it jumps right into these super 
> long pages , and don't really explain whats happening in the back. Also, I 
> am running web2py on my machine, ubuntu, as well as another win7 machine. 
> It feels sluggish. Anyone else experience this? Is this whe web based IDE 
> causing it? Its difficult to switch through browser tabs / windows to make 
> changes to things, validate errors, read the book..It just felt like django 
> + eclipse + djangobook + terminalx was easier to manipulate. I could use 
> terminal to quickly validate things and find errors, which djangobook 
> explained thouroughly.
>  I recently went on to IRC and was told to look at the Vimeo videos. The 
> first one just jumped into features, and did not seem like a in depth 
> tutorial. I really want to use Web2py, I think it will make my life easier 
> when deploying apps, creating forms quickly, etc, but it just doesnt feel 
> streamlined, I feel like alt tabbing and inputting code makes me wait 
> longer than I had to in eclipse. I am having these weird issues getting it 
> going. Anyone experience anything like this? Should I just push through it 
> ? 
>


[web2py] Re: missing FROM-clause entry

2012-03-23 Thread monotasker
I may be off target but I just recently noticed the .as_dict() method for 
rows objects. This converts the rows object to a regular dict (instead of a 
gluon storage object) which can be stored in session or cache (i.e., it's 
picklable). If you need the query (not the resulting rows object) to be 
stored this doesn't help, but if it works in your case to store the 
select() result this may actually be easier.

Ian

On Friday, March 23, 2012 4:49:23 PM UTC-4, Limedrop wrote:
>
> Thanks for your suggestion...it pointed me in the right direction. 
>
> It turns out the issue is not with the query construction, but that 
> DAL handles string input differently to objects.  What I am trying to 
> do is take a Query and then convert it to a string so it can be saved 
> in the session.  The string can then be pulled from the session and 
> converted back into a Query.  This works for simple queries, but not 
> for queries with implicit joins.  See the difference: 
>
>
> >>>from gluon.dal import Query 
> >>>query = (db.comment.id > 0) & (db.webpage.title == 'FAQ') & 
> (db.comment.page_id == db.webpage.id) 
> >>>query_as_string = str(query) 
> >>>query_from_string = Query(db, query_as_string) 
> >>>db(query)._select(db.​comment.body) 
> "SELECT  comment.body FROM comment, webpage WHERE (((comment.id > 0) 
> AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id));" 
> >>>db(query_from_string)._​select(db.comment.body) 
> "SELECT  comment.body FROM comment WHERE comment.id > 0) AND 
> (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)));" 
>
> Does anyone know how to convert a Query to a string (so it can be 
> saved in the session) and then get it back again? 
>
>
> On Mar 24, 4:52 am, Wikus van de Merwe  
> wrote: 
> > Just a blind guess but does this work any better? 
> > query = (comment.id > 0) & (webpage.title == 'FAQ') & (comment.page_id 
> == 
> > webpage.id) & (comment.id == comment_tags.comment_id) & (tag.id == 
> > comment_tags.tag_id) & (tag.label == 'Agree') 
> > db(query).select()



[web2py] can web2py have a place in an 'html5 app' environment?

2012-03-23 Thread monotasker
I've been struck by the huge push lately for 'html5 apps' as a (partly) 
cross-platform approach to mobile and desktop development. Now win8 is 
integrating html5+js heafily into the desktop and the Mozilla app project 
is pushing in a similar direction. In many ways I think it makes sense (I 
find css, for all its shortcomings, a lot nicer to deal with than qt or 
gtk). But where does it leave a framework like web2py? It seems to me that 
part of the html5 push comes from developers' reluctance to learn a 
server-side language well (even php). If we have jquery and indexed local 
storage in the browser, then people can do a lot with simple tools. I think 
this is a mirage in many ways. At the same time, I would like to think that 
I could benefit from the strengths of web2py (and python in general) and 
still, say, develop an app for Mozilla's upcoming app store. Has anyone 
been thinking about this? Is there room in things like the win8 api or the 
Mozilla app api to use web2py? If not, how difficult would it be to create 
bindings and an api to be included in gluon? Could the DAL be extended to 
work with browser-based local storage? Or should we see web2py as a 
traditional server-client framework only?

Ian


[web2py] Re: missing FROM-clause entry

2012-03-23 Thread Anthony
On Friday, March 23, 2012 5:36:28 PM UTC-4, monotasker wrote:
>
> I may be off target but I just recently noticed the .as_dict() method for 
> rows objects. This converts the rows object to a regular dict (instead of a 
> gluon storage object) which can be stored in session or cache (i.e., it's 
> picklable). If you need the query (not the resulting rows object) to be 
> stored this doesn't help, but if it works in your case to store the 
> select() result this may actually be easier.
>

There is also an .as_list() method, which converts to a list of 
dictionaries rather than a dictionary of dictionaries. You can also just 
store Rows objects directly in the session or cache -- the DAL defines a 
reduction function that calls the .as_list() method when a Rows object is 
pickled, so you don't have to call the method manually.

Anthony


[web2py] Re: can web2py have a place in an 'html5 app' environment?

2012-03-23 Thread Derek
It's a server-client framework only. Your question does not make sense 
because html5+js+local storage = client. This is a server application. If 
you want to integrate localstorage, you're developing a client app, and 
thus there is no need for a server framework such as web2py. You could do 
all of that in your layout as easily as you could do anything else.

Now, let's take an example app that is normally server-side and design it 
as an html5 client app, as an example, let's choose an RSS reader, for 
example.
Your current (non-html5) app parses the rss files on the server, converts 
it to html and displays it on the browser. The only things you have stored 
in the database is the login, and urls for the rss files that the user 
would like to access.

Your html5 app (+web2py) would work like this:
login to the webapp (server) the first time. this will present your (client 
side) app - which will connect to the server, retrieve the json for the rss 
feeds, and saves the json into local storage, then displays what's in local 
storage based on javascript templates. 

The only advantage you'd get with an app like this is you can use it while 
you are disconnected from the network. 

But what would be better is to rewrite it so it will retrieve the rss feeds 
directly. Then you don't need the web2py piece at all.

And that's my point.
On Friday, March 23, 2012 2:53:15 PM UTC-7, monotasker wrote:
>
> I've been struck by the huge push lately for 'html5 apps' as a (partly) 
> cross-platform approach to mobile and desktop development. Now win8 is 
> integrating html5+js heafily into the desktop and the Mozilla app project 
> is pushing in a similar direction. In many ways I think it makes sense (I 
> find css, for all its shortcomings, a lot nicer to deal with than qt or 
> gtk). But where does it leave a framework like web2py? It seems to me that 
> part of the html5 push comes from developers' reluctance to learn a 
> server-side language well (even php). If we have jquery and indexed local 
> storage in the browser, then people can do a lot with simple tools. I think 
> this is a mirage in many ways. At the same time, I would like to think that 
> I could benefit from the strengths of web2py (and python in general) and 
> still, say, develop an app for Mozilla's upcoming app store. Has anyone 
> been thinking about this? Is there room in things like the win8 api or the 
> Mozilla app api to use web2py? If not, how difficult would it be to create 
> bindings and an api to be included in gluon? Could the DAL be extended to 
> work with browser-based local storage? Or should we see web2py as a 
> traditional server-client framework only?
>
> Ian
>


[web2py] Re: Cookbook Chapter 2 - Reddit clone Ajax problem

2012-03-23 Thread Alan Etkin
I tested the example app with the book support files and it worked
(with Firefox 10 and web2py trunk). Maybe there is a bug fixed in the
app code that was not updated in the book's text.

On 23 mar, 18:11, Omi Chiba  wrote:
> I was following cookbook and having a problem for the ajax part. I can
> click plus or minus to change the value for the first time, but it doesn't
> update the value next time it's clicked. Also, I don't get any flash
> message like 'you voted already' or 'vote recorded'.
>
> What am I missing ?
>
> Controller
> ---
> def news_comments():
>     news = db.news(request.args(0)) or redirect(URL('categories'))
>     if auth.user:
>         db.comment.news.default = news.id
>         db.comment.posted_on.default = request.now
>         db.comment.posted_by.default = auth.user.id
>         form = crud.create(db.comment)
>     comments =
> db(db.comment.news==news.id).select(orderby=db.comment.posted_on)
>     return locals()
>
> @auth.requires_login()
> def vote():
>     if not request.env.request_method=='POST': raise HTTP(400)
>     news_id, mode = request.args(0), request.args(1)
>     news = db.news(id=news_id)
>     vote = db.vote(posted_by=auth.user.id, news=news_id)
>     votes = news.votes
>     value = (mode=='plus') and +1 or -1
>     if vote and value*vote.value==1:
>         message = 'you voted already'
>     else:
>         if vote:
>             votes += value - vote.value
>             vote.update_record(value=value)
>         else:
>             votes += value
>             db.vote.insert(value=value, posted_by=auth.user.id,
> posted_on=request.now, news=news.id)
>             news.update_record(votes=votes)
>             message ='vote recorded'
>         return "jQuery('#votes').html('%s');jQuery('.flash').\
>                 html('%s').slideDown();" % (votes, message)
>
> View - news_comment.html
> -
> {{extend 'layout.html'}}
> {{=A(news.title, _href=news.link)}}
> {{if auth.user:}}
> {{=news.votes}}
> plus
> minus
> {{=form}}
> {{pass}}
> 
> {{for comment in comments:}}
> 
>     {{=comment.posted_on}}
>     {{=comment.posted_by.first_name}}: 
>     {{=MARKMIN(comment.body)}}
> 
> {{pass}}
> 


[web2py] Re: can web2py have a place in an 'html5 app' environment?

2012-03-23 Thread monotasker
Right. For something as simple as an RSS reader I see your point. But for 
more complex applications (I'm working on a web-based educational game for 
language instruction) I think the gluon libraries offer more than this. The 
DAL greatly simplifies the process of working with a db, and to the extent 
that indexed client-side storage becomes the norm the DAL could certainly 
help with that. On the other hand, web2py allows us to write complex 
business logic in python rather than being forced to use js. I know that 
some people write large applications with jquery, but for larger apps I 
would much prefer writing in python. So web2py provides an MVC framework 
for organizing the application (like, say, backbone.js would) as well as 
providing all of the html helper objects. 

I realize that, as it stands, web2py requires a server to run and is based 
on a traditional server-client model. My question is, could we take 
advantage of the benefits of web2py in a local environment when other web 
technologies are moving rapidly into local environments. If I code an html5 
app for win8 or for Mozilla's app store I would like the business logic to 
be in python if that turns out to be a possibility. So could web2py provide 
a framework for that, and if so how much work would it take to 
implement/adapt. After all, web2py already includes the ability to generate 
desktop executables with a freestanding local server.

Ian


On Friday, March 23, 2012 6:14:34 PM UTC-4, Derek wrote:
>
> It's a server-client framework only. Your question does not make sense 
> because html5+js+local storage = client. This is a server application. If 
> you want to integrate localstorage, you're developing a client app, and 
> thus there is no need for a server framework such as web2py. You could do 
> all of that in your layout as easily as you could do anything else.
>
> Now, let's take an example app that is normally server-side and design it 
> as an html5 client app, as an example, let's choose an RSS reader, for 
> example.
> Your current (non-html5) app parses the rss files on the server, converts 
> it to html and displays it on the browser. The only things you have stored 
> in the database is the login, and urls for the rss files that the user 
> would like to access.
>
> Your html5 app (+web2py) would work like this:
> login to the webapp (server) the first time. this will present your 
> (client side) app - which will connect to the server, retrieve the json for 
> the rss feeds, and saves the json into local storage, then displays what's 
> in local storage based on javascript templates. 
>
> The only advantage you'd get with an app like this is you can use it while 
> you are disconnected from the network. 
>
> But what would be better is to rewrite it so it will retrieve the rss 
> feeds directly. Then you don't need the web2py piece at all.
>
> And that's my point.
> On Friday, March 23, 2012 2:53:15 PM UTC-7, monotasker wrote:
>>
>> I've been struck by the huge push lately for 'html5 apps' as a (partly) 
>> cross-platform approach to mobile and desktop development. Now win8 is 
>> integrating html5+js heafily into the desktop and the Mozilla app project 
>> is pushing in a similar direction. In many ways I think it makes sense (I 
>> find css, for all its shortcomings, a lot nicer to deal with than qt or 
>> gtk). But where does it leave a framework like web2py? It seems to me that 
>> part of the html5 push comes from developers' reluctance to learn a 
>> server-side language well (even php). If we have jquery and indexed local 
>> storage in the browser, then people can do a lot with simple tools. I think 
>> this is a mirage in many ways. At the same time, I would like to think that 
>> I could benefit from the strengths of web2py (and python in general) and 
>> still, say, develop an app for Mozilla's upcoming app store. Has anyone 
>> been thinking about this? Is there room in things like the win8 api or the 
>> Mozilla app api to use web2py? If not, how difficult would it be to create 
>> bindings and an api to be included in gluon? Could the DAL be extended to 
>> work with browser-based local storage? Or should we see web2py as a 
>> traditional server-client framework only?
>>
>> Ian
>>
>

[web2py] Re: breakpoints + Eclipse + Web2Py

2012-03-23 Thread dlypka
I believe you must delete all .pyc files before running it with
breakpoints.

On Mar 23, 1:18 pm, web2py_tn  wrote:
> Hi guys- I sat up my Aptana Studio and loaded a web2py project that has
> breakpoints in it. I ran web2py.py in a debug more and for some reason, it
> doesn't stop at the breakpoints.
> If I create a new python project with breakpoints, it works perfectly fine.
>
> can you guys help?


[web2py] Re: can web2py have a place in an 'html5 app' environment?

2012-03-23 Thread Derek
DAL is not going to help any client side storage, it's for server storage. 
DAL isn't going to help with any storage client-side. Only your views would 
help here.
Python won't run client side, not unless you have Pyjamas, but then you 
don't have an HTML5 WebApp, you have a Pyjamas webapp. That may be what you 
are looking for. The way I see it, I would not want Web2Py turning into 
another Pyjamas. Pyjamas has it's place, Web2Py has it's own place, and 
remember one of the keys to Web2Py is DRY.

On Friday, March 23, 2012 3:34:27 PM UTC-7, monotasker wrote:
>
> Right. For something as simple as an RSS reader I see your point. But for 
> more complex applications (I'm working on a web-based educational game for 
> language instruction) I think the gluon libraries offer more than this. The 
> DAL greatly simplifies the process of working with a db, and to the extent 
> that indexed client-side storage becomes the norm the DAL could certainly 
> help with that. On the other hand, web2py allows us to write complex 
> business logic in python rather than being forced to use js. I know that 
> some people write large applications with jquery, but for larger apps I 
> would much prefer writing in python. So web2py provides an MVC framework 
> for organizing the application (like, say, backbone.js would) as well as 
> providing all of the html helper objects. 
>
> I realize that, as it stands, web2py requires a server to run and is based 
> on a traditional server-client model. My question is, could we take 
> advantage of the benefits of web2py in a local environment when other web 
> technologies are moving rapidly into local environments. If I code an html5 
> app for win8 or for Mozilla's app store I would like the business logic to 
> be in python if that turns out to be a possibility. So could web2py provide 
> a framework for that, and if so how much work would it take to 
> implement/adapt. After all, web2py already includes the ability to generate 
> desktop executables with a freestanding local server.
>
> Ian
>
>
> On Friday, March 23, 2012 6:14:34 PM UTC-4, Derek wrote:
>>
>> It's a server-client framework only. Your question does not make sense 
>> because html5+js+local storage = client. This is a server application. If 
>> you want to integrate localstorage, you're developing a client app, and 
>> thus there is no need for a server framework such as web2py. You could do 
>> all of that in your layout as easily as you could do anything else.
>>
>> Now, let's take an example app that is normally server-side and design it 
>> as an html5 client app, as an example, let's choose an RSS reader, for 
>> example.
>> Your current (non-html5) app parses the rss files on the server, converts 
>> it to html and displays it on the browser. The only things you have stored 
>> in the database is the login, and urls for the rss files that the user 
>> would like to access.
>>
>> Your html5 app (+web2py) would work like this:
>> login to the webapp (server) the first time. this will present your 
>> (client side) app - which will connect to the server, retrieve the json for 
>> the rss feeds, and saves the json into local storage, then displays what's 
>> in local storage based on javascript templates. 
>>
>> The only advantage you'd get with an app like this is you can use it 
>> while you are disconnected from the network. 
>>
>> But what would be better is to rewrite it so it will retrieve the rss 
>> feeds directly. Then you don't need the web2py piece at all.
>>
>> And that's my point.
>> On Friday, March 23, 2012 2:53:15 PM UTC-7, monotasker wrote:
>>>
>>> I've been struck by the huge push lately for 'html5 apps' as a (partly) 
>>> cross-platform approach to mobile and desktop development. Now win8 is 
>>> integrating html5+js heafily into the desktop and the Mozilla app project 
>>> is pushing in a similar direction. In many ways I think it makes sense (I 
>>> find css, for all its shortcomings, a lot nicer to deal with than qt or 
>>> gtk). But where does it leave a framework like web2py? It seems to me that 
>>> part of the html5 push comes from developers' reluctance to learn a 
>>> server-side language well (even php). If we have jquery and indexed local 
>>> storage in the browser, then people can do a lot with simple tools. I think 
>>> this is a mirage in many ways. At the same time, I would like to think that 
>>> I could benefit from the strengths of web2py (and python in general) and 
>>> still, say, develop an app for Mozilla's upcoming app store. Has anyone 
>>> been thinking about this? Is there room in things like the win8 api or the 
>>> Mozilla app api to use web2py? If not, how difficult would it be to create 
>>> bindings and an api to be included in gluon? Could the DAL be extended to 
>>> work with browser-based local storage? Or should we see web2py as a 
>>> traditional server-client framework only?
>>>
>>> Ian
>>>
>>

[web2py] Re: Auto Login on Google App engine

2012-03-23 Thread howesc
can you disable auto-login, and then in your wrapping controller (or 
perhaps there is an onaccept handler) manually add the user data to the 
session?  "login" really just means 'verify that the user exists in the db 
with the right credentials and then copy some stuff to the session' so you 
have done the first parts and could manually copy stuff to the session 
perhaps.

On Friday, March 23, 2012 5:55:33 AM UTC-7, Sushant Taneja wrote:
>
> Hi,
>
> As per the source code of the auth.register(), if auto-login is enabled, 
> another DAL query is executed to get the user from auth_user table. 
>
> 1958 user = self.db(table_user[username] == 
> form.vars[username]).select
> ().​first
> () 
>
> This user object is then set in the session and user is redirected to the 
> page specified.
>
> 1959 user = 
> Storage
> (table_user._filter_​fields
> (user, id=True)) 1960 
> session
> .auth = 
> Storage
> (user=user, 
> last_visit=request
> .now, 1961 
> expiration=self.settings
> .expir​ation, 1962 hmac_key = 
> web2py_uuid
> ()) 
>
> But on App engine's HRD, this read (line no: 1958 as above) fails.
> As per my understanding, this is because the write operation of the 
> auth_user table is still not complete so the query returns None and thus 
> the code in line 1959/1960 fails.
>
> Can somebody suggest a workaround for this problem ?
> I would really like to include the auto login feature in my app. 
>
> Also what does the line of code in *line number: 1959* exactly does ?
>
> Thanks,
> Sushant
>


[web2py] Re: Auto Login on Google App engine

2012-03-23 Thread Sushant Taneja
Thanks. 
I have a user object in the memory, may be I can use it to store the data 
in session. Let me try this out.
In the meantime, can you explain what does the line no: 1959 (as below) 
does ??

1959 user = 
Storage
(table_user._filter_​​fields
(user, id=True)) 

On Saturday, March 24, 2012 4:17:29 AM UTC+5:30, howesc wrote:
>
> can you disable auto-login, and then in your wrapping controller (or 
> perhaps there is an onaccept handler) manually add the user data to the 
> session?  "login" really just means 'verify that the user exists in the db 
> with the right credentials and then copy some stuff to the session' so you 
> have done the first parts and could manually copy stuff to the session 
> perhaps.
>
> On Friday, March 23, 2012 5:55:33 AM UTC-7, Sushant Taneja wrote:
>>
>> Hi,
>>
>> As per the source code of the auth.register(), if auto-login is enabled, 
>> another DAL query is executed to get the user from auth_user table. 
>>
>> 1958 user = self.db(table_user[username] == 
>> form.vars[username]).select
>> ().​​first
>> () 
>>
>> This user object is then set in the session and user is redirected to the 
>> page specified.
>>
>> 1959 user = 
>> Storage
>> (table_user._filter_​​fields
>> (user, id=True)) 1960 
>> session
>> .auth = 
>> Storage
>> (user=user, 
>> last_visit=request
>> .now, 1961 
>> expiration=self.settings
>> .expir​​ation, 1962 hmac_key = 
>> web2py_uuid
>> ()) 
>>
>> But on App engine's HRD, this read (line no: 1958 as above) fails.
>> As per my understanding, this is because the write operation of the 
>> auth_user table is still not complete so the query returns None and thus 
>> the code in line 1959/1960 fails.
>>
>> Can somebody suggest a workaround for this problem ?
>> I would really like to include the auto login feature in my app. 
>>
>> Also what does the line of code in *line number: 1959* exactly does ?
>>
>> Thanks,
>> Sushant
>>
>

[web2py] Re: can web2py have a place in an 'html5 app' environment?

2012-03-23 Thread Anthony

>
> If I code an html5 app for win8 or for Mozilla's app store I would like 
> the business logic to be in python if that turns out to be a possibility. 
> So could web2py provide a framework for that, and if so how much work would 
> it take to implement/adapt. After all, web2py already includes the ability 
> to generate desktop executables with a freestanding local server.
>

Well, the only language the clients can run is Javascript, so if you want 
to code in Python, it will ultimately have to generate Javascript for you. 
That's what Pyjamas does: http://pyjs.org/.

Anthony 


Re: [web2py] Re: Cookbook Chapter 2 - Reddit clone Ajax problem

2012-03-23 Thread ochiba77
Alan,

Thanks. Good idea. I will try the support files.


Sent from my Verizon Wireless BlackBerry

-Original Message-
From: Alan Etkin 
Sender: web2py@googlegroups.com
Date: Fri, 23 Mar 2012 15:22:25 
To: web2py-users
Reply-To: web2py@googlegroups.com
Subject: [web2py] Re: Cookbook Chapter 2 - Reddit clone Ajax problem

I tested the example app with the book support files and it worked
(with Firefox 10 and web2py trunk). Maybe there is a bug fixed in the
app code that was not updated in the book's text.

On 23 mar, 18:11, Omi Chiba  wrote:
> I was following cookbook and having a problem for the ajax part. I can
> click plus or minus to change the value for the first time, but it doesn't
> update the value next time it's clicked. Also, I don't get any flash
> message like 'you voted already' or 'vote recorded'.
>
> What am I missing ?
>
> Controller
> ---
> def news_comments():
>     news = db.news(request.args(0)) or redirect(URL('categories'))
>     if auth.user:
>         db.comment.news.default = news.id
>         db.comment.posted_on.default = request.now
>         db.comment.posted_by.default = auth.user.id
>         form = crud.create(db.comment)
>     comments =
> db(db.comment.news==news.id).select(orderby=db.comment.posted_on)
>     return locals()
>
> @auth.requires_login()
> def vote():
>     if not request.env.request_method=='POST': raise HTTP(400)
>     news_id, mode = request.args(0), request.args(1)
>     news = db.news(id=news_id)
>     vote = db.vote(posted_by=auth.user.id, news=news_id)
>     votes = news.votes
>     value = (mode=='plus') and +1 or -1
>     if vote and value*vote.value==1:
>         message = 'you voted already'
>     else:
>         if vote:
>             votes += value - vote.value
>             vote.update_record(value=value)
>         else:
>             votes += value
>             db.vote.insert(value=value, posted_by=auth.user.id,
> posted_on=request.now, news=news.id)
>             news.update_record(votes=votes)
>             message ='vote recorded'
>         return "jQuery('#votes').html('%s');jQuery('.flash').\
>                 html('%s').slideDown();" % (votes, message)
>
> View - news_comment.html
> -
> {{extend 'layout.html'}}
> {{=A(news.title, _href=news.link)}}
> {{if auth.user:}}
> {{=news.votes}}
> plus
> minus
> {{=form}}
> {{pass}}
> 
> {{for comment in comments:}}
> 
>     {{=comment.posted_on}}
>     {{=comment.posted_by.first_name}}: 
>     {{=MARKMIN(comment.body)}}
> 
> {{pass}}
> 

[web2py] Re: can web2py have a place in an 'html5 app' environment?

2012-03-23 Thread Derek
No, Pyjamas actually requires python installed everywhere it runs, even on 
desktops.

On Friday, March 23, 2012 4:14:42 PM UTC-7, Anthony wrote:
>
> If I code an html5 app for win8 or for Mozilla's app store I would like 
>> the business logic to be in python if that turns out to be a possibility. 
>> So could web2py provide a framework for that, and if so how much work would 
>> it take to implement/adapt. After all, web2py already includes the ability 
>> to generate desktop executables with a freestanding local server.
>>
>
> Well, the only language the clients can run is Javascript, so if you want 
> to code in Python, it will ultimately have to generate Javascript for you. 
> That's what Pyjamas does: http://pyjs.org/.
>
> Anthony 
>


[web2py] Re: Auto Login on Google App engine

2012-03-23 Thread Anthony

>
> Thanks. 
> I have a user object in the memory, may be I can use it to store the data 
> in session. Let me try this out.
> In the meantime, can you explain what does the line no: 1959 (as below) 
> does ??
>
> 1959 user = 
> Storage
> (table_user._filter_​​​fields
> (user, id=True)) 
>

table_user._filter_fields(user, id=True)

just converts the user record (which is a Row object) to a dict. I'm not 
sure why the _filter_fields method is used, as I believe this would just be 
equivalent to the simpler user.as_dict(). The additional benefit of 
_filter_fields is that it filters out any fields that are not included in 
the table definition, but in this case that is unnecessary, as the user object 
comes directly from the user table and therefore would not include any 
extraneous fields.

After conversion to a dict, user is then converted to a Storage object, 
which enables you to access the fields as attributes (i.e., user.first_name, 
etc.).

Anthony


Re: [web2py] Re: sqlite on production

2012-03-23 Thread Massimo Di Pierro
+1

If you have only one server sqlite is great. If you have many servers 
behind load balancer than you need to a client-server database like mysql 
or postgresql.


On Thursday, 22 March 2012 21:59:26 UTC-5, Vasile Ermicioi wrote:
>
> developers themselves say 'dont use it for sites that have 100k hits/day
>
>  
> I disagree,
>
> look here 
> http://www.sqlite.org/​whentouse.html
>  
> Generally speaking, any site that gets fewer than 100K hits/day should 
> work fine with SQLite. The 100K hits/day figure is a conservative estimate, 
> not a hard upper bound. SQLite has been demonstrated to work with 10 times 
> that amount of traffic.
>
> and that was written even before WAL appeared 
>
> you can't cluster sqlite 
>
>  
> you can use a clustered file system 
> I think cloud based hostings have such FS 
> e.g. Amazon S3
>
>
> many assumptions that were true  for sqlite are not valid since version 3.7
>
> SQLite is an awesome product, it supports
> 1) concurrency 
> http://www.sqlite.org/draft/​wal.html 
>
> 2) full text search
> http://www.sqlite.org/fts3.​html  with 
> contributions from some google engineers
>
> 3) R-Trees for geospacial systems
> http://www.sqlite.org/rtree.​html  
>


[web2py] Re: Markmin - could we use instead of ?

2012-03-23 Thread Massimo Di Pierro
Agreed. should be  not .

On Friday, 23 March 2012 10:05:48 UTC-5, villas wrote:
>
> I see bold is ,  so why is em rendered as  - it is 
> inconsistent.  Also inconsistent with Markdown.  And  isn't even styled 
> in the current web2py.js (unless I'm missing something).   Anyhow,  if it 
> wouldn't cause a problem, could we please change it.  Thanks.



[web2py] Re: Chrome extension to auto-open error tickets

2012-03-23 Thread Massimo Di Pierro
+1

On Friday, 23 March 2012 10:20:26 UTC-5, Alexander Garden wrote:
>
> Hi,
>
> I am working on a project using web2py and found clicking on trouble 
> tickets rather a nuisance. So I wrote a Chrome extension that watches for 
> web2py error pages and, when it finds one, opens the trouble ticket in an 
> iframe, thus saving me a couple clicks and a bunch of time. It's on 
> github. 
> Packed extension is on the download 
> page
> .
>
> Alexander
>


[web2py] Re: Chrome extension to auto-open error tickets

2012-03-23 Thread Massimo Di Pierro
Can you please open ticket about this. It will help me keep track and I 
will add a link in the docs.

On Friday, 23 March 2012 10:20:26 UTC-5, Alexander Garden wrote:
>
> Hi,
>
> I am working on a project using web2py and found clicking on trouble 
> tickets rather a nuisance. So I wrote a Chrome extension that watches for 
> web2py error pages and, when it finds one, opens the trouble ticket in an 
> iframe, thus saving me a couple clicks and a bunch of time. It's on 
> github. 
> Packed extension is on the download 
> page
> .
>
> Alexander
>


[web2py] Re: DAL and schema

2012-03-23 Thread Massimo Di Pierro
I am not sure if this can be done or not. If not supported, we can add 
support. Can you open a ticket and post an example of how to do it in SQL?

On Friday, 2 March 2012 05:58:35 UTC-6, Wuwei wrote:
>
> Hello,
> I'm trying to use DAL with a MSSQL db.
> I need to work with tables from 2 different schemas but I don't find how 
> to specify the schema when I define the table.
>
> Can you help me?
>
> Thank you.
>


[web2py] Re: bug in auth -- reset_password_onaccept doesn't exist ...

2012-03-23 Thread Massimo Di Pierro
Added to trunk.

On Friday, 23 March 2012 09:36:11 UTC-5, Anthony wrote:
>
> Congratulations, it appears you are the first person to need a reset 
> password callback. :-)
>
> On Friday, March 23, 2012 2:11:13 AM UTC-4, weheh wrote:
>>
>> I'm doing some more of this modal stuff for my login/password routines 
>> and ran into this problem. Probably an oversight in the code (lots of 
>> moving parts there!) 
>>
>> Traceback (most recent call last): 
>>   File "N:\web2py\gluon\restricted.​​py", line 204, in restricted 
>> exec ccode in environment 
>>   File "N:/web2py/applications/myapp/​​models/0_db_1_user.py", line 171, 
>> in  
>> auth.settings.reset_password_​​onaccept = 
>> [complete_request_reset_​​password] 
>>   File "N:\web2py\gluon\storage.py", line 196, in __setattr__ 
>> raise SyntaxError, 'setting key \'%s\' does not exist' % key 
>> SyntaxError: setting key 'reset_password_onaccept' does not exist
>
>

[web2py] Re: can web2py have a place in an 'html5 app' environment?

2012-03-23 Thread Anthony
On Friday, March 23, 2012 7:21:08 PM UTC-4, Derek wrote:
>
> No, Pyjamas actually requires python installed everywhere it runs, even on 
> desktops.
>

Not sure what you mean. Pyjamas compiles your Python code to Javascript. 
The Javascript is then sent to the browser as part of the web app. The 
machine with the browser does not have to have Python installed. Only the 
developer of the Pyjamas app nees Python, not the users (I'm talking about 
Pyjamas web apps, not desktop apps).

Anthony


Re: [web2py] Re: sqlite on production

2012-03-23 Thread Derek
Well, to each their own. If you want to use it, go ahead. I think that 
since postgresql and mysql are both free, you would want to choose the one 
that's the best fit. Sqlite is built in and makes it easy to do the sample 
code and such, and it can be used in some cases, but if you have postgresql 
or mysql available, you'll probably be happier using those, especially 
since the same code will work on all of them.

The question was, is it okay to use it for production, or is it not 
recommended. I still stand by my statement that it is okay, but it is not 
recommended.

On Thursday, March 22, 2012 7:59:26 PM UTC-7, Vasile Ermicioi wrote:
>
> developers themselves say 'dont use it for sites that have 100k hits/day
>
>  
> I disagree,
>
> look here 
> http://www.sqlite.org/​whentouse.html
>  
> Generally speaking, any site that gets fewer than 100K hits/day should 
> work fine with SQLite. The 100K hits/day figure is a conservative estimate, 
> not a hard upper bound. SQLite has been demonstrated to work with 10 times 
> that amount of traffic.
>
> and that was written even before WAL appeared 
>
> you can't cluster sqlite 
>
>  
> you can use a clustered file system 
> I think cloud based hostings have such FS 
> e.g. Amazon S3
>
>
> many assumptions that were true  for sqlite are not valid since version 3.7
>
> SQLite is an awesome product, it supports
> 1) concurrency 
> http://www.sqlite.org/draft/​wal.html 
>
> 2) full text search
> http://www.sqlite.org/fts3.​html  with 
> contributions from some google engineers
>
> 3) R-Trees for geospacial systems
> http://www.sqlite.org/rtree.​html  
>


[web2py] Re: can web2py have a place in an 'html5 app' environment?

2012-03-23 Thread Derek
In that case, it still depends on a server. You know what I meant. The 
original topic is about using a web framework for a client-only app.

On Friday, March 23, 2012 4:59:33 PM UTC-7, Anthony wrote:
>
> On Friday, March 23, 2012 7:21:08 PM UTC-4, Derek wrote:
>>
>> No, Pyjamas actually requires python installed everywhere it runs, even 
>> on desktops.
>>
>
> Not sure what you mean. Pyjamas compiles your Python code to Javascript. 
> The Javascript is then sent to the browser as part of the web app. The 
> machine with the browser does not have to have Python installed. Only the 
> developer of the Pyjamas app nees Python, not the users (I'm talking about 
> Pyjamas web apps, not desktop apps).
>
> Anthony
>


Re: [web2py] Re: Getting started in Web2py

2012-03-23 Thread Derek
Same here. It works just fine in Chrome. I fullscreen and start coding. 
Sure, I don't get autocomplete, but I rarely use that anyway. It does have 
issues managing files, but I found it was easy enough to put the files in 
the folders. (I'm not used to that coming from Zope).

On Friday, March 23, 2012 10:31:17 AM UTC-7, Vasile Ermicioi wrote:
>
>
>
> Don't use the web admin. It's for kids :P Copy welcome or example app and 
>> change the files directly.
>>
>>
> may be... but I rarely code outside of it :) 
>
>
On Friday, March 23, 2012 10:31:17 AM UTC-7, Vasile Ermicioi wrote:
>
>
>
> Don't use the web admin. It's for kids :P Copy welcome or example app and 
>> change the files directly.
>>
>>
> may be... but I rarely code outside of it :) 
>
>

[web2py] Re: SQLForm.grid : is it possible to delete multiple rows at once ?

2012-03-23 Thread Derek
Or you could avoid javascript, store the IDs of the "deleted" items in the 
session and do your own calls to the DAL to delete items.

On Friday, March 23, 2012 7:33:42 AM UTC-7, Anthony wrote:
>
> Is it possible to select and delete multiple rows with one button click 
>> using SQLFORM.grid ?  (instead of clicking delete on each row)
>> I tried the "selectable" property but this doesn't help to delete.
>> I searched the archive of this group / mailing-list without success
>>
>
> Not out of the box. I suppose you could add a column (via the "links" 
> argument) with "delete" checkboxes, and then add a "delete checked" button 
> to the page with a Javascript event handler that identifies the checked 
> records, submits a request to the server, and then possibly reloads the 
> whole page or just the grid via Ajax.
>
> Anthony 
>


[web2py] Re: Chrome extension to auto-open error tickets

2012-03-23 Thread Alexander Garden
Sure. Where do I do that?

On Friday, March 23, 2012 7:49:54 PM UTC-4, Massimo Di Pierro wrote:
>
> Can you please open ticket about this. It will help me keep track and I 
> will add a link in the docs.
>
> On Friday, 23 March 2012 10:20:26 UTC-5, Alexander Garden wrote:
>>
>> Hi,
>>
>> I am working on a project using web2py and found clicking on trouble 
>> tickets rather a nuisance. So I wrote a Chrome extension that watches for 
>> web2py error pages and, when it finds one, opens the trouble ticket in an 
>> iframe, thus saving me a couple clicks and a bunch of time. It's on 
>> github . Packed 
>> extension is on the download 
>> page
>> .
>>
>> Alexander
>>
>

[web2py] Re: missing FROM-clause entry

2012-03-23 Thread Limedrop
Thanks for the information.  Unfortunately, in my case I really do
need to store the raw query in the session...and then convert it back
to a Query so I can then add a few more filters before the final
select(). Has anyone managed to store a representation of a query in
the session?

On Mar 24, 11:09 am, Anthony  wrote:
> On Friday, March 23, 2012 5:36:28 PM UTC-4, monotasker wrote:
>
> > I may be off target but I just recently noticed the .as_dict() method for
> > rows objects. This converts the rows object to a regular dict (instead of a
> > gluon storage object) which can be stored in session or cache (i.e., it's
> > picklable). If you need the query (not the resulting rows object) to be
> > stored this doesn't help, but if it works in your case to store the
> > select() result this may actually be easier.
>
> There is also an .as_list() method, which converts to a list of
> dictionaries rather than a dictionary of dictionaries. You can also just
> store Rows objects directly in the session or cache -- the DAL defines a
> reduction function that calls the .as_list() method when a Rows object is
> pickled, so you don't have to call the method manually.
>
> Anthony


[web2py] Re: DAL / connection pool leaking objects?

2012-03-23 Thread nick name
Probably a bug in DAL (at least for standalone use, but I suspect also when 
used in web2py). A test case that easily reproduces this behavior can be 
found in Issue 731 : 
Standalone 
DAL is leaking memory+resources (don't know whether or not inside web2py)


[web2py] Re: missing FROM-clause entry

2012-03-23 Thread nick name

On Friday, March 23, 2012 6:09:30 PM UTC-4, Anthony wrote:
>
> There is also an .as_list() method, which converts to a list of 
> dictionaries rather than a dictionary of dictionaries. You can also just 
> store Rows objects directly in the session or cache -- the DAL defines a 
> reduction function that calls the .as_list() method when a Rows object is 
> pickled, so you don't have to call the method manually.


as_dict() and as_list() are both very helpful. A caveat that I've noticed 
with them, however, is that as_dict() defaults to leaving datetime fields 
as-is (you can override that to convert them to string), whereas as_list() 
defaults to converting datetime fields to string (you can override that so 
that they stay as-is).

While this is not going to change because of backward compatibility issues, 
I think this deserves more attention in the documentation.

I have a few things to contribute to a "web2py caveats" page if one was to 
be put on web2py.com -- things that people find unintuitive and surprising 
about web2py (which is, in general, has a very logical coherent structure 
with almost no surprises).


[web2py] Re: missing FROM-clause entry

2012-03-23 Thread nick name
On Friday, March 23, 2012 10:09:07 PM UTC-4, Limedrop wrote:
>
> Thanks for the information.  Unfortunately, in my case I really do 
> need to store the raw query in the session...and then convert it back 
> to a Query so I can then add a few more filters before the final 
> select(). Has anyone managed to store a representation of a query in 
> the session? 
>

If you are using an SQL database, and the initial query is for a subset of 
records in a specific table, you might be able to use "belongs", which can 
accept a query string; so:

# compute complicated query; use _select instead of select
sqlquery = db(table)(...)(...)._select(table.id)

# store sqlquery in your string storage, etc; it is a string.
#  e.g. put it in your session (but under no circumstance in a form/request 
# variable or a cookie - that would make your app vulnerable to SQL 
injection)

# retrieve your sqlquery string from the secure storage

# add additional conditions
finalquery = db(table.id.belongs(sqlquery) & table.field1=='field1value')





[web2py] Re: missing FROM-clause entry

2012-03-23 Thread Limedrop
An interesting suggestion...I can see how I could use it for some sort
of workaround.  What it would me is that I would have to use two
separate selects, when I was hoping you only do one.  Still it seems
to me that my initial approach is the correct one, and that the DAL
should be consistent in the way it generates SQL. Specifically:

==Controller 1==
query1 = (db.comment.id > 0) & (db.webpage.title == 'FAQ') &
(db.comment.page_id == db.webpage.id)
session.query = str(query1)

==Controller 2==
from gluon.dal import Query
query2 = Query(db, session.query)

Should work, but does NOT work because the DAL gives different results
for query1 and query2.  Is this, then a bug?


On Mar 24, 3:28 pm, nick name  wrote:
> On Friday, March 23, 2012 10:09:07 PM UTC-4, Limedrop wrote:
>
> > Thanks for the information.  Unfortunately, in my case I really do
> > need to store the raw query in the session...and then convert it back
> > to a Query so I can then add a few more filters before the final
> > select(). Has anyone managed to store a representation of a query in
> > the session?
>
> If you are using an SQL database, and the initial query is for a subset of
> records in a specific table, you might be able to use "belongs", which can
> accept a query string; so:
>
> # compute complicated query; use _select instead of select
> sqlquery = db(table)(...)(...)._select(table.id)
>
> # store sqlquery in your string storage, etc; it is a string.
> #  e.g. put it in your session (but under no circumstance in a form/request
> # variable or a cookie - that would make your app vulnerable to SQL
> injection)
>
> # retrieve your sqlquery string from the secure storage
>
> # add additional conditions
> finalquery = db(table.id.belongs(sqlquery) & table.field1=='field1value')


[web2py] Re: can web2py have a place in an 'html5 app' environment?

2012-03-23 Thread Anthony

>
> In that case, it still depends on a server. You know what I meant. The 
> original topic is about using a web framework for a client-only app.


Really, I didn't know what you meant, as you said Pyjamas requires Python 
to be installed. It doesn't depend on a server either, other than to 
deliver the app to the browser (though I suppose it could be run locally as 
well). Anyway, my point was just that Python can't be used for client-side 
apps unless compiled to Javascript, and Pyjamas is an example of that.

Anthony 


[web2py] Re: Chrome extension to auto-open error tickets

2012-03-23 Thread Anthony
On Friday, March 23, 2012 9:03:17 PM UTC-4, Alexander Garden wrote:
>
> Sure. Where do I do that?
>

http://code.google.com/p/web2py/issues/list


Re: [web2py] Re: sqlite on production

2012-03-23 Thread Anthony

>
> Well, to each their own. If you want to use it, go ahead. I think that 
> since postgresql and mysql are both free, you would want to choose the one 
> that's the best fit. Sqlite is built in and makes it easy to do the sample 
> code and such, and it can be used in some cases, but if you have postgresql 
> or mysql available, you'll probably be happier using those, especially 
> since the same code will work on all of them.
>
> The question was, is it okay to use it for production, or is it not 
> recommended. I still stand by my statement that it is okay, but it is not 
> recommended.
>

"production" just means the version of the app that gets deployed to users 
-- it doesn't imply a particular scale. SQLite is stable, reliable, 
reasonably fast, and more than adequate for many production applications. 
And it is in fact very widely deployed "in production" -- 
http://www.sqlite.org/mostdeployed.html.

The advantage of SQLite, particularly with web2py, is simply that it's 
easier -- nothing to install or set up. web2py even creates the db for you. 
If your app calls for it, certainly use Postgres or MySQL, but in many 
cases, SQLite will do just fine.

Anthony 


Re: [web2py] Re: SQLForm.grid : is it possible to delete multiple rows at once ?

2012-03-23 Thread Javier Pepe
sabsto

You can use selectable, for example:

selectable = lambda ids: delete(ids)
form=SQLFORM.grid(query,selectable=selectable)

def delete(ids):
to_delete=db(db.tabla.id.belongs(ids))
to_delete.delete()




On Fri, Mar 23, 2012 at 9:46 PM, Derek  wrote:

> Or you could avoid javascript, store the IDs of the "deleted" items in the
> session and do your own calls to the DAL to delete items.
>
>
> On Friday, March 23, 2012 7:33:42 AM UTC-7, Anthony wrote:
>>
>> Is it possible to select and delete multiple rows with one button click
>>> using SQLFORM.grid ?  (instead of clicking delete on each row)
>>> I tried the "selectable" property but this doesn't help to delete.
>>> I searched the archive of this group / mailing-list without success
>>>
>>
>> Not out of the box. I suppose you could add a column (via the "links"
>> argument) with "delete" checkboxes, and then add a "delete checked" button
>> to the page with a Javascript event handler that identifies the checked
>> records, submits a request to the server, and then possibly reloads the
>> whole page or just the grid via Ajax.
>>
>> Anthony
>>
>


[web2py] Unsupported query SQLFORM.grid

2012-03-23 Thread FERNANDO VILLARROEL
Dear All.

I am trying the following query:


fields=[db.llamados.id,db.accountcode.ani,db.llamados.destino,db.rutas.nombre,db.llamados.answeredtime,db.llamados.inicio,db.llamados.valor,db.l
lamados.billing]

left = 
([db.accountcode.on(db.llamados.id_accountcode==db.accountcode.id),db.rutaproveedor.on(db.llamados.id_rutaproveedor==db.rutaproveedor.id)
,db.rutas.on(db.rutaproveedor.id_rutas==db.rutas.id)])


 query = ((db.accountcode.id_clientes==session.cliente_id) & 
(db.llamados.dialstatus=='ANSWER') & (db.llamados.inicio >= dt1) & (db.llamad   
 os.inicio <= dt2))

 
grid=SQLFORM.grid(query=query,fields=fields,left=left,orderby=default_sort_order,create=False,deletable=False,editable=False,det
ails=False,maxtextlength=100,paginate=50)

Does when i press submit i received : Unsupported query 
and not show  db.rutas.nombre column

How i can do?