[web2py] [off] PHP has its DAL clone

2011-06-17 Thread Bruno Rocha
NotORM

http://abcphp.com/64372/

even PHP being an ugly language, can we learn something from it?

--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]


[web2py] Re: For Massimo: which version of book to buy?

2011-06-17 Thread Massimo Di Pierro
I work in a university. My merit review (salary, promotions, etc)
depend on my publications. Books on paper count. Books online do not.

On Jun 17, 6:47 pm, mikech  wrote:
> Wouldn't it be better at this point to use the online version and just
> contribute to the project using the link on the main page?


[web2py] Re: sum(decimal field) comes back as float

2011-06-17 Thread Massimo Di Pierro
I need to think about this. The sum(...) is performed at the db level
and therefore - on sqlite -  it is computed as float. The result
should be converted back to decimal anyway.

You are using sqlite, correct?

On Jun 17, 6:15 pm, apple  wrote:
> Here is some test code. It prints the type of testfield as decimal;
> and the type of summary(sumtest) as float.
>
>  model:
>
>    db.define_table('test',
>     Field('testfield', 'decimal(8,2)'))
>
> controller:
>
>     db.test.insert(testfield=3.2)
>     db.test.insert(testfield=7.8)
>     db.commit()
>     test1=db(db.test.testfield<5).select()[0]
>     print(test1.testfield, type(test1.testfield))
>     sumtest=db.test.testfield.sum()
>     summary=db(db.test.testfield>0).select(sumtest).first()
>     print(summary(sumtest), type(summary(sumtest)))
>
> On Jun 17, 9:56 pm, Massimo Di Pierro 
> wrote:
>
>
>
>
>
>
>
> > unless there is a bug, Field('name','decimal(5,2)') will always treat
> > the number as decimal.Decimal at the web2py level. The problem is how
> > is it stored in the database. If the database supports decimal is it
> > stored accordingly. If the database does not (sqlite) that it is
> > converted to float and stored as float.
>
> > I am not sure I answered the question. perhaps I misunderstood.
>
> > On Jun 17, 12:54 pm, apple  wrote:
>
> > > Yes sqlite.
>
> > > The book says "SQLite does not handle the decimal type so internally
> > > we treat it as a double". However wouldn't it be logical to convert it
> > > back to decimal if that is what my tabledef says?
>
> > > On Jun 17, 6:40 pm, Anthony  wrote:
>
> > > > On Friday, June 17, 2011 1:13:26 PM UTC-4, apple wrote:
>
> > > > > I am using the DAL to aggregate SUM a decimal field and the result is
> > > > > a float. Shouldn't the DAL keep it in same format as the underlying
> > > > > field?
>
> > > > Are you using SQLite? As far as I know, it doesn't support decimal 
> > > > fields,
> > > > so I think web2py has to treat them as doubles. 
> > > > Seehttp://web2py.com/book/default/chapter/06#DAL,-Table,-Field.
>
> > > > Anthony


[web2py] Re: For Massimo: which version of book to buy?

2011-06-17 Thread mikech
Wouldn't it be better at this point to use the online version and just 
contribute to the project using the link on the main page?


Re: [web2py] Re: import error

2011-06-17 Thread Pierre Thibault
2011/6/17 selecta 

> I also have problems importing pygments from the modules directory
> http://jaguar.biologie.hu-berlin.de/~fkrause/web2py.app.pygments_test.w2p
>
> i downloaded pygments from http://pypi.python.org/pypi/Pygments
>
>
Do you still have problems with you are using the last version of trunk?

-- 


A+

-
Pierre
My blog and profile
(http://pierrethibault.posterous.com)
YouTube page 
(http://www.youtube.com/user/tubetib)
Twitter (http://twitter.com/pierreth2) 


[web2py] Re: sum(decimal field) comes back as float

2011-06-17 Thread apple
Here is some test code. It prints the type of testfield as decimal;
and the type of summary(sumtest) as float.

 model:

   db.define_table('test',
Field('testfield', 'decimal(8,2)'))

controller:

db.test.insert(testfield=3.2)
db.test.insert(testfield=7.8)
db.commit()
test1=db(db.test.testfield<5).select()[0]
print(test1.testfield, type(test1.testfield))
sumtest=db.test.testfield.sum()
summary=db(db.test.testfield>0).select(sumtest).first()
print(summary(sumtest), type(summary(sumtest)))

On Jun 17, 9:56 pm, Massimo Di Pierro 
wrote:
> unless there is a bug, Field('name','decimal(5,2)') will always treat
> the number as decimal.Decimal at the web2py level. The problem is how
> is it stored in the database. If the database supports decimal is it
> stored accordingly. If the database does not (sqlite) that it is
> converted to float and stored as float.
>
> I am not sure I answered the question. perhaps I misunderstood.
>
> On Jun 17, 12:54 pm, apple  wrote:
>
>
>
>
>
>
>
> > Yes sqlite.
>
> > The book says "SQLite does not handle the decimal type so internally
> > we treat it as a double". However wouldn't it be logical to convert it
> > back to decimal if that is what my tabledef says?
>
> > On Jun 17, 6:40 pm, Anthony  wrote:
>
> > > On Friday, June 17, 2011 1:13:26 PM UTC-4, apple wrote:
>
> > > > I am using the DAL to aggregate SUM a decimal field and the result is
> > > > a float. Shouldn't the DAL keep it in same format as the underlying
> > > > field?
>
> > > Are you using SQLite? As far as I know, it doesn't support decimal fields,
> > > so I think web2py has to treat them as doubles. 
> > > Seehttp://web2py.com/book/default/chapter/06#DAL,-Table,-Field.
>
> > > Anthony


Re: [web2py] Re: Seems Like a NEW error in Trunk.

2011-06-17 Thread David J.

Yes I did; Thank you;

(You can spend a day on a comma sometimes.)

On 6/17/11 4:34 PM, Anthony wrote:

On Friday, June 17, 2011 4:24:04 PM UTC-4, David J wrote:

I just defined some new tables after upgrading to latest trunk.

db.define_table('people'


Field('owner',db.auth_user,default=auth.user_id,readable=False,writable=False),
 Field('email','string'),
 signature
)

I think you're missing a comma after 'people'.


Also

Before the default behavior was to return generic.html;

Seems like that is no longer the case.

See https://groups.google.com/d/msg/web2py/JR_pyGVfm_g/VlCfeKZWAvkJ
Anthony




[web2py] Re: For Massimo: which version of book to buy?

2011-06-17 Thread Massimo Di Pierro
Thank you for asking.
I make the same from the pdf version and the printed version.

Massimo

On Jun 17, 2:40 pm, Cliff  wrote:
> Which version of the Web2py book most benefits the author?
>
> Let me know and that is the one I will purchase.


[web2py] For Massimo: which version of book to buy?

2011-06-17 Thread Cliff
Which version of the Web2py book most benefits the author?

Let me know and that is the one I will purchase.


[web2py] Re: bug in custom_import.py

2011-06-17 Thread Massimo Di Pierro
done. sorry.

On Jun 17, 4:51 pm, Pierre Thibault 
wrote:
> 2011/6/17 Jonathan Lundell 
>
>
>
>
>
>
>
>
>
> > On Jun 17, 2011, at 2:28 PM, Pierre Thibault wrote:
>
> > 2011/6/17 Jose 
>
> >> at line 254 (trunk version)
>
> >>        if not name.startswith(".") and level <= 0 and globals != None
> >> and
> >>                and not name.startswith("applications."):
>
> >> Jose
>
> > ?? What do you mean? More information is needed.
>
> > There are two 'and's in a row. (Also: globals is not None)
>
> OK. I think Massimo made an error with the patch. Here is my personal code:
>
>         if not name.startswith(".") and level <= 0 \
>                 and not name.startswith("applications.") \
>                 and isinstance(globals, dict):
>
> Massimo, can you correct?
> --
>
> A+
>
> -
> Pierre
> My blog and profile
> (http://pierrethibault.posterous.com)
> YouTube page 
> (http://www.youtube.com/user/tubetib)
> Twitter (http://twitter.com/pierreth2) 


[web2py] auth.signature in auth_user?

2011-06-17 Thread pbreit
Would it make sense to include auth.signature in my custom auth_user table 
or would there be some sort of circular reference problem?

Also, am I missing anything major by customizing auth_user? Are there any 
benefits to using the extra_fields approach instead?


Re: [web2py] bug in custom_import.py

2011-06-17 Thread Pierre Thibault
2011/6/17 Jonathan Lundell 

> On Jun 17, 2011, at 2:28 PM, Pierre Thibault wrote:
>
> 2011/6/17 Jose 
>
>> at line 254 (trunk version)
>>
>>if not name.startswith(".") and level <= 0 and globals != None
>> and
>>and not name.startswith("applications."):
>>
>> Jose
>
>
> ?? What do you mean? More information is needed.
>
>
> There are two 'and's in a row. (Also: globals is not None)
>

OK. I think Massimo made an error with the patch. Here is my personal code:

if not name.startswith(".") and level <= 0 \
and not name.startswith("applications.") \
and isinstance(globals, dict):

Massimo, can you correct?
-- 


A+

-
Pierre
My blog and profile
(http://pierrethibault.posterous.com)
YouTube page 
(http://www.youtube.com/user/tubetib)
Twitter (http://twitter.com/pierreth2) 


Re: [web2py] bug in custom_import.py

2011-06-17 Thread Jonathan Lundell
On Jun 17, 2011, at 2:28 PM, Pierre Thibault wrote:
> 2011/6/17 Jose 
> at line 254 (trunk version)
> 
>if not name.startswith(".") and level <= 0 and globals != None
> and
>and not name.startswith("applications."):
> 
> Jose
> 
> ?? What do you mean? More information is needed.

There are two 'and's in a row. (Also: globals is not None)

[web2py] Re: bug in custom_import.py

2011-06-17 Thread Jose
should just be like:

if not name.startswith(".") and level <= 0 and globals != None \
and not name.startswith("applications."):

original code has a double and one on each line, and the lines are not
concatenated.

Jose


Re: [web2py] bug in custom_import.py

2011-06-17 Thread Pierre Thibault
2011/6/17 Jose 

> at line 254 (trunk version)
>
>if not name.startswith(".") and level <= 0 and globals != None
> and
>and not name.startswith("applications."):
>
> Jose


?? What do you mean? More information is needed.

-- 


A+

-
Pierre
My blog and profile
(http://pierrethibault.posterous.com)
YouTube page 
(http://www.youtube.com/user/tubetib)
Twitter (http://twitter.com/pierreth2) 


[web2py] bug in custom_import.py

2011-06-17 Thread Jose
at line 254 (trunk version)

if not name.startswith(".") and level <= 0 and globals != None
and
and not name.startswith("applications."):

Jose


[web2py] Re: Download of big files broken

2011-06-17 Thread Massimo Di Pierro
Can you make a list of combinations

browser name, version, server os, web server
FF, 4, Windows 7, Rocket
...

for which you experienced the problem?

can you also try the following:
1) in the rocket.py code replace

   'HTTP/1.1 ' with 'HTTP/1.0 '

and replace

   environ['SERVER_PROTOCOL'] = request['protocol']

with

   environ['SERVER_PROTOCOL'] = "1.0"

Looks like acts as if the protocol of response is the same as the
request but always declare the protocol of the response to be 1.1 even
if the request is 1.0. This may result in keep-alive connections
ignored by the browser. Perhaps this is part of the problem?




On Jun 17, 1:35 pm, Stefan Scholl  wrote:
> To Massimo and the list/group:
>
> You asked on Reddit if the only constant is the browser. No it
> isn't. But it was the browser which had the problem first, with
> smaller files.
>
> For smaller files it was enough to raise the chunk_size. IE8 is
> slow, maybe this is the reason?
>
> Firefox 4 failed when I tried to download a 33 MiB file remotely.
> IE8 failed for anything above 64 KiB on localhost.
>
> It's almost as if Rocket is so fast because it sends without
> regard for any receiver. Direct (localhost) or behind a proxy
> (Apache 2.2 on the remote Linux server).
> Don't know how this could happen. HTTP isn't ZModem. ;-)
>
>
>
>
>
>
>
>
>
> Stefan Scholl  wrote:
> > I have a parameters_XXX.py file from the normal web2py (with
> > rocket) and used the same IP and port with anyserver.py+Tornado
> > (and the other one stopped, of course).
>
> > Tested with web2py 1.91.6. Were there any changes regarding this?
>
> > (I'm still very reluctant to upgrade this project.)
>
> > Massimo Di Pierro  wrote:
> >> Try this:
>
> >> python
> > from gluon.main import save_password
> > save_password(raw_input('admin password: '),XXX)
>
> >> This will create a parameters_XXX.py file. It must be in the main
> >> web2py folder. Caveats, the admin interface is disabled if you are not
> >> form localhost and you are not using https.
> >> Hope this helps. Hope to have you back on the mailing list.
>
> >> On Jun 17, 8:43 am, Stefan Scholl  wrote:
> >>> Now I can't access the admin interface, because the password
> >>> isn't set. (It isn't reading the stored password.)
>
> >>> Stefan Scholl  wrote:
> >>> > OK, it was Rocket.
>
> >>> > Tested it with the old web2py and Tornado 1.2.1 via anyserver.py
> >>> > and the download is OK.
>
> >>> > Stefan Scholl  wrote:
> >>> >> The higher value for chunk_size didn't work with a 33 MiB file. Even
> >>> >> in Firefox 4.
> >>> >> So I tried 1.96.4 (Rocket 1.2.2) on Windows XP.
>
> >>> >> Made a new and simple app (dtest). The download there uses
> >>> >> "response.download(request,db)" as well.
>
> >>> >> 1 simple table: db.define_table('stuff', Field('file', 'upload'))
>
> >>> >> Upload of the 33 MiB file via db admin, content listed on
> >>> >>http://127.0.0.1:8001/dtest/default/data/select/stuff(default
> >>> >> function "data" with "return dict(form=crud())". Download with
> >>> >> Internet Explorer 8 (after removing the tag that switches to "Chrome
> >>> >> Frame", to have a realistic test like "normal" users).
>
> >>> >> Download was broken. A few KiB were missing. This was on localhost.
> >>> >> Remote tests have even worse results.
>
> >>> >> On 6 Mai, 17:51, Massimo Di Pierro  wrote:
> >>> >>> Can you try 1.95.1
>
> >>> >>> On May 6, 6:03 am, Stefan Scholl  wrote:
>
> >>> >>> > The classicdownloadfunction:
>
> >>> >>> > defdownload():
> >>> >>> > return response.download(request, db)
>
> >>> >>> > I'm developing on localhost (127.0.0.1, no SSL) and one strange 
> >>> >>> > thing
> >>> >>> > happened: Downloads in IE8 (Windows XP) were all corrupt/broken if
> >>> >>> > they weren't below 64KiB in size. Very easy to see with large 
> >>> >>> > images.
>
> >>> >>> > Using a higher value for the argument 'chunk_size' solves this
> >>> >>> > problem, up to this new maximum.
>
> >>> >>> > web2py 1.91.6
>
> --
> Web (en):http://www.no-spoon.de/-*- Web (de):http://www.frell.de/
> 


[web2py] Re: sum(decimal field) comes back as float

2011-06-17 Thread Massimo Di Pierro
unless there is a bug, Field('name','decimal(5,2)') will always treat
the number as decimal.Decimal at the web2py level. The problem is how
is it stored in the database. If the database supports decimal is it
stored accordingly. If the database does not (sqlite) that it is
converted to float and stored as float.

I am not sure I answered the question. perhaps I misunderstood.

On Jun 17, 12:54 pm, apple  wrote:
> Yes sqlite.
>
> The book says "SQLite does not handle the decimal type so internally
> we treat it as a double". However wouldn't it be logical to convert it
> back to decimal if that is what my tabledef says?
>
> On Jun 17, 6:40 pm, Anthony  wrote:
>
>
>
>
>
>
>
> > On Friday, June 17, 2011 1:13:26 PM UTC-4, apple wrote:
>
> > > I am using the DAL to aggregate SUM a decimal field and the result is
> > > a float. Shouldn't the DAL keep it in same format as the underlying
> > > field?
>
> > Are you using SQLite? As far as I know, it doesn't support decimal fields,
> > so I think web2py has to treat them as doubles. 
> > Seehttp://web2py.com/book/default/chapter/06#DAL,-Table,-Field.
>
> > Anthony


[web2py] acting upon anchor text post login

2011-06-17 Thread Carl
The anchor text of URLs is lost when I'm redirected to login and then
on to "next.

I think it's down to gluon.py requires_login()
this code:

next = URL(r=request,args=request.args,
   vars=request.get_vars)
...
self.settings.login_url + '?_next='+urllib.quote(next)
///

I think URL() creates an url but doesn't added any existing anchor
text.

thoughts, any one?


[web2py] Re: Seems Like a NEW error in Trunk.

2011-06-17 Thread pbreit
Only thing I can think of is that if you have it the way it's appearing in 
the post, line 2 is blank and line 3 is not indented.

Does this work?

db.define_table('people'

 Field('owner',db.auth_user,default=auth.user_id,readable=False,writable=False),
 Field('email','string'),
 signature
)




[web2py] Re: Seems Like a NEW error in Trunk.

2011-06-17 Thread Anthony
On Friday, June 17, 2011 4:24:04 PM UTC-4, David J wrote: 
>
> I just defined some new tables after upgrading to latest trunk. 
>
> db.define_table('people'
>  
>
> Field('owner',db.auth_user,default=auth.user_id,readable=False,writable=False),
>  Field('email','string'),
>  signature
> )
>
I think you're missing a comma after 'people'.

>
> Also 
>
> Before the default behavior was to return generic.html; 
>
> Seems like that is no longer the case.
>
See https://groups.google.com/d/msg/web2py/JR_pyGVfm_g/VlCfeKZWAvkJ
 
Anthony


[web2py] Re: File upload bug?

2011-06-17 Thread pbreit
Can you make it look more like the Book? Not tested:

db.define_table('t_file',
   Field ('ifile', 'upload'))


def upload_data()
import csv
form = SQLFORM(db.t_file)
if form.accepts(request.vars, session):
reader = csv.DictReader(form.vars.ifile.file)
return dict(reader=reader)
return dict(form=form)


{{if form:}}{{=form}}{{pass}
{{if reader:}}
{{for row in reader:}}
{{=row['col_a']}}
{{pass}}
{{pass}}




[web2py] Re: Strange Error: Field does not belong to the table

2011-06-17 Thread Anthony
Actually, I think it would also work if you simply avoided assigning to 
form.vars after form submission. So, instead of:
 
form.vars.is_administrator = user and auth.has_membership(user_id=user.id, 
role='Administrators') 
 
do:
 
if not request.vars:
form.vars.is_administrator = user and auth.has_membership(user_id=
user.id, role='Administrators')
 
 
That way, you will assign to form.vars when the form is first created, but 
you will not assign to it once the form has been submitted, which is 
probably what you want anyway.
 
Anthony
 

On Friday, June 17, 2011 4:16:34 PM UTC-4, Anthony wrote:

> Try:
>  
> form = SQLFORM(db.auth_user, user, showid=False)
> is_administrator = user and auth.has_membership(user_id=user.id, 
> role='Administrators')
> form[0].insert(-1, TR((
> TD(LABEL('Is Administrator', _for='auth_user_is_administrator')),
> TD(INPUT(_type='checkbox', _name='is_administrator', 
> _id='auth_user_is_administrator',
> value=is_administrator)
>  
> Notice, instead of pre-populating the is_administrator field via 
> form.vars.is_administrator=[value], the above pre-populates the filed by 
> setting the 'value' argument of the INPUT helper. It appears that using the 
> form.vars method does not work when the form/table doesn't contain a Field 
> object for the field being pre-populated.
>  
> Anthony
>  
>
> On Monday, June 13, 2011 9:21:51 PM UTC-4, Ross Peoples wrote:
>
>> I am trying to provide an editor for auth_user using SQLFORM. I also am 
>> trying to add a checkbox to the bottom of the form to set whether or not the 
>> user is an administrator. If so, then the user gets added to an 
>> Administrators group when calling form.accepts(). 
>>
>> The strange part is, the code works fine if you check the box, then click 
>> submit, but if you try to uncheck the box, that's when you get the following 
>> traceback:
>>
>>   1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>> 13.
>> 14.
>> 15.
>> 16.
>> 17.
>> 18.
>> 19.
>> 20.
>> 21.
>> 22.
>>
>> Traceback (most recent call last):
>>   File "/media/psf/Python/web2py/gluon/restricted.py", line 192, in 
>> restricted
>> exec ccode in environment
>>   File 
>> "/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
>>  , line 
>> 650, in 
>>   File "/media/psf/Python/web2py/gluon/globals.py", line 137, in 
>> self._caller = lambda f: f()
>>   File "/Users/rosspeoples/Dropbox/Code/Python/web2py/gluon/tools.py", line 
>> 2485, in f
>> return action(*a, **b)
>>   File 
>> "/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
>>  , line 
>> 148, in security
>> return update()
>>   File 
>> "/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
>>  , line 
>> 143, in update
>> return user_form(user)
>>   File 
>> "/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
>>  , line 
>> 120, in user_form
>> if form.accepts(request.vars, session):
>>   File "/media/psf/Python/web2py/gluon/sqlhtml.py", line 1203, in accepts
>> self.table._db(self.table._id == self.record.id).update(**fields)
>>   File "/Users/rosspeoples/Dropbox/Code/Python/web2py/gluon/dal.py", line 
>> 5401, in update
>> fields = self.db[tablename]._listify(update_fields,update=True)
>>   File "/Users/rosspeoples/Dropbox/Code/Python/web2py/gluon/dal.py", line 
>> 4677, in _listify
>> raise SyntaxError, 'Field %s does not belong to the table' % name
>> SyntaxError: Field is_administrator does not belong to the table
>>
>> And here is the controller that is adding the checkbox:
>>
>>  form = SQLFORM(db.auth_user, user, showid=False)
>> form[0].insert(-1, TR((
>> TD(LABEL('Is Administrator', 
>> _for='auth_user_is_administrator')),
>> TD(INPUT(_type='checkbox', _name='is_administrator', 
>> _id='auth_user_is_administrator'))
>> )))
>> 
>> form.vars.is_administrator = False
>> if user:
>> if auth.has_membership(user_id=user.id, 
>> role='Administrators'):
>> form.vars.is_administrator = True
>> 
>> if form.accepts(request.vars, session):
>> admin_group = 
>> db(db.auth_group.role=='Administrators').select().first()
>> db((db.auth_membership.user_id==user.id) & 
>> (db.auth_membership.group_id==admin_group.id)).delete()
>> 
>> if form.vars.is_administrator:
>> db.auth_membership.insert(group_id=admin_group.id, 
>> user_id=user.id)
>> 
>> return 'OK'
>> 
>> ret

[web2py] Re: entry level permissions

2011-06-17 Thread max
thanks
On Jun 17, 8:17 pm, Anthony  wrote:
> On Friday, June 17, 2011 2:08:45 PM UTC-4, max wrote:
>
> > i want to give for ceratin records of a table different user
> > permissions.
> > can the authentication of web2py used for this?
>
> Look at add_permission and has_permission 
> here:http://web2py.com/book/default/chapter/08#Authorization. You can specify
> permissions for tables and record ID's.
>
> Or, if you're using CRUD, you can link auth with 
> CRUD:http://web2py.com/book/default/chapter/08#Authorization-and-CRUD.
>
> Anthony


[web2py] Seems Like a NEW error in Trunk.

2011-06-17 Thread David J.

I just defined some new tables after upgrading to latest trunk.

db.define_table('people'

Field('owner',db.auth_user,default=auth.user_id,readable=False,writable=False),

Field('email','string'),
signature
)


S'Traceback (most recent call last):\n  File 
"/apps/www/web2py.trunk/gluon/restricted.py", line 191, in 
restricted\nccode = compile2(code,layer)\n  File 
"/apps/www/web2py.trunk/gluon/restricted.py", line 178, in compile2\n
return compile(code.rstrip().replace(\'\\r\\n\',\'\\n\')+\'\\n\', layer, 
\'exec\')\n  File 
"/apps/www/web2py.trunk/applications/app/models/db.py", line 346\n
Field(\'owner\',db.auth_user,default=auth.user_id,readable=False,writable=False),\n
^\nSyntaxError: invalid syntax\n'

p3755


Also

Before the default behavior was to return generic.html;

Seems like that is no longer the case.

Thanks.


[web2py] Re: Strange Error: Field does not belong to the table

2011-06-17 Thread Anthony
Try:
 
form = SQLFORM(db.auth_user, user, showid=False)
is_administrator = user and auth.has_membership(user_id=user.id, 
role='Administrators')
form[0].insert(-1, TR((
TD(LABEL('Is Administrator', _for='auth_user_is_administrator')),
TD(INPUT(_type='checkbox', _name='is_administrator', 
_id='auth_user_is_administrator',
value=is_administrator)
 
Notice, instead of pre-populating the is_administrator field via 
form.vars.is_administrator=[value], the above pre-populates the filed by 
setting the 'value' argument of the INPUT helper. It appears that using the 
form.vars method does not work when the form/table doesn't contain a Field 
object for the field being pre-populated.
 
Anthony
 

On Monday, June 13, 2011 9:21:51 PM UTC-4, Ross Peoples wrote:

> I am trying to provide an editor for auth_user using SQLFORM. I also am 
> trying to add a checkbox to the bottom of the form to set whether or not the 
> user is an administrator. If so, then the user gets added to an 
> Administrators group when calling form.accepts(). 
>
> The strange part is, the code works fine if you check the box, then click 
> submit, but if you try to uncheck the box, that's when you get the following 
> traceback:
>
>   1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
> 19.
> 20.
> 21.
> 22.
>
> Traceback (most recent call last):
>   File "/media/psf/Python/web2py/gluon/restricted.py", line 192, in restricted
> exec ccode in environment
>   File 
> "/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
>  , line 
> 650, in 
>   File "/media/psf/Python/web2py/gluon/globals.py", line 137, in 
> self._caller = lambda f: f()
>   File "/Users/rosspeoples/Dropbox/Code/Python/web2py/gluon/tools.py", line 
> 2485, in f
> return action(*a, **b)
>   File 
> "/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
>  , line 
> 148, in security
> return update()
>   File 
> "/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
>  , line 
> 143, in update
> return user_form(user)
>   File 
> "/Users/rosspeoples/Dropbox/Code/Python/web2py/applications/init/controllers/administration.py"
>  , line 
> 120, in user_form
> if form.accepts(request.vars, session):
>   File "/media/psf/Python/web2py/gluon/sqlhtml.py", line 1203, in accepts
> self.table._db(self.table._id == self.record.id).update(**fields)
>   File "/Users/rosspeoples/Dropbox/Code/Python/web2py/gluon/dal.py", line 
> 5401, in update
> fields = self.db[tablename]._listify(update_fields,update=True)
>   File "/Users/rosspeoples/Dropbox/Code/Python/web2py/gluon/dal.py", line 
> 4677, in _listify
> raise SyntaxError, 'Field %s does not belong to the table' % name
> SyntaxError: Field is_administrator does not belong to the table
>
> And here is the controller that is adding the checkbox:
>
>  form = SQLFORM(db.auth_user, user, showid=False)
> form[0].insert(-1, TR((
> TD(LABEL('Is Administrator', 
> _for='auth_user_is_administrator')),
> TD(INPUT(_type='checkbox', _name='is_administrator', 
> _id='auth_user_is_administrator'))
> )))
> 
> form.vars.is_administrator = False
> if user:
> if auth.has_membership(user_id=user.id, 
> role='Administrators'):
> form.vars.is_administrator = True
> 
> if form.accepts(request.vars, session):
> admin_group = 
> db(db.auth_group.role=='Administrators').select().first()
> db((db.auth_membership.user_id==user.id) & 
> (db.auth_membership.group_id==admin_group.id)).delete()
> 
> if form.vars.is_administrator:
> db.auth_membership.insert(group_id=admin_group.id, 
> user_id=user.id)
> 
> return 'OK'
> 
> return dict(form=form)
>
> The thing that is driving me nuts is that I am doing exactly what the book 
> says to do:
>
>
> http://web2py.com/book/default/chapter/07#Adding-extra-form-elements-to-SQLFORM
>
> Any thoughts? Thanks.
>


[web2py] Re: File upload bug?

2011-06-17 Thread DJ
Does anyone have experience processing a file's contents (eg. csv) during 
upload? 

Thanks,
Sebastian


[web2py] Re: Download of big files broken

2011-06-17 Thread Stefan Scholl
To Massimo and the list/group:

You asked on Reddit if the only constant is the browser. No it
isn't. But it was the browser which had the problem first, with
smaller files.

For smaller files it was enough to raise the chunk_size. IE8 is
slow, maybe this is the reason?

Firefox 4 failed when I tried to download a 33 MiB file remotely.
IE8 failed for anything above 64 KiB on localhost.


It's almost as if Rocket is so fast because it sends without
regard for any receiver. Direct (localhost) or behind a proxy
(Apache 2.2 on the remote Linux server).
Don't know how this could happen. HTTP isn't ZModem. ;-)


Stefan Scholl  wrote:
> I have a parameters_XXX.py file from the normal web2py (with
> rocket) and used the same IP and port with anyserver.py+Tornado
> (and the other one stopped, of course).
> 
> Tested with web2py 1.91.6. Were there any changes regarding this?
> 
> (I'm still very reluctant to upgrade this project.)
> 
> Massimo Di Pierro  wrote:
>> Try this:
>> 
>> python
> from gluon.main import save_password
> save_password(raw_input('admin password: '),XXX)
>> 
>> This will create a parameters_XXX.py file. It must be in the main
>> web2py folder. Caveats, the admin interface is disabled if you are not
>> form localhost and you are not using https.
>> Hope this helps. Hope to have you back on the mailing list.
>> 
>> 
>> On Jun 17, 8:43 am, Stefan Scholl  wrote:
>>> Now I can't access the admin interface, because the password
>>> isn't set. (It isn't reading the stored password.)
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Stefan Scholl  wrote:
>>> > OK, it was Rocket.
>>>
>>> > Tested it with the old web2py and Tornado 1.2.1 via anyserver.py
>>> > and the download is OK.
>>>
>>> > Stefan Scholl  wrote:
>>> >> The higher value for chunk_size didn't work with a 33 MiB file. Even
>>> >> in Firefox 4.
>>> >> So I tried 1.96.4 (Rocket 1.2.2) on Windows XP.
>>>
>>> >> Made a new and simple app (dtest). The download there uses
>>> >> "response.download(request,db)" as well.
>>>
>>> >> 1 simple table: db.define_table('stuff', Field('file', 'upload'))
>>>
>>> >> Upload of the 33 MiB file via db admin, content listed on
>>> >>http://127.0.0.1:8001/dtest/default/data/select/stuff(default
>>> >> function "data" with "return dict(form=crud())". Download with
>>> >> Internet Explorer 8 (after removing the tag that switches to "Chrome
>>> >> Frame", to have a realistic test like "normal" users).
>>>
>>> >> Download was broken. A few KiB were missing. This was on localhost.
>>> >> Remote tests have even worse results.
>>>
>>> >> On 6 Mai, 17:51, Massimo Di Pierro  wrote:
>>> >>> Can you try 1.95.1
>>>
>>> >>> On May 6, 6:03 am, Stefan Scholl  wrote:
>>>
>>> >>> > The classicdownloadfunction:
>>>
>>> >>> > defdownload():
>>> >>> > return response.download(request, db)
>>>
>>> >>> > I'm developing on localhost (127.0.0.1, no SSL) and one strange thing
>>> >>> > happened: Downloads in IE8 (Windows XP) were all corrupt/broken if
>>> >>> > they weren't below 64KiB in size. Very easy to see with large images.
>>>
>>> >>> > Using a higher value for the argument 'chunk_size' solves this
>>> >>> > problem, up to this new maximum.
>>>
>>> >>> > web2py 1.91.6
>> 
> 
> 


-- 
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/




[web2py] Re: Strange Error: Field does not belong to the table

2011-06-17 Thread Ross Peoples
I tried it in a multitude of ways, (using SQLFORM and SQLFORM.factory) and 
none of them worked. I did not try setting dbio=False and doing it myself, 
however. Perhaps that's what I should have done. Instead, I turned 
is_administrator into something that gets set separately. Not optimal, but 
maybe I will try this route. Can't believe I didn't think to try dbio=False.

Thanks


[web2py] Re: entry level permissions

2011-06-17 Thread Anthony
On Friday, June 17, 2011 2:08:45 PM UTC-4, max wrote: 
>
> i want to give for ceratin records of a table different user 
> permissions. 
> can the authentication of web2py used for this?

 
Look at add_permission and has_permission here: 
http://web2py.com/book/default/chapter/08#Authorization. You can specify 
permissions for tables and record ID's.
 
Or, if you're using CRUD, you can link auth with CRUD: 
http://web2py.com/book/default/chapter/08#Authorization-and-CRUD.
 
Anthony


[web2py] entry level permissions

2011-06-17 Thread max
i want to give for ceratin records of a table different user
permissions.
can the authentication of web2py used for this?


[web2py] Re: sum(decimal field) comes back as float

2011-06-17 Thread Anthony
On Friday, June 17, 2011 1:54:02 PM UTC-4, apple wrote: 
>
> Yes sqlite. 
>
> The book says "SQLite does not handle the decimal type so internally 
> we treat it as a double". However wouldn't it be logical to convert it 
> back to decimal if that is what my tabledef says?

 
Yes, I suppose it would. Maybe Massimo can comment.
 


[web2py] Re: sum(decimal field) comes back as float

2011-06-17 Thread apple
Yes sqlite.

The book says "SQLite does not handle the decimal type so internally
we treat it as a double". However wouldn't it be logical to convert it
back to decimal if that is what my tabledef says?

On Jun 17, 6:40 pm, Anthony  wrote:
> On Friday, June 17, 2011 1:13:26 PM UTC-4, apple wrote:
>
> > I am using the DAL to aggregate SUM a decimal field and the result is
> > a float. Shouldn't the DAL keep it in same format as the underlying
> > field?
>
> Are you using SQLite? As far as I know, it doesn't support decimal fields,
> so I think web2py has to treat them as doubles. 
> Seehttp://web2py.com/book/default/chapter/06#DAL,-Table,-Field.
>
> Anthony


[web2py] Re: sum(decimal field) comes back as float

2011-06-17 Thread Anthony
On Friday, June 17, 2011 1:13:26 PM UTC-4, apple wrote: 
>
> I am using the DAL to aggregate SUM a decimal field and the result is 
> a float. Shouldn't the DAL keep it in same format as the underlying 
> field?

 
Are you using SQLite? As far as I know, it doesn't support decimal fields, 
so I think web2py has to treat them as doubles. See 
http://web2py.com/book/default/chapter/06#DAL,-Table,-Field.
 
Anthony


[web2py] sum(decimal field) comes back as float

2011-06-17 Thread apple
I am using the DAL to aggregate SUM a decimal field and the result is
a float. Shouldn't the DAL keep it in same format as the underlying
field?

More generally I keep coming across the issue that you cannot combine
decimal and float in calculations. So I guess it is better to try and
stick with one or the other. Which is the best choice?




[web2py] Re: Download of big files broken

2011-06-17 Thread Stefan Scholl
I have a parameters_XXX.py file from the normal web2py (with
rocket) and used the same IP and port with anyserver.py+Tornado
(and the other one stopped, of course).

Tested with web2py 1.91.6. Were there any changes regarding this?

(I'm still very reluctant to upgrade this project.)

Massimo Di Pierro  wrote:
> Try this:
> 
> python
 from gluon.main import save_password
 save_password(raw_input('admin password: '),XXX)
> 
> This will create a parameters_XXX.py file. It must be in the main
> web2py folder. Caveats, the admin interface is disabled if you are not
> form localhost and you are not using https.
> Hope this helps. Hope to have you back on the mailing list.
> 
> 
> On Jun 17, 8:43 am, Stefan Scholl  wrote:
>> Now I can't access the admin interface, because the password
>> isn't set. (It isn't reading the stored password.)
>>
>>
>>
>>
>>
>>
>>
>> Stefan Scholl  wrote:
>> > OK, it was Rocket.
>>
>> > Tested it with the old web2py and Tornado 1.2.1 via anyserver.py
>> > and the download is OK.
>>
>> > Stefan Scholl  wrote:
>> >> The higher value for chunk_size didn't work with a 33 MiB file. Even
>> >> in Firefox 4.
>> >> So I tried 1.96.4 (Rocket 1.2.2) on Windows XP.
>>
>> >> Made a new and simple app (dtest). The download there uses
>> >> "response.download(request,db)" as well.
>>
>> >> 1 simple table: db.define_table('stuff', Field('file', 'upload'))
>>
>> >> Upload of the 33 MiB file via db admin, content listed on
>> >>http://127.0.0.1:8001/dtest/default/data/select/stuff(default
>> >> function "data" with "return dict(form=crud())". Download with
>> >> Internet Explorer 8 (after removing the tag that switches to "Chrome
>> >> Frame", to have a realistic test like "normal" users).
>>
>> >> Download was broken. A few KiB were missing. This was on localhost.
>> >> Remote tests have even worse results.
>>
>> >> On 6 Mai, 17:51, Massimo Di Pierro  wrote:
>> >>> Can you try 1.95.1
>>
>> >>> On May 6, 6:03 am, Stefan Scholl  wrote:
>>
>> >>> > The classicdownloadfunction:
>>
>> >>> > defdownload():
>> >>> > return response.download(request, db)
>>
>> >>> > I'm developing on localhost (127.0.0.1, no SSL) and one strange thing
>> >>> > happened: Downloads in IE8 (Windows XP) were all corrupt/broken if
>> >>> > they weren't below 64KiB in size. Very easy to see with large images.
>>
>> >>> > Using a higher value for the argument 'chunk_size' solves this
>> >>> > problem, up to this new maximum.
>>
>> >>> > web2py 1.91.6
> 


-- 
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/




Re: [web2py] Re: Linking directly to an uploaded image

2011-06-17 Thread Vinicius Assef
Thank you all.

Certainly it will go to the book, Bruno. ;-)

--
Vinicius Assef.


On Fri, Jun 17, 2011 at 12:19 PM, Bruno Rocha  wrote:
> The viewer action is only for cosmetics, to work as an URL shortener. The
> filename generated by DAl is so extense.
> BTW: I mentioned in the end of the email:
> "you can always refer directly to the image path (not using the viewer
> function) but you always need to fetch the picture name from db"
> On Fri, Jun 17, 2011 at 11:19 AM, Massimo Di Pierro
>  wrote:
>>
>> I think that is the point. In 'uploads' if you need authorization. In
>> 'static' if you do not. In the latter you do not need to worry about
>> authorization and you can let the web server by-pass web2py (so do not
>> viewer action).
>>
>> On Jun 17, 9:16 am, Anthony  wrote:
>> > Thanks, Bruno -- this is very helpful. With this method, you can't
>> > enforce
>> > authorization, though, right? So this should only be used for uploaded
>> > files
>> > intended to be accessed by anyone.
>> >
>> > Anthony
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Friday, June 17, 2011 6:56:52 AM UTC-4, rochacbruno wrote:
>> > > For security reasons, web2py does not expose the 'uploads' folder to
>> > > the
>> > > user, this folder can be accessed only by the 'download' function.
>> >
>> > > The best way is to set the upload path pointing to /static not to
>> > > /upload
>> > > and you will have your uploaded files to be served as static files,
>> > > bypassing download function.
>> >
>> > > under /static create a folder called 'picture'
>> >
>> > > *Go to the table definition and do this:*
>> >
>> > > **
>> > > db.define_table('announce',
>> >
>> > >
>> > > Field('picture','upload',uploadfolder=request.folder+'static/pictures'),
>> > >                         )
>> > > **
>> >
>> > > You are saying DAL to store uploades files in to that folder under
>> > > static
>> > > and store the ath in the field.
>> >
>> > > Now in your controller create a function do handle that (different
>> > > from
>> > > download, it is a kind of viewer)
>> >
>> > > **
>> > > def viewer():
>> > >     row = db(db.announce.id
>> > > ==request.args(0)).select(db.announce.picture).first()
>> > >     redirect(URL('static','pictures',args=row.picture))
>> > > **
>> >
>> > > *Now you can fo this:*
>> >
>> > >http://server/app/default/viewer/3# record id
>> >
>> > > then you got redirected to the image (no html page)
>> >
>> > > example:
>> >
>> >
>> > > >http://127.0.0.1:8000/app/static/pictures/announce.picture.aaf5d3f777...
>> >
>> > > you can always refer directly to the image path (not using the viewer
>> > > function) but you always need to fetch the picture name from db.
>> >
>> > > Hope it helps.
>> >
>> > > Should go on the book?
>> >
>> > >  --
>> > > Bruno Rocha
>> > > [ About me:http://zerp.ly/rochacbruno]
>> > > [ Aprenda a programar:http://CursoDePython.com.br]
>> >
>> > > On Thu, Jun 16, 2011 at 6:09 AM, Vinicius Assef
>> > > wrote:
>> >
>> > >> Hi guys.
>> >
>> > >> I have a table (called anuncio) with an upload field (called foto),
>> > >> so
>> > >> anuncio.foto is my upload field.
>> >
>> > >> I'm showing and linking it with this piece of code in my view :
>> > >>    {{url = URL(c='anuncios',f='download', args=['uploads',
>> > >> anuncio.foto])}}
>> > >>    {{=A(IMG(_src=url), _href=url)}}
>> >
>> > >> My /contollers/anuncios.py/download() function is the default, as
>> > >> seen
>> > >> below:
>> > >> def download():
>> > >>    return response.download(request,db)
>> >
>> > >> When user clicks on this image, browser shows the download dialog,
>> > >> asking him/her where to save the image.
>> > >> But I'd like to simply show the image, not present the download
>> > >> dialog. All these images will be public.
>> >
>> > >> How I solved it:
>> > >> 1) I entered in /myapp/static/images and created a symbolic link
>> > >> called 'uploads' pointing to /myapp/uploads.
>> > >> 2) In my view, I changed the: {{url = URL(...}} stuff by this: {{url
>> > >> =
>> > >> URL(c='static', f='images', args=['uploads', anuncio.foto])}}
>> >
>> > >> I think this isn't the best choice because I'm pointing URL() to a
>> > >> fake controller and function, and I'm counting on an external
>> > >> resource: a symbolic link in my filesystem.
>> >
>> > >> How would be the "web2pythonic" way to do this?
>> >
>> > >> --
>> > >> Vinicius Assef.
>


[web2py] Re: Altering wizard metadata

2011-06-17 Thread William Tate
Oh dang - sorry about that - I should have looked at the 0.py file.
Thanks again.


[web2py] Re: bug with default view

2011-06-17 Thread Jose


On 17 jun, 11:35, Anthony  wrote:
> On Friday, June 17, 2011 10:16:16 AM UTC-4, Jose wrote:
>
> > Hi,
>
> > In later versions of the trunk the default view does not work. If I
> > create a function without creating ls associated view, should load the
> > default view, well, this is what fails. [invalid view]
>
> Are you having this problem with requests on the local machine, or only
> remote requests? Due to a security vulnerability, generic views are turned
> off by default unless the request is local. In db.py of the 'welcome' app,
> the following has been added:
>
> response.generic_patterns = ['*'] if request.is_local else []
>
> response.generic_patterns is a list of glob patterns that can be used to
> match /controller/function.extension to determine which generic views should
> be available for which controllers and functions. The above line allows all
> generic views, but only when request.is_local is True. You can set the
> generic_patterns centrally in a model file (as above), or you can set it
> within specific controllers or functions. For example:
>
> In default.py:
>
> def myaction():
>     response.generic_patterns = ['html', 'load']
>     # more code
>     return dict(...)
>
> The above will enable generic.html and generic.load views specifically for
> requests to /default/myaction.[html/load].
>
> Anthony

Thanks Anthony.


[web2py] silent registration - how to handle one-off processing

2011-06-17 Thread Carl
I'm allowing some of my users to skip registration and login using
OAuth/LinkedIn.

I still want to perform some one-off code.
What's the best approach with Web2py?

I see in gluon/tools.py that Auth.get_or_create_user() checks if
'user' is valid and if not... calls self.add_membership()

How can I do something similar?


Re: [web2py] Re: Linking directly to an uploaded image

2011-06-17 Thread Bruno Rocha
The viewer action is only for cosmetics, to work as an URL shortener. The
filename generated by DAl is so extense.

BTW: I mentioned in the end of the email:

"you can always refer directly to the image path (not using the viewer
function) but you always need to fetch the picture name from db"

On Fri, Jun 17, 2011 at 11:19 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> I think that is the point. In 'uploads' if you need authorization. In
> 'static' if you do not. In the latter you do not need to worry about
> authorization and you can let the web server by-pass web2py (so do not
> viewer action).
>
> On Jun 17, 9:16 am, Anthony  wrote:
> > Thanks, Bruno -- this is very helpful. With this method, you can't
> enforce
> > authorization, though, right? So this should only be used for uploaded
> files
> > intended to be accessed by anyone.
> >
> > Anthony
> >
> >
> >
> >
> >
> >
> >
> > On Friday, June 17, 2011 6:56:52 AM UTC-4, rochacbruno wrote:
> > > For security reasons, web2py does not expose the 'uploads' folder to
> the
> > > user, this folder can be accessed only by the 'download' function.
> >
> > > The best way is to set the upload path pointing to /static not to
> /upload
> > > and you will have your uploaded files to be served as static files,
> > > bypassing download function.
> >
> > > under /static create a folder called 'picture'
> >
> > > *Go to the table definition and do this:*
> >
> > > **
> > > db.define_table('announce',
> >
> > >
> Field('picture','upload',uploadfolder=request.folder+'static/pictures'),
> > > )
> > > **
> >
> > > You are saying DAL to store uploades files in to that folder under
> static
> > > and store the ath in the field.
> >
> > > Now in your controller create a function do handle that (different from
> > > download, it is a kind of viewer)
> >
> > > **
> > > def viewer():
> > > row = db(db.announce.id
> > > ==request.args(0)).select(db.announce.picture).first()
> > > redirect(URL('static','pictures',args=row.picture))
> > > **
> >
> > > *Now you can fo this:*
> >
> > >http://server/app/default/viewer/3# record id
> >
> > > then you got redirected to the image (no html page)
> >
> > > example:
> >
> > >http://127.0.0.1:8000/app/static/pictures/announce.picture.aaf5d3f777.
> ..
> >
> > > you can always refer directly to the image path (not using the viewer
> > > function) but you always need to fetch the picture name from db.
> >
> > > Hope it helps.
> >
> > > Should go on the book?
> >
> > >  --
> > > Bruno Rocha
> > > [ About me:http://zerp.ly/rochacbruno]
> > > [ Aprenda a programar:http://CursoDePython.com.br]
> >
> > > On Thu, Jun 16, 2011 at 6:09 AM, Vinicius Assef  >wrote:
> >
> > >> Hi guys.
> >
> > >> I have a table (called anuncio) with an upload field (called foto), so
> > >> anuncio.foto is my upload field.
> >
> > >> I'm showing and linking it with this piece of code in my view :
> > >>{{url = URL(c='anuncios',f='download', args=['uploads',
> > >> anuncio.foto])}}
> > >>{{=A(IMG(_src=url), _href=url)}}
> >
> > >> My /contollers/anuncios.py/download() function is the default, as
> seen
> > >> below:
> > >> def download():
> > >>return response.download(request,db)
> >
> > >> When user clicks on this image, browser shows the download dialog,
> > >> asking him/her where to save the image.
> > >> But I'd like to simply show the image, not present the download
> > >> dialog. All these images will be public.
> >
> > >> How I solved it:
> > >> 1) I entered in /myapp/static/images and created a symbolic link
> > >> called 'uploads' pointing to /myapp/uploads.
> > >> 2) In my view, I changed the: {{url = URL(...}} stuff by this: {{url =
> > >> URL(c='static', f='images', args=['uploads', anuncio.foto])}}
> >
> > >> I think this isn't the best choice because I'm pointing URL() to a
> > >> fake controller and function, and I'm counting on an external
> > >> resource: a symbolic link in my filesystem.
> >
> > >> How would be the "web2pythonic" way to do this?
> >
> > >> --
> > >> Vinicius Assef.
>


Re: [web2py] Re: import error

2011-06-17 Thread Pierre Thibault
2011/6/17 Massimo Di Pierro 

> uploading your fix to trunk.
>
> On Jun 17, 8:50 am, amit  wrote:
> > I am getting the same import error as the OP. The problem occurs when
> > an external module calls __import__ but has passed globals=None. The
> > following patch in gluon/custom_import.py fixes it for me, since in
> > this case, web2py does not need to perform any customized import.
> >
>
> > 255c255
> > < and not name.startswith("applications."):
> > ---
> >
> > > and not name.startswith("applications.") and not
> globals==None:
> >
>

Exact. I prefer "and isinstance(globals, dict)" to "not globals==None".

Note that this patch means that the "modules" directory not be searched in
that case.
-- 


A+

-
Pierre
My blog and profile
(http://pierrethibault.posterous.com)
YouTube page 
(http://www.youtube.com/user/tubetib)
Twitter (http://twitter.com/pierreth2) 


[web2py] treads versus processes

2011-06-17 Thread KMax
This is information I want to share.

I guess this is not America, but it will be usefull for someone.
> Lets begin with test results
All tests done with web2py 1.96.4, apache2.2.16/mod_wsgi 3.3/python 
2.6.6/debian64, AMD64 4x 3.2Ghz
> Test #1
WSGIDaemonProcess web2py user=kmax group=kmax home=/home/kmax/web/web2py 
processes=1 threads=4 maximum-requests=1000
MEM by wsgi daemon
#1 VIRT:356m  RES:45m SHR:5348 
$ ab -n 1000 -c 4 http://web2py.ru/welcome/default/index
Document Path:  /welcome/default/index
Document Length:10442 bytes
Concurrency Level:  4
Time taken for tests:   54.334 seconds
Complete requests:  1000
Failed requests:0
Write errors:   0
Requests per second:18.40 [#/sec] (mean)
Time per request:   217.334 [ms] (mean)
Time per request:   54.334 [ms] (mean, across all concurrent requests)
Transfer rate:  195.29 [Kbytes/sec] received

Connection Times (ms)
  min  mean[+/-sd] median   max
Connect:00   0.1  0   1
Processing:   153  217  23.3216 497
Waiting:  153  216  23.2216 496
Total:154  217  23.3216 498

Percentage of the requests served within a certain time (ms)
  50%216
  66%224
  75%228
  80%231
  90%241
  95%247
  98%257
  99%264
 100%498 (longest request)

###
>Test #2
WSGIDaemonProcess web2py user=kmax group=kmax home=/home/kmax/web/web2py 
processes=4 threads=1 maximum-requests=1000
MEM by wsgi daemons
#1 VIRT:201m  RES:26m SHR:5336
#2 VIRT:201m  RES:26m SHR:5336
#3 VIRT:201m  RES:26m SHR:5336
#4 VIRT:201m  RES:26m SHR:5336
$ ab -n 1000 -c 4 http://web2py.ru/welcome/default/index
Document Path:  /welcome/default/index
Document Length:10442 bytes

Concurrency Level:  4
Time taken for tests:   5.324 seconds
Complete requests:  1000
Failed requests:0
Write errors:   0
Total transferred:  10859098 bytes
HTML transferred:   10442000 bytes
Requests per second:187.82 [#/sec] (mean)
Time per request:   21.297 [ms] (mean)
Time per request:   5.324 [ms] (mean, across all concurrent requests)
Transfer rate:  1991.74 [Kbytes/sec] received

Connection Times (ms)
  min  mean[+/-sd] median   max
Connect:00   0.1  0   1
Processing:18   21  13.5 19 239
Waiting:   18   21  13.5 19 239
Total: 18   21  13.5 19 240

Percentage of the requests served within a certain time (ms)
  50% 19
  66% 20
  75% 20
  80% 20
  90% 23
  95% 25
  98% 29
  99% 46
 100%240 (longest request)

###
>Test #3
WSGIDaemonProcess web2py user=kmax group=kmax home=/home/kmax/web/web2py 
processes=1 threads=1 maximum-requests=1000
MEM by wsgi daemon
#1  VIRT:202m  RES:27m SHR:5344
kmax@PEAKTOP:~$ ab -n 1000 -c 4 http://web2py.ru/welcome/default/index
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking web2py.ru (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:nginx/1.0.4
Server Hostname:web2py.ru
Server Port:80

Document Path:  /welcome/default/index
Document Length:10442 bytes

Concurrency Level:  4
Time taken for tests:   18.126 seconds
Complete requests:  1000
Failed requests:0
Write errors:   0
Total transferred:  1087 bytes
HTML transferred:   10442000 bytes
Requests per second:55.17 [#/sec] (mean)
Time per request:   72.503 [ms] (mean)
Time per request:   18.126 [ms] (mean, across all concurrent requests)
Transfer rate:  585.65 [Kbytes/sec] received

Connection Times (ms)
  min  mean[+/-sd] median   max
Connect:00   0.1  0   2
Processing:68   72  12.5 70 281
Waiting:   68   72  12.5 69 281
Total: 68   72  12.5 70 281

Percentage of the requests served within a certain time (ms)
  50% 70
  66% 72
  75% 73
  80% 73
  90% 73
  95% 74
  98% 92
  99% 92
 100%281 (longest request)
==
> Test #4
Same configuration as above but with only one request at same time.
$ ab -n 1000 -c 1 http://web2py.ru/welcome/default/index
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking web2py.ru (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Co

[web2py] Re: bug with default view

2011-06-17 Thread Anthony
On Friday, June 17, 2011 10:16:16 AM UTC-4, Jose wrote: 
>
> Hi, 
>
> In later versions of the trunk the default view does not work. If I 
> create a function without creating ls associated view, should load the 
> default view, well, this is what fails. [invalid view]

 
Are you having this problem with requests on the local machine, or only 
remote requests? Due to a security vulnerability, generic views are turned 
off by default unless the request is local. In db.py of the 'welcome' app, 
the following has been added:
 
response.generic_patterns = ['*'] if request.is_local else []
 
 
response.generic_patterns is a list of glob patterns that can be used to 
match /controller/function.extension to determine which generic views should 
be available for which controllers and functions. The above line allows all 
generic views, but only when request.is_local is True. You can set the 
generic_patterns centrally in a model file (as above), or you can set it 
within specific controllers or functions. For example:
 
In default.py:
 
def myaction():
response.generic_patterns = ['html', 'load']
# more code
return dict(...)
 
The above will enable generic.html and generic.load views specifically for 
requests to /default/myaction.[html/load].
 
Anthony


Re: [web2py] Re: user table just minimal customization

2011-06-17 Thread Manuele Pesenti

On 17/06/2011 16:23, Anthony wrote:

On Friday, June 17, 2011 10:20:49 AM UTC-4, Manuele wrote:

...
auth.define_tables(username=True)
auth.settings.extra_fields['auth_user'].append(
Fields('company', db.company, required=True, notnull=True,
requires=IS_IN_DB(db, 'company.id ', '%(name)s'))
)
auth.define_tables() # creates all needed tables

You've got auth.define_tables twice -- once before and once after.


I solved in this way defining the dict entry "auth_user"... in this way 
everything works fine


db.define_table('company',
Field('name'),
format = '%(name)s'
)

auth.settings.extra_fields['auth_user'] = [
Field('company', db.company, required=True, requires=IS_IN_DB(db, 
'company.id', '%(name)s'))

]
auth.define_tables(username=True)   # creates all needed tables

cheers

Manuele


[web2py] Re: Altering wizard metadata

2011-06-17 Thread Massimo Di Pierro
Unfortunately the wizard still experimental. If you want to setup
email for an existing app I suggest you edit the model files (0.py and/
or db.py).

Massimo

On Jun 17, 7:19 am, William Tate  wrote:
> I created an application some time ago using the wizard but I did not
> set the email settings at the time.  They're correct in the db.py file
> but I still can't get the email function to work.  In interactive
> mode, it's picking up settings (I think) from wizard.metadata file.
>
> A test application built with the wizard with the correct settings at
> the start works fine.
>
> Is there something I can do to edit that metadata file or should I
> edit it elsewhere.  Settings in db.py are up to date.
>
> I'm pretty sure I'm just missing something simple here.  Thanks in
> advance.
>
> BTW - WEB2PY absolutely rocks!  I've never had so much fun building a
> web application before.


[web2py] Re: import error

2011-06-17 Thread Massimo Di Pierro
uploading your fix to trunk.

On Jun 17, 8:50 am, amit  wrote:
> I am getting the same import error as the OP. The problem occurs when
> an external module calls __import__ but has passed globals=None. The
> following patch in gluon/custom_import.py fixes it for me, since in
> this case, web2py does not need to perform any customized import.
>

> 255c255
> <                 and not name.startswith("applications."):
> ---
>
> >                 and not name.startswith("applications.") and not 
> > globals==None:
>
> On Jun 17, 5:07 pm, selecta  wrote:
>
>
>
>
>
>
>
> > I also have problems importing pygments from the modules 
> > directoryhttp://jaguar.biologie.hu-berlin.de/~fkrause/web2py.app.pygments_test...
>
> > i downloaded pygments fromhttp://pypi.python.org/pypi/Pygments
>
> > and wrote in db.py
> > from pygments import highlight
> > from pygments.formatters import HtmlFormatter
> > import pygments.lexers
>
> > Traceback (most recent call last):
> >   File "/home/fkrause/Downloads/tmp/web2py/gluon/restricted.py", line
> > 192, in restricted
> >     exec ccode in environment
> >   File "/home/fkrause/Downloads/tmp/web2py/applications/pygments_test/
> > models/db.py", line 10, in 
> >     import pygments.lexers
> >   File "/home/fkrause/Downloads/tmp/web2py/gluon/custom_import.py",
> > line 271, in __call__
> >     globals, locals, fromlist, level)
> >   File "/home/fkrause/Downloads/tmp/web2py/gluon/custom_import.py",
> > line 299, in __import__dot
> >     locals, [name], level)
> >   File "/home/fkrause/Downloads/tmp/web2py/gluon/custom_import.py",
> > line 75, in __call__
> >     level)
> >   File "applications/pygments_test/modules/pygments/lexers/
> > __init__.py", line 222, in 
> >     oldmod = sys.modules['pygments.lexers']
> > KeyError: 'pygments.lexers'
>
> > On Jun 17, 10:57 am, selecta  wrote:
>
> > > I send you a test app that reproduces the error
> > > in case somebody else wants to test/debug you can download it 
> > > fromhttp://jaguar.biologie.hu-berlin.de/~fkrause/web2py.app.w2popenid_tes...
>
> > > On Jun 17, 4:32 am, Pierre Thibault 
> > > wrote:
>
> > > > 2011/6/15 Massimo Di Pierro 
>
> > > > > looking into this...
>
> > > > Still no news. Should we forget this issue? I really would like to 
> > > > debug but
> > > > I don't have enough information. It seems the bug is very rare.
>
> > > > > On Jun 15, 8:12 am, "mb_...@yahoo.fr"  wrote:
> > > > > > I wanted to use the w2popenid example application from bitbucket
> > > > > > website :https://bitbucket.org/bottiger/web2py-openid/overview
> > > > > >  I have downloaded and placed the code in the applications 
> > > > > > directory.
> > > > > > I have changed in the models folder the file db.py: this line "from
> > > > > > applications.cas.modules.w2popenid import OpenIDLogin" is replaced
> > > > > > with this one "from w2popenid import OpenIDLogin" or this "from
> > > > > > applications.w2popenid.modules.import OpenIDLogin". But it don't
> > > > > > worked. I get to follow this trace
> > > > > > Traceback (most recent call last):
> > > > > >   File "/home/mamadou/Desktop/web2py/gluon/restricted.py", line 192,
> > > > > > in restricted
> > > > > >     exec ccode in environment
> > > > > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/models/
> > > > > > db.py", line 42, in 
> > > > > >     from testing import lala
> > > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > > > 280, in __call__
> > > > > >     fromlist, level)
> > > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 
> > > > > > 75,
> > > > > > in __call__
> > > > > >     level)
> > > > > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/modules/
> > > > > > testing.py", line 7, in 
> > > > > >     import openid.consumer.consumer
> > > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > > > 280, in __call__
> > > > > >     fromlist, level)
> > > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 
> > > > > > 75,
> > > > > > in __call__
> > > > > >     level)
> > > > > >   File "/usr/lib/pymodules/python2.7/openid/consumer/consumer.py",
> > > > > > line 197, in 
> > > > > >     from openid.consumer.discover import discover,
> > > > > > OpenIDServiceEndpoint, \
> > > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > > > 280, in __call__
> > > > > >     fromlist, level)
> > > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 
> > > > > > 75,
> > > > > > in __call__
> > > > > >     level)
> > > > > >   File "/usr/lib/pymodules/python2.7/openid/consumer/discover.py",
> > > > > > line 21, in 
> > > > > >     from openid.yadis.etxrd import nsTag, XRDSError, XRD_NS_2_0
> > > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > > > 280, in __call__
> > > > > >     fromlist, level)
> > > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 
> > > > > > 75,

Re: [web2py] Re: user table just minimal customization

2011-06-17 Thread Anthony
On Friday, June 17, 2011 10:20:49 AM UTC-4, Manuele wrote: 
>
> ...
> auth.define_tables(username=True)
> auth.settings.extra_fields['auth_user'].append(
>  Fields('company', db.company, required=True, notnull=True,
>  requires=IS_IN_DB(db, 'company.id', '%(name)s'))
> )
> auth.define_tables()# creates all needed tables
>
You've got auth.define_tables twice -- once before and once after.


[web2py] Re: Download of big files broken

2011-06-17 Thread Massimo Di Pierro
Try this:

python
>>> from gluon.main import save_password
>>> save_password(raw_input('admin password: '),XXX)

This will create a parameters_XXX.py file. It must be in the main
web2py folder. Caveats, the admin interface is disabled if you are not
form localhost and you are not using https.
Hope this helps. Hope to have you back on the mailing list.


On Jun 17, 8:43 am, Stefan Scholl  wrote:
> Now I can't access the admin interface, because the password
> isn't set. (It isn't reading the stored password.)
>
>
>
>
>
>
>
> Stefan Scholl  wrote:
> > OK, it was Rocket.
>
> > Tested it with the old web2py and Tornado 1.2.1 via anyserver.py
> > and the download is OK.
>
> > Stefan Scholl  wrote:
> >> The higher value for chunk_size didn't work with a 33 MiB file. Even
> >> in Firefox 4.
> >> So I tried 1.96.4 (Rocket 1.2.2) on Windows XP.
>
> >> Made a new and simple app (dtest). The download there uses
> >> "response.download(request,db)" as well.
>
> >> 1 simple table: db.define_table('stuff', Field('file', 'upload'))
>
> >> Upload of the 33 MiB file via db admin, content listed on
> >>http://127.0.0.1:8001/dtest/default/data/select/stuff(default
> >> function "data" with "return dict(form=crud())". Download with
> >> Internet Explorer 8 (after removing the tag that switches to "Chrome
> >> Frame", to have a realistic test like "normal" users).
>
> >> Download was broken. A few KiB were missing. This was on localhost.
> >> Remote tests have even worse results.
>
> >> On 6 Mai, 17:51, Massimo Di Pierro  wrote:
> >>> Can you try 1.95.1
>
> >>> On May 6, 6:03 am, Stefan Scholl  wrote:
>
> >>> > The classicdownloadfunction:
>
> >>> > defdownload():
> >>> > return response.download(request, db)
>
> >>> > I'm developing on localhost (127.0.0.1, no SSL) and one strange thing
> >>> > happened: Downloads in IE8 (Windows XP) were all corrupt/broken if
> >>> > they weren't below 64KiB in size. Very easy to see with large images.
>
> >>> > Using a higher value for the argument 'chunk_size' solves this
> >>> > problem, up to this new maximum.
>
> >>> > web2py 1.91.6


Re: [web2py] Re: user table just minimal customization

2011-06-17 Thread Manuele Pesenti

On 17/06/2011 15:58, Anthony wrote:

On Friday, June 17, 2011 9:38:09 AM UTC-4, Manuele wrote:

is there a way to add just a single field to the user table without
re-wrintig a customized version as explained in

http://www.web2py.com/book/default/chapter/08#Customizing-Auth


I mean... if I only want to add "username" field in order to use it in
place of email during user login... how can I do it? if I can...

Specifically for adding a username field to to be used for login, you
can do:
auth.define_tables(username=True)
See http://web2py.com/book/default/chapter/08#Authentication.
More generally, as of 1.96.1, you can add custom fields to any auth
table with:
auth.settings.extra_fields['auth_table_name_goes_here'].append(Fields('new_field_name',...))
Anthony


found this feature that you cite:

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

'''
auth.settings.extra_fields['auth_user'].append(Field('country')) allows 
to extend auth_* tables without need of definiting a custom auth_* 
table. Must be placed before auth.define_tables()

'''

but applied as written I got a KeyError: 'auth_user'. I thik I have 
correcly applied as reported here under (I'm using a 1.96.4 version)


...
auth.define_tables(username=True)
auth.settings.extra_fields['auth_user'].append(
Fields('company', db.company, required=True, notnull=True,
requires=IS_IN_DB(db, 'company.id', '%(name)s'))
)
auth.define_tables()# creates all needed tables
...

thanks

Manuele


[web2py] Re: Linking directly to an uploaded image

2011-06-17 Thread Massimo Di Pierro
I think that is the point. In 'uploads' if you need authorization. In
'static' if you do not. In the latter you do not need to worry about
authorization and you can let the web server by-pass web2py (so do not
viewer action).

On Jun 17, 9:16 am, Anthony  wrote:
> Thanks, Bruno -- this is very helpful. With this method, you can't enforce
> authorization, though, right? So this should only be used for uploaded files
> intended to be accessed by anyone.
>
> Anthony
>
>
>
>
>
>
>
> On Friday, June 17, 2011 6:56:52 AM UTC-4, rochacbruno wrote:
> > For security reasons, web2py does not expose the 'uploads' folder to the
> > user, this folder can be accessed only by the 'download' function.
>
> > The best way is to set the upload path pointing to /static not to /upload
> > and you will have your uploaded files to be served as static files,
> > bypassing download function.
>
> > under /static create a folder called 'picture'
>
> > *Go to the table definition and do this:*
>
> > **
> > db.define_table('announce',
>
> > Field('picture','upload',uploadfolder=request.folder+'static/pictures'),
> >                         )
> > **
>
> > You are saying DAL to store uploades files in to that folder under static
> > and store the ath in the field.
>
> > Now in your controller create a function do handle that (different from
> > download, it is a kind of viewer)
>
> > **
> > def viewer():
> >     row = db(db.announce.id
> > ==request.args(0)).select(db.announce.picture).first()
> >     redirect(URL('static','pictures',args=row.picture))
> > **
>
> > *Now you can fo this:*
>
> >http://server/app/default/viewer/3# record id
>
> > then you got redirected to the image (no html page)
>
> > example:
>
> >http://127.0.0.1:8000/app/static/pictures/announce.picture.aaf5d3f777...
>
> > you can always refer directly to the image path (not using the viewer
> > function) but you always need to fetch the picture name from db.
>
> > Hope it helps.
>
> > Should go on the book?
>
> >  --
> > Bruno Rocha
> > [ About me:http://zerp.ly/rochacbruno]
> > [ Aprenda a programar:http://CursoDePython.com.br]
>
> > On Thu, Jun 16, 2011 at 6:09 AM, Vinicius Assef wrote:
>
> >> Hi guys.
>
> >> I have a table (called anuncio) with an upload field (called foto), so
> >> anuncio.foto is my upload field.
>
> >> I'm showing and linking it with this piece of code in my view :
> >>    {{url = URL(c='anuncios',f='download', args=['uploads',
> >> anuncio.foto])}}
> >>    {{=A(IMG(_src=url), _href=url)}}
>
> >> My /contollers/anuncios.py/download() function is the default, as seen
> >> below:
> >> def download():
> >>    return response.download(request,db)
>
> >> When user clicks on this image, browser shows the download dialog,
> >> asking him/her where to save the image.
> >> But I'd like to simply show the image, not present the download
> >> dialog. All these images will be public.
>
> >> How I solved it:
> >> 1) I entered in /myapp/static/images and created a symbolic link
> >> called 'uploads' pointing to /myapp/uploads.
> >> 2) In my view, I changed the: {{url = URL(...}} stuff by this: {{url =
> >> URL(c='static', f='images', args=['uploads', anuncio.foto])}}
>
> >> I think this isn't the best choice because I'm pointing URL() to a
> >> fake controller and function, and I'm counting on an external
> >> resource: a symbolic link in my filesystem.
>
> >> How would be the "web2pythonic" way to do this?
>
> >> --
> >> Vinicius Assef.


[web2py] Re: Linking directly to an uploaded image

2011-06-17 Thread Massimo Di Pierro
This is fine:

db.define_table('announce',
Field('picture','upload',uploadfolder=request.folder+'static/
pictures'),
)

but why do you need an action to download from the static folder? Why
not simply use

URL('static',record.picture)



On Jun 17, 5:56 am, Bruno Rocha  wrote:
> For security reasons, web2py does not expose the 'uploads' folder to the
> user, this folder can be accessed only by the 'download' function.
>
> The best way is to set the upload path pointing to /static not to /upload
> and you will have your uploaded files to be served as static files,
> bypassing download function.
>
> under /static create a folder called 'picture'
>
> *Go to the table definition and do this:*
>
> **
> db.define_table('announce',
>
> Field('picture','upload',uploadfolder=request.folder+'static/pictures'),
>                         )
> **
>
> You are saying DAL to store uploades files in to that folder under static
> and store the ath in the field.
>
> Now in your controller create a function do handle that (different from
> download, it is a kind of viewer)
>
> **
> def viewer():
>     row = db(db.announce.id
> ==request.args(0)).select(db.announce.picture).first()
>     redirect(URL('static','pictures',args=row.picture))
> **
>
> *Now you can fo this:*
>
> http://server/app/default/viewer/3# record id
>
> then you got redirected to the image (no html page)
>
> example:http://127.0.0.1:8000/app/static/pictures/announce.picture.aaf5d3f777...
>
> you can always refer directly to the image path (not using the viewer
> function) but you always need to fetch the picture name from db.
>
> Hope it helps.
>
> Should go on the book?
>
> --
> Bruno Rocha
> [ About me:http://zerp.ly/rochacbruno]
> [ Aprenda a programar:http://CursoDePython.com.br]
>
> On Thu, Jun 16, 2011 at 6:09 AM, Vinicius Assef wrote:
>
>
>
>
>
>
>
> > Hi guys.
>
> > I have a table (called anuncio) with an upload field (called foto), so
> > anuncio.foto is my upload field.
>
> > I'm showing and linking it with this piece of code in my view :
> >    {{url = URL(c='anuncios',f='download', args=['uploads', anuncio.foto])}}
> >    {{=A(IMG(_src=url), _href=url)}}
>
> > My /contollers/anuncios.py/download() function is the default, as seen
> > below:
> > def download():
> >    return response.download(request,db)
>
> > When user clicks on this image, browser shows the download dialog,
> > asking him/her where to save the image.
> > But I'd like to simply show the image, not present the download
> > dialog. All these images will be public.
>
> > How I solved it:
> > 1) I entered in /myapp/static/images and created a symbolic link
> > called 'uploads' pointing to /myapp/uploads.
> > 2) In my view, I changed the: {{url = URL(...}} stuff by this: {{url =
> > URL(c='static', f='images', args=['uploads', anuncio.foto])}}
>
> > I think this isn't the best choice because I'm pointing URL() to a
> > fake controller and function, and I'm counting on an external
> > resource: a symbolic link in my filesystem.
>
> > How would be the "web2pythonic" way to do this?
>
> > --
> > Vinicius Assef.


Re: [web2py] Linking directly to an uploaded image

2011-06-17 Thread Anthony
Thanks, Bruno -- this is very helpful. With this method, you can't enforce 
authorization, though, right? So this should only be used for uploaded files 
intended to be accessed by anyone.
 
Anthony

On Friday, June 17, 2011 6:56:52 AM UTC-4, rochacbruno wrote:

> For security reasons, web2py does not expose the 'uploads' folder to the 
> user, this folder can be accessed only by the 'download' function. 
>  
> The best way is to set the upload path pointing to /static not to /upload 
> and you will have your uploaded files to be served as static files, 
> bypassing download function.
>
> under /static create a folder called 'picture' 
>
> *Go to the table definition and do this:*
>
> **
> db.define_table('announce',
> 
> Field('picture','upload',uploadfolder=request.folder+'static/pictures'),
> )
> **
>
> You are saying DAL to store uploades files in to that folder under static 
> and store the ath in the field.
>
> Now in your controller create a function do handle that (different from 
> download, it is a kind of viewer)
>
> **
> def viewer():
> row = db(db.announce.id
> ==request.args(0)).select(db.announce.picture).first()
> redirect(URL('static','pictures',args=row.picture)) 
> **
>
> *Now you can fo this:*
>
> http://server/app/default/viewer/3 # record id
>
> then you got redirected to the image (no html page)
>
> example:
>
> http://127.0.0.1:8000/app/static/pictures/announce.picture.aaf5d3f7779841d0.6e65775f64616c5f68656c702e706466.jpg
>
> you can always refer directly to the image path (not using the viewer 
> function) but you always need to fetch the picture name from db.
>
> Hope it helps.
>
> Should go on the book?
>
>
>  --
> Bruno Rocha
> [ About me: http://zerp.ly/rochacbruno ]
> [ Aprenda a programar: http://CursoDePython.com.br ]
>
>
>
> On Thu, Jun 16, 2011 at 6:09 AM, Vinicius Assef wrote:
>
>> Hi guys.
>>
>> I have a table (called anuncio) with an upload field (called foto), so
>> anuncio.foto is my upload field.
>>
>> I'm showing and linking it with this piece of code in my view :
>>{{url = URL(c='anuncios',f='download', args=['uploads', 
>> anuncio.foto])}}
>>{{=A(IMG(_src=url), _href=url)}}
>>
>> My /contollers/anuncios.py/download() function is the default, as seen 
>> below:
>> def download():
>>return response.download(request,db)
>>
>> When user clicks on this image, browser shows the download dialog,
>> asking him/her where to save the image.
>> But I'd like to simply show the image, not present the download
>> dialog. All these images will be public.
>>
>> How I solved it:
>> 1) I entered in /myapp/static/images and created a symbolic link
>> called 'uploads' pointing to /myapp/uploads.
>> 2) In my view, I changed the: {{url = URL(...}} stuff by this: {{url =
>> URL(c='static', f='images', args=['uploads', anuncio.foto])}}
>>
>> I think this isn't the best choice because I'm pointing URL() to a
>> fake controller and function, and I'm counting on an external
>> resource: a symbolic link in my filesystem.
>>
>> How would be the "web2pythonic" way to do this?
>>
>> --
>> Vinicius Assef.
>>
>
>

[web2py] bug with default view

2011-06-17 Thread Jose
Hi,

In later versions of the trunk the default view does not work. If I
create a function without creating ls associated view, should load the
default view, well, this is what fails. [invalid view]

Jose


[web2py] Altering wizard metadata

2011-06-17 Thread William Tate
I created an application some time ago using the wizard but I did not
set the email settings at the time.  They're correct in the db.py file
but I still can't get the email function to work.  In interactive
mode, it's picking up settings (I think) from wizard.metadata file.

A test application built with the wizard with the correct settings at
the start works fine.

Is there something I can do to edit that metadata file or should I
edit it elsewhere.  Settings in db.py are up to date.

I'm pretty sure I'm just missing something simple here.  Thanks in
advance.

BTW - WEB2PY absolutely rocks!  I've never had so much fun building a
web application before.


[web2py] Re: [tip] reference guide for context [request, response] objects

2011-06-17 Thread Anthony
Bruno, is that page using the latest version of generic.html? I notice that 
it is displaying the toolbar at the bottom of the page (i.e., buttons for 
admin, request, session, and response). However, the toolbar is only 
supposed to display if request.is_local is True (I see the same thing with 
the hello6 example). Does request.is_local not work properly on web2py.com?
 
Anthony

On Friday, June 17, 2011 7:38:02 AM UTC-4, rochacbruno wrote:

>  Sometimes you want to know which objects are in the default web2py 
> context [response, request]
>
> Sometimes you do not want to start web2py locally to see that, go to: 
> http://bit.ly/web2pycontext
>
> Hope it helps!
>
>
>
>
>  --
> Bruno Rocha
> [ About me: http://zerp.ly/rochacbruno ]
> [ Aprenda a programar: http://CursoDePython.com.br ]
>


[web2py] Re: user table just minimal customization

2011-06-17 Thread Anthony
On Friday, June 17, 2011 9:38:09 AM UTC-4, Manuele wrote: 
>
> is there a way to add just a single field to the user table without 
> re-wrintig a customized version as explained in 
>
> http://www.web2py.com/book/default/chapter/08#Customizing-Auth 
>
> I mean... if I only want to add "username" field in order to use it in 
> place of email during user login... how can I do it? if I can...
>
Specifically for adding a username field to to be used for login, you can 
do:
 
auth.define_tables(username=True)
 
See http://web2py.com/book/default/chapter/08#Authentication.
 
More generally, as of 1.96.1, you can add custom fields to any auth table 
with:
 
auth.settings.extra_fields['auth_table_name_goes_here'].append(Fields('new_field_name',...))
 
 
Anthony


[web2py] Re: import error

2011-06-17 Thread amit
I am getting the same import error as the OP. The problem occurs when
an external module calls __import__ but has passed globals=None. The
following patch in gluon/custom_import.py fixes it for me, since in
this case, web2py does not need to perform any customized import.


255c255
< and not name.startswith("applications."):
---
> and not name.startswith("applications.") and not 
> globals==None:



On Jun 17, 5:07 pm, selecta  wrote:
> I also have problems importing pygments from the modules 
> directoryhttp://jaguar.biologie.hu-berlin.de/~fkrause/web2py.app.pygments_test...
>
> i downloaded pygments fromhttp://pypi.python.org/pypi/Pygments
>
> and wrote in db.py
> from pygments import highlight
> from pygments.formatters import HtmlFormatter
> import pygments.lexers
>
> Traceback (most recent call last):
>   File "/home/fkrause/Downloads/tmp/web2py/gluon/restricted.py", line
> 192, in restricted
>     exec ccode in environment
>   File "/home/fkrause/Downloads/tmp/web2py/applications/pygments_test/
> models/db.py", line 10, in 
>     import pygments.lexers
>   File "/home/fkrause/Downloads/tmp/web2py/gluon/custom_import.py",
> line 271, in __call__
>     globals, locals, fromlist, level)
>   File "/home/fkrause/Downloads/tmp/web2py/gluon/custom_import.py",
> line 299, in __import__dot
>     locals, [name], level)
>   File "/home/fkrause/Downloads/tmp/web2py/gluon/custom_import.py",
> line 75, in __call__
>     level)
>   File "applications/pygments_test/modules/pygments/lexers/
> __init__.py", line 222, in 
>     oldmod = sys.modules['pygments.lexers']
> KeyError: 'pygments.lexers'
>
> On Jun 17, 10:57 am, selecta  wrote:
>
>
>
>
>
>
>
> > I send you a test app that reproduces the error
> > in case somebody else wants to test/debug you can download it 
> > fromhttp://jaguar.biologie.hu-berlin.de/~fkrause/web2py.app.w2popenid_tes...
>
> > On Jun 17, 4:32 am, Pierre Thibault 
> > wrote:
>
> > > 2011/6/15 Massimo Di Pierro 
>
> > > > looking into this...
>
> > > Still no news. Should we forget this issue? I really would like to debug 
> > > but
> > > I don't have enough information. It seems the bug is very rare.
>
> > > > On Jun 15, 8:12 am, "mb_...@yahoo.fr"  wrote:
> > > > > I wanted to use the w2popenid example application from bitbucket
> > > > > website :https://bitbucket.org/bottiger/web2py-openid/overview
> > > > >  I have downloaded and placed the code in the applications directory.
> > > > > I have changed in the models folder the file db.py: this line "from
> > > > > applications.cas.modules.w2popenid import OpenIDLogin" is replaced
> > > > > with this one "from w2popenid import OpenIDLogin" or this "from
> > > > > applications.w2popenid.modules.import OpenIDLogin". But it don't
> > > > > worked. I get to follow this trace
> > > > > Traceback (most recent call last):
> > > > >   File "/home/mamadou/Desktop/web2py/gluon/restricted.py", line 192,
> > > > > in restricted
> > > > >     exec ccode in environment
> > > > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/models/
> > > > > db.py", line 42, in 
> > > > >     from testing import lala
> > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > > 280, in __call__
> > > > >     fromlist, level)
> > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > > > in __call__
> > > > >     level)
> > > > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/modules/
> > > > > testing.py", line 7, in 
> > > > >     import openid.consumer.consumer
> > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > > 280, in __call__
> > > > >     fromlist, level)
> > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > > > in __call__
> > > > >     level)
> > > > >   File "/usr/lib/pymodules/python2.7/openid/consumer/consumer.py",
> > > > > line 197, in 
> > > > >     from openid.consumer.discover import discover,
> > > > > OpenIDServiceEndpoint, \
> > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > > 280, in __call__
> > > > >     fromlist, level)
> > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > > > in __call__
> > > > >     level)
> > > > >   File "/usr/lib/pymodules/python2.7/openid/consumer/discover.py",
> > > > > line 21, in 
> > > > >     from openid.yadis.etxrd import nsTag, XRDSError, XRD_NS_2_0
> > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > > 280, in __call__
> > > > >     fromlist, level)
> > > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > > > in __call__
> > > > >     level)
> > > > >   File "/usr/lib/pymodules/python2.7/openid/yadis/etxrd.py", line 28,
> > > > > in 
> > > > >     ElementTree = importElementTree()
> > > > >   File "/usr/lib/pymodules/python2.7/openid/oidutil.py", line 58, in
> > > > > importElementTree
> > > > >     ElementTree = __im

[web2py] Re: Download of big files broken

2011-06-17 Thread Stefan Scholl
Now I can't access the admin interface, because the password
isn't set. (It isn't reading the stored password.)



Stefan Scholl  wrote:
> OK, it was Rocket.
> 
> Tested it with the old web2py and Tornado 1.2.1 via anyserver.py
> and the download is OK.
> 
> 
> Stefan Scholl  wrote:
>> The higher value for chunk_size didn't work with a 33 MiB file. Even
>> in Firefox 4.
>> So I tried 1.96.4 (Rocket 1.2.2) on Windows XP.
>> 
>> Made a new and simple app (dtest). The download there uses
>> "response.download(request,db)" as well.
>> 
>> 1 simple table: db.define_table('stuff', Field('file', 'upload'))
>> 
>> Upload of the 33 MiB file via db admin, content listed on
>> http://127.0.0.1:8001/dtest/default/data/select/stuff (default
>> function "data" with "return dict(form=crud())". Download with
>> Internet Explorer 8 (after removing the tag that switches to "Chrome
>> Frame", to have a realistic test like "normal" users).
>> 
>> Download was broken. A few KiB were missing. This was on localhost.
>> Remote tests have even worse results.
>> 
>> 
>> 
>> On 6 Mai, 17:51, Massimo Di Pierro  wrote:
>>> Can you try 1.95.1
>>>
>>> On May 6, 6:03 am, Stefan Scholl  wrote:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> > The classicdownloadfunction:
>>>
>>> > defdownload():
>>> >     return response.download(request, db)
>>>
>>> > I'm developing on localhost (127.0.0.1, no SSL) and one strange thing
>>> > happened: Downloads in IE8 (Windows XP) were all corrupt/broken if
>>> > they weren't below 64KiB in size. Very easy to see with large images.
>>>
>>> > Using a higher value for the argument 'chunk_size' solves this
>>> > problem, up to this new maximum.
>>>
>>> > web2py 1.91.6



[web2py] user table just minimal customization

2011-06-17 Thread Manuele Pesenti
is there a way to add just a single field to the user table without 
re-wrintig a customized version as explained in


http://www.web2py.com/book/default/chapter/08#Customizing-Auth

I mean... if I only want to add "username" field in order to use it in 
place of email during user login... how can I do it? if I can...


thanks

Manuele


[web2py] Re: Download of big files broken

2011-06-17 Thread Stefan Scholl
OK, it was Rocket.

Tested it with the old web2py and Tornado 1.2.1 via anyserver.py
and the download is OK.


Stefan Scholl  wrote:
> The higher value for chunk_size didn't work with a 33 MiB file. Even
> in Firefox 4.
> So I tried 1.96.4 (Rocket 1.2.2) on Windows XP.
> 
> Made a new and simple app (dtest). The download there uses
> "response.download(request,db)" as well.
> 
> 1 simple table: db.define_table('stuff', Field('file', 'upload'))
> 
> Upload of the 33 MiB file via db admin, content listed on
> http://127.0.0.1:8001/dtest/default/data/select/stuff (default
> function "data" with "return dict(form=crud())". Download with
> Internet Explorer 8 (after removing the tag that switches to "Chrome
> Frame", to have a realistic test like "normal" users).
> 
> Download was broken. A few KiB were missing. This was on localhost.
> Remote tests have even worse results.
> 
> 
> 
> On 6 Mai, 17:51, Massimo Di Pierro  wrote:
>> Can you try 1.95.1
>>
>> On May 6, 6:03 am, Stefan Scholl  wrote:
>>
>>
>>
>>
>>
>>
>>
>> > The classicdownloadfunction:
>>
>> > defdownload():
>> >     return response.download(request, db)
>>
>> > I'm developing on localhost (127.0.0.1, no SSL) and one strange thing
>> > happened: Downloads in IE8 (Windows XP) were all corrupt/broken if
>> > they weren't below 64KiB in size. Very easy to see with large images.
>>
>> > Using a higher value for the argument 'chunk_size' solves this
>> > problem, up to this new maximum.
>>
>> > web2py 1.91.6
> 




Re: [web2py] Models in subfolders are not executed

2011-06-17 Thread Manuele Pesenti

On 17/06/2011 15:15, Bruno Rocha wrote:


If you are defining your db and tables under /models and If you want you
module to know your db tables, you have two options:


nice tricks! :)

thank again

Manuele


[web2py] Re: web2py with Rocket and Tornado - very simple benchmark

2011-06-17 Thread Stefan Scholl
Stefan Scholl  wrote:
> You could try to download a big file (>30 MiB) via web2py. Is
> Tornado sending everything or currupting the data?
> 
> web2py+Rocket is broken for large downloads.

Or I just test it myself. :-)

Works. Tornado lets me download a 33 MiB file without problems.
Rocket corrupts the file.

(Download via the default "download" function.)





Re: [web2py] Models in subfolders are not executed

2011-06-17 Thread Bruno Rocha
On Fri, Jun 17, 2011 at 10:02 AM, Manuele Pesenti  wrote:

> do you mean that in this way my module knows all my db table models?
> right??


Nop,

from gluon import * # this let the module to know all classes under gluon
package as dal, html, validators

If you are defining your db and tables under /models and If you want you
module to know your db tables, you have two options:

*# Pass it to the module:*

**

def index():
from modulex import MyClass
myobject = MyClass(database=db) # passing db to the class __init__

lower = myobject.value
upper = myobject.my_method()

return dict(u=upper, l=lower)

**

*# Use the current object *
*
*
*
*
**
*
*
db = DAL(...)
db.define_table(.)

from gluon import current
current.database = db
*
*
**
*
*
*


from gluon import *
db = current.database
**
# do whatever you want with db
**
# dont forget that in modules you need db.commit()

class MyClass(object):
def __init__(self, value):
self.value  = value

def my_method(self):
return self.value.upper()


*
*
*
*
*


Re: [web2py] Models in subfolders are not executed

2011-06-17 Thread Manuele Pesenti

On 17/06/2011 14:22, Bruno Rocha wrote:

where do I have to write a function lib based on my models and call
it from my controllers only when I need it? I mean without put it in
models??



*This should go in /modules*

# Lets say you wrote a file in /modules/modulex.py

**

from gluon import *


do you mean that in this way my module knows all my db table models? right??

thanks Bruno

Manuele



class MyClass(object):
 def __init__(self, value):
 self.value  = value

 def my_method(self):
 return self.value.upper()




Re: [web2py] Models in subfolders are not executed

2011-06-17 Thread Bruno Rocha
>
> where do I have to write a function lib based on my models and call it from
> my controllers only when I need it? I mean without put it in models??
>


*This should go in /modules*

# Lets say you wrote a file in /modules/modulex.py

**

from gluon import *

class MyClass(object):
def __init__(self, value):
self.value  = value

def my_method(self):
return self.value.upper()

**

# Now, in your controller (or model if you need) you can do:

**

def index():
from modulex import MyClass
myobject = MyClass("banana")

lower = myobject.value
upper = myobject.my_method()

return dict(u=upper, l=lower)

**

# Then in related view:

**


{{=u}}

{{=l}}


**


Hope it helps!

---
Bruno Rocha
[zerp.ly/rochacbruno]


[web2py] Re: web2py with Rocket and Tornado - very simple benchmark

2011-06-17 Thread Stefan Scholl
You could try to download a big file (>30 MiB) via web2py. Is
Tornado sending everything or currupting the data?

web2py+Rocket is broken for large downloads.





Re: [web2py] Models in subfolders are not executed

2011-06-17 Thread Manuele Pesenti

On 15/06/2011 03:19, Bruno Rocha wrote:

This is a feature. Not a bug.

Subfolder models run only if the matched url is requested.

This is util for modular apps and ajax callbacks.

Commom objects have to be in root of models.

Or. Better modular apps should use class based modules.


maybe this is a related question:

where do I have to write a function lib based on my models and call it 
from my controllers only when I need it? I mean without put it in models??


thanks

Manuele



Em 14/06/2011 20:16, "contatogilson...@gmail.com
" mailto:contatogilson...@gmail.com>> escreveu:
 > Hello guys,
 >
 > I'm using the new version of web2py, and created a feature in my
project and
 > took thesub models. Except that as I run the application and the
controller
 > of this functionality,it does not create tables in the database.
Someone went
 > through this too?
 > _
 > *Gilson Filho*
 > *Web Developer
 > http://gilsondev.com*




[web2py] [tip] reference guide for context [request, response] objects

2011-06-17 Thread Bruno Rocha
Sometimes you want to know which objects are in the default web2py context
[response, request]

Sometimes you do not want to start web2py locally to see that, go to:
http://bit.ly/web2pycontext

Hope it helps!




--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]
[ Aprenda a programar: http://CursoDePython.com.br ]


Re: [web2py] Linking directly to an uploaded image

2011-06-17 Thread Bruno Rocha
For security reasons, web2py does not expose the 'uploads' folder to the
user, this folder can be accessed only by the 'download' function.

The best way is to set the upload path pointing to /static not to /upload
and you will have your uploaded files to be served as static files,
bypassing download function.

under /static create a folder called 'picture'

*Go to the table definition and do this:*

**
db.define_table('announce',

Field('picture','upload',uploadfolder=request.folder+'static/pictures'),
)
**

You are saying DAL to store uploades files in to that folder under static
and store the ath in the field.

Now in your controller create a function do handle that (different from
download, it is a kind of viewer)

**
def viewer():
row = db(db.announce.id
==request.args(0)).select(db.announce.picture).first()
redirect(URL('static','pictures',args=row.picture))
**

*Now you can fo this:*

http://server/app/default/viewer/3 # record id

then you got redirected to the image (no html page)

example:
http://127.0.0.1:8000/app/static/pictures/announce.picture.aaf5d3f7779841d0.6e65775f64616c5f68656c702e706466.jpg

you can always refer directly to the image path (not using the viewer
function) but you always need to fetch the picture name from db.

Hope it helps.

Should go on the book?


--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]
[ Aprenda a programar: http://CursoDePython.com.br ]



On Thu, Jun 16, 2011 at 6:09 AM, Vinicius Assef wrote:

> Hi guys.
>
> I have a table (called anuncio) with an upload field (called foto), so
> anuncio.foto is my upload field.
>
> I'm showing and linking it with this piece of code in my view :
>{{url = URL(c='anuncios',f='download', args=['uploads', anuncio.foto])}}
>{{=A(IMG(_src=url), _href=url)}}
>
> My /contollers/anuncios.py/download() function is the default, as seen
> below:
> def download():
>return response.download(request,db)
>
> When user clicks on this image, browser shows the download dialog,
> asking him/her where to save the image.
> But I'd like to simply show the image, not present the download
> dialog. All these images will be public.
>
> How I solved it:
> 1) I entered in /myapp/static/images and created a symbolic link
> called 'uploads' pointing to /myapp/uploads.
> 2) In my view, I changed the: {{url = URL(...}} stuff by this: {{url =
> URL(c='static', f='images', args=['uploads', anuncio.foto])}}
>
> I think this isn't the best choice because I'm pointing URL() to a
> fake controller and function, and I'm counting on an external
> resource: a symbolic link in my filesystem.
>
> How would be the "web2pythonic" way to do this?
>
> --
> Vinicius Assef.
>


[web2py] web2py with Rocket and Tornado - very simple benchmark

2011-06-17 Thread David Marko
Just for your information I have compared the web2py running default Rocket 
http server and Tornado (using anyserver.py). Is very simple benchmark using 
ApacheBench and accessing page from standard web2py examples.
Tests were running on WindowsXP, Python 2.7.2. and lastest web2py 1.96.4


### Here we have default web2py running Rocket
Server Software:Rocket
Server Hostname:127.0.0.1
Server Port:8000

Document Path:  /examples/simple_examples/hello5.html
Document Length:179 bytes

Concurrency Level:  30
Time taken for tests:   4.953 seconds
Complete requests:  100
Failed requests:0
Write errors:   0
Total transferred:  59800 bytes
HTML transferred:   17900 bytes
Requests per second:20.19 [#/sec] (mean)
Time per request:   1485.938 [ms] (mean)
Time per request:   49.531 [ms] (mean, across all concurrent requests)
Transfer rate:  11.79 [Kbytes/sec] received

Connection Times (ms)
  min  mean[+/-sd] median   max
Connect:0   49 146.4  0 500
Processing:47 1289 435.9   14531922
Waiting:   47  860 383.39531516
Total: 47 1338 436.5   14532016


### Here we have web2py running via Tornado using anyserver.py (running 
Tornado from trunk ... so the latest one)
Server Software:TornadoServer/2.0rc1
Server Hostname:localhost
Server Port:8080

Document Path:  /examples/simple_examples/hello5.html
Document Length:179 bytes

Concurrency Level:  30
Time taken for tests:   1.797 seconds
Complete requests:  100
Failed requests:0
Write errors:   0
Total transferred:  53700 bytes
HTML transferred:   17900 bytes
Requests per second:55.65 [#/sec] (mean)
Time per request:   539.063 [ms] (mean)
Time per request:   17.969 [ms] (mean, across all concurrent requests)
Transfer rate:  29.18 [Kbytes/sec] received

Connection Times (ms)
  min  mean[+/-sd] median   max
Connect:00   1.6  0  16
Processing:   125  508 152.1563 969
Waiting:   63  461 142.2516 578
Total:125  509 151.8563 969

More tests show that by increasing the number of concurent users the Tornado 
becomes 2x or more faster. Not sure about overall .. real world ... 
stability, but simply runnng web2py with different http server you can 
increase application responsivness. Does anyone have any real world 
experience with running web2py using Tornado? Is it stable? Any potential 
disadvantages?

David




[web2py] Re: making requests to components from outside

2011-06-17 Thread blackthorne
this is gook. Things like this make me think how cool would it be to have 
some sort of system in the web2py admin app or an API to handle updates for 
plugins as well 

[web2py] Re: Linking directly to an uploaded image

2011-06-17 Thread selecta
btw if you have different image type you can get the extension with
os.path.splitext(path)

On Jun 17, 11:41 am, selecta  wrote:
> The problem is that download creates a http response with attachment
> you should be able to write a function that just returns the content
> of the image
> def show()
>   import gluon.contenttype
>   response.headers['Content-Type'] =
> gluon.contenttype.contenttype('.jpg')
>   filename, file =
> db.myimages.img_upload.retrieve( db.myimages[1].img_upload)
>   return file.read()
>
> On Jun 16, 11:09 am, Vinicius Assef  wrote:
>
>
>
> > Hi guys.
>
> > I have a table (called anuncio) with an upload field (called foto), so
> > anuncio.foto is my upload field.
>
> > I'm showing and linking it with this piece of code in my view :
> >     {{url = URL(c='anuncios',f='download', args=['uploads', anuncio.foto])}}
> >     {{=A(IMG(_src=url), _href=url)}}
>
> > My /contollers/anuncios.py/download() function is the default, as seen 
> > below:
> > def download():
> >     return response.download(request,db)
>
> > When user clicks on this image, browser shows the download dialog,
> > asking him/her where to save the image.
> > But I'd like to simply show the image, not present the download
> > dialog. All these images will be public.
>
> > How I solved it:
> > 1) I entered in /myapp/static/images and created a symbolic link
> > called 'uploads' pointing to /myapp/uploads.
> > 2) In my view, I changed the: {{url = URL(...}} stuff by this: {{url =
> > URL(c='static', f='images', args=['uploads', anuncio.foto])}}
>
> > I think this isn't the best choice because I'm pointing URL() to a
> > fake controller and function, and I'm counting on an external
> > resource: a symbolic link in my filesystem.
>
> > How would be the "web2pythonic" way to do this?
>
> > --
> > Vinicius Assef.


[web2py] Re: Linking directly to an uploaded image

2011-06-17 Thread selecta
The problem is that download creates a http response with attachment
you should be able to write a function that just returns the content
of the image
def show()
  import gluon.contenttype
  response.headers['Content-Type'] =
gluon.contenttype.contenttype('.jpg')
  filename, file =
db.myimages.img_upload.retrieve( db.myimages[1].img_upload)
  return file.read()

On Jun 16, 11:09 am, Vinicius Assef  wrote:
> Hi guys.
>
> I have a table (called anuncio) with an upload field (called foto), so
> anuncio.foto is my upload field.
>
> I'm showing and linking it with this piece of code in my view :
>     {{url = URL(c='anuncios',f='download', args=['uploads', anuncio.foto])}}
>     {{=A(IMG(_src=url), _href=url)}}
>
> My /contollers/anuncios.py/download() function is the default, as seen below:
> def download():
>     return response.download(request,db)
>
> When user clicks on this image, browser shows the download dialog,
> asking him/her where to save the image.
> But I'd like to simply show the image, not present the download
> dialog. All these images will be public.
>
> How I solved it:
> 1) I entered in /myapp/static/images and created a symbolic link
> called 'uploads' pointing to /myapp/uploads.
> 2) In my view, I changed the: {{url = URL(...}} stuff by this: {{url =
> URL(c='static', f='images', args=['uploads', anuncio.foto])}}
>
> I think this isn't the best choice because I'm pointing URL() to a
> fake controller and function, and I'm counting on an external
> resource: a symbolic link in my filesystem.
>
> How would be the "web2pythonic" way to do this?
>
> --
> Vinicius Assef.


[web2py] Re: import error

2011-06-17 Thread selecta
I also have problems importing pygments from the modules directory
http://jaguar.biologie.hu-berlin.de/~fkrause/web2py.app.pygments_test.w2p

i downloaded pygments from http://pypi.python.org/pypi/Pygments

and wrote in db.py
from pygments import highlight
from pygments.formatters import HtmlFormatter
import pygments.lexers


Traceback (most recent call last):
  File "/home/fkrause/Downloads/tmp/web2py/gluon/restricted.py", line
192, in restricted
exec ccode in environment
  File "/home/fkrause/Downloads/tmp/web2py/applications/pygments_test/
models/db.py", line 10, in 
import pygments.lexers
  File "/home/fkrause/Downloads/tmp/web2py/gluon/custom_import.py",
line 271, in __call__
globals, locals, fromlist, level)
  File "/home/fkrause/Downloads/tmp/web2py/gluon/custom_import.py",
line 299, in __import__dot
locals, [name], level)
  File "/home/fkrause/Downloads/tmp/web2py/gluon/custom_import.py",
line 75, in __call__
level)
  File "applications/pygments_test/modules/pygments/lexers/
__init__.py", line 222, in 
oldmod = sys.modules['pygments.lexers']
KeyError: 'pygments.lexers'

On Jun 17, 10:57 am, selecta  wrote:
> I send you a test app that reproduces the error
> in case somebody else wants to test/debug you can download it 
> fromhttp://jaguar.biologie.hu-berlin.de/~fkrause/web2py.app.w2popenid_tes...
>
> On Jun 17, 4:32 am, Pierre Thibault 
> wrote:
>
>
>
> > 2011/6/15 Massimo Di Pierro 
>
> > > looking into this...
>
> > Still no news. Should we forget this issue? I really would like to debug but
> > I don't have enough information. It seems the bug is very rare.
>
> > > On Jun 15, 8:12 am, "mb_...@yahoo.fr"  wrote:
> > > > I wanted to use the w2popenid example application from bitbucket
> > > > website :https://bitbucket.org/bottiger/web2py-openid/overview
> > > >  I have downloaded and placed the code in the applications directory.
> > > > I have changed in the models folder the file db.py: this line "from
> > > > applications.cas.modules.w2popenid import OpenIDLogin" is replaced
> > > > with this one "from w2popenid import OpenIDLogin" or this "from
> > > > applications.w2popenid.modules.import OpenIDLogin". But it don't
> > > > worked. I get to follow this trace
> > > > Traceback (most recent call last):
> > > >   File "/home/mamadou/Desktop/web2py/gluon/restricted.py", line 192,
> > > > in restricted
> > > >     exec ccode in environment
> > > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/models/
> > > > db.py", line 42, in 
> > > >     from testing import lala
> > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > 280, in __call__
> > > >     fromlist, level)
> > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > > in __call__
> > > >     level)
> > > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/modules/
> > > > testing.py", line 7, in 
> > > >     import openid.consumer.consumer
> > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > 280, in __call__
> > > >     fromlist, level)
> > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > > in __call__
> > > >     level)
> > > >   File "/usr/lib/pymodules/python2.7/openid/consumer/consumer.py",
> > > > line 197, in 
> > > >     from openid.consumer.discover import discover,
> > > > OpenIDServiceEndpoint, \
> > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > 280, in __call__
> > > >     fromlist, level)
> > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > > in __call__
> > > >     level)
> > > >   File "/usr/lib/pymodules/python2.7/openid/consumer/discover.py",
> > > > line 21, in 
> > > >     from openid.yadis.etxrd import nsTag, XRDSError, XRD_NS_2_0
> > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > 280, in __call__
> > > >     fromlist, level)
> > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > > in __call__
> > > >     level)
> > > >   File "/usr/lib/pymodules/python2.7/openid/yadis/etxrd.py", line 28,
> > > > in 
> > > >     ElementTree = importElementTree()
> > > >   File "/usr/lib/pymodules/python2.7/openid/oidutil.py", line 58, in
> > > > importElementTree
> > > >     ElementTree = __import__(mod_name, None, None, ['unused'])
> > > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > > 258, in __call__
> > > >     globals.get("__file__", ""))
> > > > AttributeError: 'NoneType' object has no attribute 'get'
>
> > > > to fix i must modify the module custom_import in the web2py/gluon
> > > > folder.
> > > > starting line 256
>
> > > > try:
> > > >     caller_file_name = os.path.join(self.web2py_path,
> > > > \globals.get("__file__", ""))
> > > > except AttributeError:
> > > > caller_file_name = ""
>
> > --
>
> > A+
>
> > -
> > Pierre
> > My blog and profile
> > (http://pierrethibault.posterous.com)

[web2py] Re: import error

2011-06-17 Thread selecta
I send you a test app that reproduces the error
in case somebody else wants to test/debug you can download it from
http://jaguar.biologie.hu-berlin.de/~fkrause/web2py.app.w2popenid_test.w2p

On Jun 17, 4:32 am, Pierre Thibault 
wrote:
> 2011/6/15 Massimo Di Pierro 
>
> > looking into this...
>
> Still no news. Should we forget this issue? I really would like to debug but
> I don't have enough information. It seems the bug is very rare.
>
>
>
>
>
>
>
> > On Jun 15, 8:12 am, "mb_...@yahoo.fr"  wrote:
> > > I wanted to use the w2popenid example application from bitbucket
> > > website :https://bitbucket.org/bottiger/web2py-openid/overview
> > >  I have downloaded and placed the code in the applications directory.
> > > I have changed in the models folder the file db.py: this line "from
> > > applications.cas.modules.w2popenid import OpenIDLogin" is replaced
> > > with this one "from w2popenid import OpenIDLogin" or this "from
> > > applications.w2popenid.modules.import OpenIDLogin". But it don't
> > > worked. I get to follow this trace
> > > Traceback (most recent call last):
> > >   File "/home/mamadou/Desktop/web2py/gluon/restricted.py", line 192,
> > > in restricted
> > >     exec ccode in environment
> > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/models/
> > > db.py", line 42, in 
> > >     from testing import lala
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 280, in __call__
> > >     fromlist, level)
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > in __call__
> > >     level)
> > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/modules/
> > > testing.py", line 7, in 
> > >     import openid.consumer.consumer
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 280, in __call__
> > >     fromlist, level)
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > in __call__
> > >     level)
> > >   File "/usr/lib/pymodules/python2.7/openid/consumer/consumer.py",
> > > line 197, in 
> > >     from openid.consumer.discover import discover,
> > > OpenIDServiceEndpoint, \
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 280, in __call__
> > >     fromlist, level)
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > in __call__
> > >     level)
> > >   File "/usr/lib/pymodules/python2.7/openid/consumer/discover.py",
> > > line 21, in 
> > >     from openid.yadis.etxrd import nsTag, XRDSError, XRD_NS_2_0
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 280, in __call__
> > >     fromlist, level)
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > in __call__
> > >     level)
> > >   File "/usr/lib/pymodules/python2.7/openid/yadis/etxrd.py", line 28,
> > > in 
> > >     ElementTree = importElementTree()
> > >   File "/usr/lib/pymodules/python2.7/openid/oidutil.py", line 58, in
> > > importElementTree
> > >     ElementTree = __import__(mod_name, None, None, ['unused'])
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 258, in __call__
> > >     globals.get("__file__", ""))
> > > AttributeError: 'NoneType' object has no attribute 'get'
>
> > > to fix i must modify the module custom_import in the web2py/gluon
> > > folder.
> > > starting line 256
>
> > > try:
> > >     caller_file_name = os.path.join(self.web2py_path,
> > > \globals.get("__file__", ""))
> > > except AttributeError:
> > > caller_file_name = ""
>
> --
>
> A+
>
> -
> Pierre
> My blog and profile
> (http://pierrethibault.posterous.com)
> YouTube page 
> (http://www.youtube.com/user/tubetib)
> Twitter (http://twitter.com/pierreth2) 


[web2py] Re: import error

2011-06-17 Thread selecta
hi there i work with mamadou on this so i try to get some code working
for you to test this

On Jun 17, 4:32 am, Pierre Thibault 
wrote:
> 2011/6/15 Massimo Di Pierro 
>
> > looking into this...
>
> Still no news. Should we forget this issue? I really would like to debug but
> I don't have enough information. It seems the bug is very rare.
>
>
>
>
>
>
>
> > On Jun 15, 8:12 am, "mb_...@yahoo.fr"  wrote:
> > > I wanted to use the w2popenid example application from bitbucket
> > > website :https://bitbucket.org/bottiger/web2py-openid/overview
> > >  I have downloaded and placed the code in the applications directory.
> > > I have changed in the models folder the file db.py: this line "from
> > > applications.cas.modules.w2popenid import OpenIDLogin" is replaced
> > > with this one "from w2popenid import OpenIDLogin" or this "from
> > > applications.w2popenid.modules.import OpenIDLogin". But it don't
> > > worked. I get to follow this trace
> > > Traceback (most recent call last):
> > >   File "/home/mamadou/Desktop/web2py/gluon/restricted.py", line 192,
> > > in restricted
> > >     exec ccode in environment
> > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/models/
> > > db.py", line 42, in 
> > >     from testing import lala
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 280, in __call__
> > >     fromlist, level)
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > in __call__
> > >     level)
> > >   File "/home/mamadou/Desktop/web2py/applications/w2popenid/modules/
> > > testing.py", line 7, in 
> > >     import openid.consumer.consumer
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 280, in __call__
> > >     fromlist, level)
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > in __call__
> > >     level)
> > >   File "/usr/lib/pymodules/python2.7/openid/consumer/consumer.py",
> > > line 197, in 
> > >     from openid.consumer.discover import discover,
> > > OpenIDServiceEndpoint, \
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 280, in __call__
> > >     fromlist, level)
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > in __call__
> > >     level)
> > >   File "/usr/lib/pymodules/python2.7/openid/consumer/discover.py",
> > > line 21, in 
> > >     from openid.yadis.etxrd import nsTag, XRDSError, XRD_NS_2_0
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 280, in __call__
> > >     fromlist, level)
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line 75,
> > > in __call__
> > >     level)
> > >   File "/usr/lib/pymodules/python2.7/openid/yadis/etxrd.py", line 28,
> > > in 
> > >     ElementTree = importElementTree()
> > >   File "/usr/lib/pymodules/python2.7/openid/oidutil.py", line 58, in
> > > importElementTree
> > >     ElementTree = __import__(mod_name, None, None, ['unused'])
> > >   File "/home/mamadou/Desktop/web2py/gluon/custom_import.py", line
> > > 258, in __call__
> > >     globals.get("__file__", ""))
> > > AttributeError: 'NoneType' object has no attribute 'get'
>
> > > to fix i must modify the module custom_import in the web2py/gluon
> > > folder.
> > > starting line 256
>
> > > try:
> > >     caller_file_name = os.path.join(self.web2py_path,
> > > \globals.get("__file__", ""))
> > > except AttributeError:
> > > caller_file_name = ""
>
> --
>
> A+
>
> -
> Pierre
> My blog and profile
> (http://pierrethibault.posterous.com)
> YouTube page 
> (http://www.youtube.com/user/tubetib)
> Twitter (http://twitter.com/pierreth2)