[web2py] Re: How can I set alternative DAL when main DAL endpoint is not available?

2012-01-11 Thread seongjoo
The solution is an elegant one, however, there is an issue I want to 
discuss further after applying it.

When the solution is applied, it works but with some trouble that might 
compromise testability. Since it will try to connect the production db and 
throws 'OperationalError' after trying to connect it for awhile and then it 
moves on to the next one, which is the local db for this case. Then, the 
test takes a lot longer with local db. Can this issue be circumvented so 
that test "experience" can be as much as like to the technique that I 
started with this thread (manually toggling on and off db endpoints)? 

If the issue persists, I guess our team will perform the test a lot more 
less, or go back to switching the endpoints manually, which is not a too 
much hassle. But what I am afraid of is that someone forgets to turn the 
endpoint back to the production before submitting the code and it goes live.


[web2py] Re: AttributeError: 'Rows' object has no attribute '_db'

2012-01-11 Thread Rahul
Thanks Anthony, That works! I've changed other queries giving me this
error and it works fine now. Thanks a million. :)

Sincerely, Rahul D.

On Jan 10, 7:46 pm, Anthony  wrote:
> On Monday, January 9, 2012 11:54:08 PM UTC-5, Rahul wrote:
>
> > I did not get it...
> > What would be an equivalent query I would need to pass for below?  I
> > need to just select rows (Friend_name column for all status that are
> > Friend and reguserid is whatever the logged in users id)  for below
> > conditions - I thought select was a valid query! Please suggest
>
> > Existing -
> > query = db((db.friends.reguserid==session.logged_in_user_id) &
> > (db.friends.status=="Friend")).select(db.friends.friend_name)
>
> No, the above is not a query -- it is a Rows object, which is the result of
> a select. The query is this part:
>
> query = (db.friends.reguserid==session.logged_in_user_id)
> & (db.friends.status=="Friend")
>
> If you only want the table to show the friend_name column, then you can
> specify the that in the "fields" argument:
>
> SQLFORM.grid(query, fields=[db.friends.friend_name], ...)
>
> Anthony


[web2py] Re: LOAD, javascript and a loading gif

2012-01-11 Thread Liam
Sorry, that was a typo.

Even something as simple as response.js = 'alert("Here");' or response.js = 
'alert("Here");' doesn't seem to work, although it does if 
included in the view.


Re: [web2py] Register User issue -- Blank password

2012-01-11 Thread Albert Abril
I tryed in Version 1.99.3 and it's working ok. When I put a blank password
there's a "Too short" message.

2012/1/11 VIREN PATEL 

> Hi,
>
>
> In register screen if i do not provide password and verify-password still
> the user does gets registered.
>
> also able to login with that user. any solution to avoid the acceptance of
> blank password
>
>
> Thanks,
> Viren
>


Re: [web2py] Register User issue -- Blank password

2012-01-11 Thread VIREN PATEL
Even i tried with version 1.99.3 still it registers successfully and also
able to login with that user with blank password

On Wed, Jan 11, 2012 at 2:38 PM, Albert Abril wrote:

> I tryed in Version 1.99.3 and it's working ok. When I put a blank
> password there's a "Too short" message.
>
>
> 2012/1/11 VIREN PATEL 
>
>> Hi,
>>
>>
>> In register screen if i do not provide password and verify-password still
>> the user does gets registered.
>>
>> also able to login with that user. any solution to avoid the acceptance
>> of blank password
>>
>>
>> Thanks,
>> Viren
>>
>
>


Re: [web2py] Web2py binary distribution and psycopg2 driver

2012-01-11 Thread Mariano Reingart
On Tue, Jan 10, 2012 at 5:14 PM, Álvaro J. Iradier  wrote:
> Hi,
>
> I was trying to distribute an application with web2py binary for
> windows, but I required the PostgreSQL driver. So I copied the
> psycopg2 files to site-packages in the web2py binary folder.
>
> If I start a shell from an application, I can import psycopg2 and
> connect to the database. However, it looks like the DAL does not
> recognize the psycopg2 driver. I am getting the error:
>
>
> Traceback (most recent call last):
>  File "gluon/restricted.py", line 204, in restricted
>  File "C:/Users/airadier/Downloads/web2py_win/web2py/applications/
> init/models/10_db.py", line 13, in 
>  File "gluon/dal.py", line 4749, in __init__
> RuntimeError: Failure to connect, tried 5 times:
> Traceback (most recent call last):
>  File "gluon/dal.py", line 4736, in __init__
>  File "gluon/dal.py", line 1867, in __init__
> RuntimeError: Unable to import driver
>
> My guess is when DAL is being initialized, the site-packages folder is
> not yet in the sys.path, so the following fails:
>
>    try:
>        import psycopg2
>        from psycopg2.extensions import adapt as psycopg2_adapt
>        drivers.append('PostgreSQL')
>    except ImportError:
>        logger.debug('no psycopg2 driver')
>
> Is there a reason for this? Is it a bug or a feature?

Mmm, site-packages seems to be added in main.py, befor dal is
imported, calling the function create_missing_folders .
If I'm correct, it should see the psycopg2 module

> Is there other way to acomplish these?

I think you could download and install python, psycopg and web2py from
source, and then use py2exe to make an installer.

BTW, I'm working on pg8000 support, a pure python postgresql
interface, you can see the changes in my clone:

http://code.google.com/r/reingart-web2py/source/detail?r=3837efb84b1f

you can download with mercurial:

hg clone https://reing...@code.google.com/r/reingart-web2py/
hg update pg8000

If you try it, please tell me if you find any issue.
With this changes, you'll not need anything else (nor even psycopg2,
and pg8000 is inside contrib)

> And is it allowed to distribute a binary web2py including the PostgreSQL 
> driver?

Psycopg2 has a LGLP licence, the same as web2py, and the license of
libq IIRC is the same as PostgreSQL: BSD so it shouldn't be an issue:

http://initd.org/psycopg/license/

pg8000 has also a BSD-like license

> Thanks in advance.

Best regards,

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com


[web2py] Re: Web2py binary distribution and psycopg2 driver

2012-01-11 Thread Alan Etkin
I think i installed one of the listed binary files listed here without
problems:
http://stickpeople.com/projects/python/win-psycopg/

Regards

On 10 ene, 17:14, Álvaro J. Iradier  wrote:
> Hi,
>
> I was trying to distribute an application with web2py binary for
> windows, but I required the PostgreSQL driver. So I copied the
> psycopg2 files to site-packages in the web2py binary folder.
>
> If I start a shell from an application, I can import psycopg2 and
> connect to the database. However, it looks like the DAL does not
> recognize the psycopg2 driver. I am getting the error:
>
> Traceback (most recent call last):
>   File "gluon/restricted.py", line 204, in restricted
>   File "C:/Users/airadier/Downloads/web2py_win/web2py/applications/
> init/models/10_db.py", line 13, in 
>   File "gluon/dal.py", line 4749, in __init__
> RuntimeError: Failure to connect, tried 5 times:
> Traceback (most recent call last):
>   File "gluon/dal.py", line 4736, in __init__
>   File "gluon/dal.py", line 1867, in __init__
> RuntimeError: Unable to import driver
>
> My guess is when DAL is being initialized, the site-packages folder is
> not yet in the sys.path, so the following fails:
>
>     try:
>         import psycopg2
>         from psycopg2.extensions import adapt as psycopg2_adapt
>         drivers.append('PostgreSQL')
>     except ImportError:
>         logger.debug('no psycopg2 driver')
>
> Is there a reason for this? Is it a bug or a feature?
>
> Is there other way to acomplish these? And is it allowed to distribute
> a binary web2py including the PostgreSQL driver?
>
> Thanks in advance.


[web2py] Re: Web2py binary distribution and psycopg2 driver

2012-01-11 Thread Álvaro J . Iradier
Thanks for your comments.

Do you remember how you did it? I can make it work correctly when
using the source version of web2py, and I install psycopg under the
python installation (c:\python27).

However, when trying the binary distribution, I have tried extracting
the files from the psycopg version for python 2.5, and putting them:

 a) Inside web2py\site-packages: They work if I start a shell and try
"import psycopg2", "psycopg2.connect(...)", etc. However they are not
detected as an available driver, and trying to connect the DAL to
Postgres fails with "Unable to import driver"
 b) I tried putting the files inside the library.zip file created by
py2exe, but it just didn't work even when importing from the
application shell...

I have managed to get it working using portable python + web2py source
distribution, but I think it would be easier to bundle it with web2py
binary.

Greets.

On Jan 11, 11:55 am, Alan Etkin  wrote:
> I think i installed one of the listed binary files listed here without
> problems:http://stickpeople.com/projects/python/win-psycopg/
>
> Regards
>
> On 10 ene, 17:14, Álvaro J. Iradier  wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I was trying to distribute an application with web2py binary for
> > windows, but I required the PostgreSQL driver. So I copied the
> > psycopg2 files to site-packages in the web2py binary folder.
>
> > If I start a shell from an application, I can import psycopg2 and
> > connect to the database. However, it looks like the DAL does not
> > recognize the psycopg2 driver. I am getting the error:
>
> > Traceback (most recent call last):
> >   File "gluon/restricted.py", line 204, in restricted
> >   File "C:/Users/airadier/Downloads/web2py_win/web2py/applications/
> > init/models/10_db.py", line 13, in 
> >   File "gluon/dal.py", line 4749, in __init__
> > RuntimeError: Failure to connect, tried 5 times:
> > Traceback (most recent call last):
> >   File "gluon/dal.py", line 4736, in __init__
> >   File "gluon/dal.py", line 1867, in __init__
> > RuntimeError: Unable to import driver
>
> > My guess is when DAL is being initialized, the site-packages folder is
> > not yet in the sys.path, so the following fails:
>
> >     try:
> >         import psycopg2
> >         from psycopg2.extensions import adapt as psycopg2_adapt
> >         drivers.append('PostgreSQL')
> >     except ImportError:
> >         logger.debug('no psycopg2 driver')
>
> > Is there a reason for this? Is it a bug or a feature?
>
> > Is there other way to acomplish these? And is it allowed to distribute
> > a binary web2py including the PostgreSQL driver?
>
> > Thanks in advance.


[web2py] Routes error

2012-01-11 Thread Web2Py Freak
Dear all ,

i am trying to use routes.py  , but its not working , i even tryed to
change the default app  and it didnt work  , why ?


[web2py] Auth user custom update

2012-01-11 Thread Magrelo
Hello all,

Ive created a custom form to change some auth.user informations.
After I submit this form how can I update auth.user?

For example, on the form I changed the first_name, submited and it
change de db, but the user session keeps the old first_name value. I
have to logout and login to see the changes.

Thanks for any help.


Thiago


[web2py] Re: Routes error

2012-01-11 Thread lyn2py
routes.py needs to be in the same location as routes.example.py

When you change routes.py you need to click on "reload routes" in
admin or restart the server.


On Jan 11, 8:16 pm, Web2Py Freak  wrote:
> Dear all ,
>
> i am trying to use routes.py  , but its not working , i even tryed to
> change the default app  and it didnt work  , why ?


[web2py] How to get name of linking field from two table names

2012-01-11 Thread monotasker
I have a function in which I have two table names 'db.A' and 'db.B'. There 
is a field in db.A that links to the id field of db.B. But I don't know 
what that linking field is called in db.A. Is there a way to find this out 
programmatically?

(This is the last nut to crack before I can release the second version of 
my ajaxselect plugin, adding the ability to filter one select based on the 
value of another.)


[web2py] Re: Auth user custom update

2012-01-11 Thread Anthony
After processing the form, try:

auth.user.update(form.vars)

auth.user is just a (dictionary-like) Storage object, so you can update it 
like any dictionary. Note, if form.vars includes some variables that are 
not part of the auth_user table (and therefore shouldn't be added to 
auth.user), you can do:

auth.user.update(db.auth_user._filter_fields(form.vars)) 

The _filter_fields method returns a filtered copy of form.vars including 
only fields in the auth_user table.

Another alternative might be to just use the auth.profile() action (it 
automatically handles updating auth.user). If you want to limit the fields 
that can be edited via profile(), you can simply set their .writeable 
attribute to False before calling auth.profile().

Anthony

On Wednesday, January 11, 2012 8:14:17 AM UTC-5, Magrelo wrote:
>
> Hello all, 
>
> Ive created a custom form to change some auth.user informations. 
> After I submit this form how can I update auth.user? 
>
> For example, on the form I changed the first_name, submited and it 
> change de db, but the user session keeps the old first_name value. I 
> have to logout and login to see the changes. 
>
> Thanks for any help. 
>
>
> Thiago



Re: [web2py] Re: Auth user custom update

2012-01-11 Thread Thiago Magro
Worked!

Thank you very much Anthony!



On Wed, Jan 11, 2012 at 11:54 AM, Anthony  wrote:

> After processing the form, try:
>
> auth.user.update(form.vars)
>
> auth.user is just a (dictionary-like) Storage object, so you can update it
> like any dictionary. Note, if form.vars includes some variables that are
> not part of the auth_user table (and therefore shouldn't be added to
> auth.user), you can do:
>
> auth.user.update(db.auth_user._filter_fields(form.vars))
>
> The _filter_fields method returns a filtered copy of form.vars including
> only fields in the auth_user table.
>
> Another alternative might be to just use the auth.profile() action (it
> automatically handles updating auth.user). If you want to limit the fields
> that can be edited via profile(), you can simply set their .writeable
> attribute to False before calling auth.profile().
>
> Anthony
>
>
> On Wednesday, January 11, 2012 8:14:17 AM UTC-5, Magrelo wrote:
>>
>> Hello all,
>>
>> Ive created a custom form to change some auth.user informations.
>> After I submit this form how can I update auth.user?
>>
>> For example, on the form I changed the first_name, submited and it
>> change de db, but the user session keeps the old first_name value. I
>> have to logout and login to see the changes.
>>
>> Thanks for any help.
>>
>>
>> Thiago
>
>


[web2py] Re: How to get name of linking field from two table names

2012-01-11 Thread Anthony
[f for f in db.B.fields if db.B[f].type == 'reference A'][0]

Anthony

On Wednesday, January 11, 2012 8:54:08 AM UTC-5, monotasker wrote:
>
> I have a function in which I have two table names 'db.A' and 'db.B'. There 
> is a field in db.A that links to the id field of db.B. But I don't know 
> what that linking field is called in db.A. Is there a way to find this out 
> programmatically?
>
> (This is the last nut to crack before I can release the second version of 
> my ajaxselect plugin, adding the ability to filter one select based on the 
> value of another.)
>


[web2py] Re: How can I set alternative DAL when main DAL endpoint is not available?

2012-01-11 Thread Massimo Di Pierro
The DAL can be into an if statement. In principle you can test outside
whether the connection is available. How would you check it
efficiently without wait?

On Jan 11, 2:35 am, seongjoo  wrote:
> The solution is an elegant one, however, there is an issue I want to
> discuss further after applying it.
>
> When the solution is applied, it works but with some trouble that might
> compromise testability. Since it will try to connect the production db and
> throws 'OperationalError' after trying to connect it for awhile and then it
> moves on to the next one, which is the local db for this case. Then, the
> test takes a lot longer with local db. Can this issue be circumvented so
> that test "experience" can be as much as like to the technique that I
> started with this thread (manually toggling on and off db endpoints)?
>
> If the issue persists, I guess our team will perform the test a lot more
> less, or go back to switching the endpoints manually, which is not a too
> much hassle. But what I am afraid of is that someone forgets to turn the
> endpoint back to the production before submitting the code and it goes live.


[web2py] Re: LOAD, javascript and a loading gif

2012-01-11 Thread Anthony
On Wednesday, January 11, 2012 3:53:24 AM UTC-5, Liam wrote:
>
> Sorry, that was a typo.
>
> Even something as simple as response.js = 'alert("Here");' or response.js 
> = 'alert("Here");' doesn't seem to work, although it 
> does if included in the view.
>

Can you show the code you tried? I tried the exact code you posted and 
simply added this to the overview() function:

response.js = '''$(function() {$(".replacewloading").click(function() 
{$(this).parent().html('Refreshing...')} );} );'''

and it worked fine for me.

Anthony 


Re: [web2py] Register User issue -- Blank password

2012-01-11 Thread Anthony
Are you using a custom auth_user table? With the default table, the 
password field has a CRYPT validator with the minimum password length set 
to auth.settings.password_min_length, which defaults to 4.

Anthony

On Wednesday, January 11, 2012 4:19:40 AM UTC-5, Viren Patel wrote:
>
> Even i tried with version 1.99.3 still it registers successfully and also 
> able to login with that user with blank password
>
> On Wed, Jan 11, 2012 at 2:38 PM, Albert Abril  wrote:
>
>> I tryed in Version 1.99.3 and it's working ok. When I put a blank 
>> password there's a "Too short" message.
>>
>>
>> 2012/1/11 VIREN PATEL 
>>
>>> Hi,
>>>
>>>
>>> In register screen if i do not provide password and verify-password 
>>> still the user does gets registered.
>>>
>>> also able to login with that user. any solution to avoid the acceptance 
>>> of blank password
>>>
>>>
>>> Thanks,
>>> Viren
>>>
>>
>>
>

Re: [web2py] plugin badmin

2012-01-11 Thread Alexandre Andrade
I understand the diferences between grid and smartgrid. thank you anyway
for reply.

What mean to ask is the diference between them and badmin, in
https://github.com/elcio/badmin


Alexandre Andrade




2012/1/10 Jim Steil 

>  The other big difference is that you can pass a query (in place of the
> table name) to .grid but not .smartgrid.  Instead with .smartgrid, you pass
> query filters in the constraints argument.
>
> -Jim
>
>
> On 1/10/2012 2:58 PM, Anthony wrote:
>
> On Tuesday, January 10, 2012 3:43:13 PM UTC-5, Alexandre Miguel de Andrade
> Souza wrote:
>>
>> What is the diference to sqlform.grid or sqlform.smartgrid?
>>
>
>  smartgrid is for exploring tables that are linked via references. It
> takes a single table, and it automatically provides links from the
> reference fields within that table to the referenced tables and records.
> See
> http://web2py.com/books/default/chapter/29/7#SQLFORM.grid-and-SQLFORM.smartgrid-(experimental)
> .
>
>  Anthony
>
>


-- 
Atenciosamente


Alexandre Andrade
Hipercenter.com Classificados Gratuitos


Re: [web2py] Web2py binary distribution and psycopg2 driver

2012-01-11 Thread Alexandre Andrade
I remember the postgresql driver usually works with the source
distribuition of web2py on windows.

I think a way u get it working is use the source web2py on windows, and use
py2exe or similar to create a executable.


Alexandre Andrade

2012/1/10 Álvaro J. Iradier 

> Hi,
>
> I was trying to distribute an application with web2py binary for
> windows, but I required the PostgreSQL driver. So I copied the
> psycopg2 files to site-packages in the web2py binary folder.
>
> If I start a shell from an application, I can import psycopg2 and
> connect to the database. However, it looks like the DAL does not
> recognize the psycopg2 driver. I am getting the error:
>
>
> Traceback (most recent call last):
>  File "gluon/restricted.py", line 204, in restricted
>  File "C:/Users/airadier/Downloads/web2py_win/web2py/applications/
> init/models/10_db.py", line 13, in 
>  File "gluon/dal.py", line 4749, in __init__
> RuntimeError: Failure to connect, tried 5 times:
> Traceback (most recent call last):
>  File "gluon/dal.py", line 4736, in __init__
>  File "gluon/dal.py", line 1867, in __init__
> RuntimeError: Unable to import driver
>
> My guess is when DAL is being initialized, the site-packages folder is
> not yet in the sys.path, so the following fails:
>
>try:
>import psycopg2
>from psycopg2.extensions import adapt as psycopg2_adapt
>drivers.append('PostgreSQL')
>except ImportError:
>logger.debug('no psycopg2 driver')
>
> Is there a reason for this? Is it a bug or a feature?
>
> Is there other way to acomplish these? And is it allowed to distribute
> a binary web2py including the PostgreSQL driver?
>
> Thanks in advance.




-- 
Atenciosamente


Alexandre Andrade
Hipercenter.com Classificados Gratuitos


[web2py] Bug in languages.py

2012-01-11 Thread Anders Roos
Hello,

I have discovered a bug where I got read errors for language files (ERROR: 
Syntax error in /home/...  .../languages/en-gb.py). After some debugging I 
found out that the cause is that the file is being read while it is half 
written by another thread (or process). There is a lock for it, but the 
full contents of the file is not written before close (which is after the 
unlock). By adding a flush before the unlock in write_dict, I don't get the 
error anymore.

I discovered the error by running system tests with Selenium in parallel, I 
suppose there is a simpler way to trigger the bug. ;-)

My patched write_dict in languages.py:

def write_dict(filename, contents):
try:
fp = open(filename, 'w')
except IOError:
if not is_gae:
logging.warning('Unable to write to file %s' % filename)
return
portalocker.lock(fp, portalocker.LOCK_EX)
fp.write('# coding: utf8\n{\n')
for key in sorted(contents):
fp.write('%s: %s,\n' % (utf8_repr(key), utf8_repr(contents[key])))
fp.write('}\n')
fp.flush()
portalocker.unlock(fp)
fp.close()

Regards
Anders


Re: [web2py] Routes error

2012-01-11 Thread Alexandre Andrade
I had the same problem.

I only made it work using router.example.py and renamed it to routes.py


2012/1/11 Web2Py Freak 

> Dear all ,
>
> i am trying to use routes.py  , but its not working , i even tryed to
> change the default app  and it didnt work  , why ?
>



-- 
Atenciosamente


Alexandre Andrade
Hipercenter.com Classificados Gratuitos


[web2py] EOFError loading errors

2012-01-11 Thread Clayton
When attempting to view list of errors via the admin application(admin/
errors/), I get an internal error (EOFError) opening the
picked error message:

File /home/www-data/web2py/applications/admin/controllers/default.py
in errors at line 1082
fullpath = os.path.join(errors_path, fn)
if not os.path.isfile(fullpath): continue
try:
fullpath_file = open(fullpath, 'r')
try:
error = pickle.load(fullpath_file)

finally:
fullpath_file.close()
except IOError:
continue

I'm running 1.99.4 on Ubuntu. Due to lxml bugs, I'm running wsgi with

 WSGIDaemonProcess web2py user=www-data group=www-data processes=3
threads=20 maximum-requests=100
 WSGIApplicationGroup %{GLOBAL}

Don't know if that is related. I could send a pickled error message
causing the problems if that would help. Clearing errors helps, but I
need to look at the errors and the problem comes back.

Thanks, Clayton


Re: [web2py] Bug in languages.py

2012-01-11 Thread Jonathan Lundell
On Jan 11, 2012, at 7:54 AM, Anders Roos wrote:

> I have discovered a bug where I got read errors for language files (ERROR: 
> Syntax error in /home/...  .../languages/en-gb.py). After some debugging I 
> found out that the cause is that the file is being read while it is half 
> written by another thread (or process). There is a lock for it, but the full 
> contents of the file is not written before close (which is after the unlock). 
> By adding a flush before the unlock in write_dict, I don't get the error 
> anymore.

A simpler fix might be to remove the unlock call. (In fact, it seems to me that 
it's an error to explicitly unlock a file that's been locked with LOCK_SH. 
Isn't it?)

A precaution (though it only papers over the error) would be to flush in 
portalocker before unlocking a file.

> 
> I discovered the error by running system tests with Selenium in parallel, I 
> suppose there is a simpler way to trigger the bug. ;-)
> 
> My patched write_dict in languages.py:
> 
> def write_dict(filename, contents):
> try:
> fp = open(filename, 'w')
> except IOError:
> if not is_gae:
> logging.warning('Unable to write to file %s' % filename)
> return
> portalocker.lock(fp, portalocker.LOCK_EX)
> fp.write('# coding: utf8\n{\n')
> for key in sorted(contents):
> fp.write('%s: %s,\n' % (utf8_repr(key), utf8_repr(contents[key])))
> fp.write('}\n')
> fp.flush()
> portalocker.unlock(fp)
> fp.close()
> 
> Regards
> Anders




[web2py] Intercept file download

2012-01-11 Thread Angelo Compagnucci
Hi guys,

For a web application, I have to implement a sort of responsive design for
images. There are tons of solution online, but they requires to use some
sort of javascript and custom html to work (insert special tags or classes
in code). I don't like the approch because it make the code unmaintenable.

The idea I have in mind is something like this:

1) On page load, a jquery function calls a controller and communicates
infos about the device.
2) Controller stores those infos in session
3) I intercept images download and
3a) If there are session infos about device width and is_mobile, I resize
the image with PIL to the exact width server side and give the new url to
the response.
3b) If there aren't infos (browser doesn't support cookies) and is_mobile,
I resize the image to an arbitrary small size (ex: 480 px) and give the new
url to the response.
3c) If !is_mobile, I return the normal url

How can I intercept file download also the static ones?

Thank you!

-- 
Profile: http://it.linkedin.com/in/compagnucciangelo


Re: [web2py] Intercept file download

2012-01-11 Thread Bruno Rocha
https://github.com/globocom/thumbor

On Wed, Jan 11, 2012 at 2:16 PM, Angelo Compagnucci <
angelo.compagnu...@gmail.com> wrote:

> Hi guys,
>
> For a web application, I have to implement a sort of responsive design for
> images. There are tons of solution online, but they requires to use some
> sort of javascript and custom html to work (insert special tags or classes
> in code). I don't like the approch because it make the code unmaintenable.
>
> The idea I have in mind is something like this:
>
> 1) On page load, a jquery function calls a controller and communicates
> infos about the device.
> 2) Controller stores those infos in session
> 3) I intercept images download and
> 3a) If there are session infos about device width and is_mobile, I resize
> the image with PIL to the exact width server side and give the new url to
> the response.
> 3b) If there aren't infos (browser doesn't support cookies) and is_mobile,
> I resize the image to an arbitrary small size (ex: 480 px) and give the new
> url to the response.
> 3c) If !is_mobile, I return the normal url
>
> How can I intercept file download also the static ones?
>
> Thank you!
>
> --
> Profile: http://it.linkedin.com/in/compagnucciangelo
>



-- 

Bruno Rocha
[http://rochacbruno.com.br]


Re: [web2py] Intercept file download

2012-01-11 Thread Bruno Rocha
On Wed, Jan 11, 2012 at 2:23 PM, Bruno Rocha  wrote:

> https://github.com/globocom/thumbor


and

https://github.com/globocom/mugshot


Re: [web2py] Intercept file download

2012-01-11 Thread Anthony
There's also this 
service: http://www.sencha.com/learn/how-to-use-src-sencha-io/

On Wednesday, January 11, 2012 11:24:23 AM UTC-5, rochacbruno wrote:
>
>
>
> On Wed, Jan 11, 2012 at 2:23 PM, Bruno Rocha  wrote:
>
>> https://github.com/globocom/thumbor
>
>
> and
>
> https://github.com/globocom/mugshot 
>  


[web2py] Re: How can I set alternative DAL when main DAL endpoint is not available?

2012-01-11 Thread seongjoo
It would be great if there is a way to check whether request is originated 
from local (127.0.0.1) and then set DAL's endpoint to local. 

Would it be possible, and if it is then, is it recommended to do so?


Re: [web2py] Intercept file download

2012-01-11 Thread Angelo Compagnucci
Thanks Bruno,

These not solve my problem! To use thumbor, I have to prepare links using a
special syntax, that is what I want to avoid. If I wanted to change links I
would have done using responsive design tecniques and my own webserver!

@Antony:
I know sencha and it adopts an approch like the one I proposed, they have a
proxy that intercepts requests to images and resize them basing on the
knowledge of the device they have by the useragent. The only caveat is that
you have to change all of your urls!

I think that we have a framework, we have user_agent_parser and we can
include responsive images in web2py!
If we can intercept GET to images, we can build something totally
integrated with web2py! And this is what I'm doing!
I'm thinking of a responsive design module for web2py that can be
configured (local processor power with PIL, online service like thumbor)
and when plugged in, it makes automatically responsive all of your images.

So, my question is, there is a way to intercept GET to static image files?

2012/1/11 Bruno Rocha 

>
>
> On Wed, Jan 11, 2012 at 2:23 PM, Bruno Rocha wrote:
>
>> https://github.com/globocom/thumbor
>
>
> and
>
> https://github.com/globocom/mugshot
>



-- 
Profile: http://it.linkedin.com/in/compagnucciangelo


[web2py] Re: LOAD, javascript and a loading gif

2012-01-11 Thread Liam
web2py 1.99.4

plugin controller:
def overview():
if len(request.args) > 0 and request.args[0] == 'refresh':
import time
time.sleep(4)
body = H2('Component header')
refresh = DIV(A('Refresh', _class='button replacewloading', 
_href=URL(c='plugin_test', f='overview.load', args=['refresh']), 
cid=request.cid))

request.js = '''$(function() 
{$(".replacewloading").click(function() {$(this).parent().html('Refreshing...')} );} 
);'''

return dict(body=body, refresh=refresh)

plugin view:
{{=body}}
{{=refresh}}

application view:
{{extend 'layout.html'}}
{{=LOAD('plugin_test', 'overview.load', ajax=True)}}



Re: [web2py] Intercept file download

2012-01-11 Thread Anthony
On Wednesday, January 11, 2012 11:49:18 AM UTC-5, AngeloC wrote:
>
> Thanks Bruno,
>
> These not solve my problem! To use thumbor, I have to prepare links using 
> a special syntax, that is what I want to avoid. If I wanted to change links 
> I would have done using responsive design tecniques and my own webserver!
>
> @Antony:
> I know sencha and it adopts an approch like the one I proposed, they have 
> a proxy that intercepts requests to images and resize them basing on the 
> knowledge of the device they have by the useragent. The only caveat is that 
> you have to change all of your urls!
>
> I think that we have a framework, we have user_agent_parser and we can 
> include responsive images in web2py!
> If we can intercept GET to images, we can build something totally 
> integrated with web2py! And this is what I'm doing!
> I'm thinking of a responsive design module for web2py that can be 
> configured (local processor power with PIL, online service like thumbor) 
> and when plugged in, it makes automatically responsive all of your images.
>
> So, my question is, there is a way to intercept GET to static image files?
>

Assuming web2py is serving static files to begin with, I believe it does so 
very early in the process, before the session is read, etc. If you can add 
a flag to the URL (e.g., in the query string) only in cases where you need 
to offer the alternative (non-static) image, maybe you could handle that 
via the pattern-based rewrite system in routes.py (though that would 
prevent using the parameter-based system for other purposes).

Anthony


[web2py] Re: How can I set alternative DAL when main DAL endpoint is not available?

2012-01-11 Thread Anthony
Sure, request.is_local indicates if the request is local (though I think 
will give a false positive if the site is running behind a proxy server).

Anthony

On Wednesday, January 11, 2012 11:44:05 AM UTC-5, seongjoo wrote:
>
> It would be great if there is a way to check whether request is originated 
> from local (127.0.0.1) and then set DAL's endpoint to local. 
>
> Would it be possible, and if it is then, is it recommended to do so?
>


Re: [web2py] Intercept file download

2012-01-11 Thread Angelo Compagnucci
Thanks Anthony,

Ok, this way I have to play anyway with urls. I'll try another approach.
There is a way to rewrite the page after rendering, just before the page
will be sent to the browser?
This way we can analyze img urls, resize images accordingly, and rewrite
the new ones.

What do you tink?


> Assuming web2py is serving static files to begin with, I believe it does
> so very early in the process, before the session is read, etc. If you can
> add a flag to the URL (e.g., in the query string) only in cases where you
> need to offer the alternative (non-static) image, maybe you could handle
> that via the pattern-based rewrite system in routes.py (though that would
> prevent using the parameter-based system for other purposes).
>
> Anthony
>



-- 
Profile: http://it.linkedin.com/in/compagnucciangelo


[web2py] Re: LOAD, javascript and a loading gif

2012-01-11 Thread Anthony
Two errors. I forgot to remove the  tag -- it isn't needed in 
response.js because the returned JS is eval'ed. Also, in your code, you 
have request.js, but it should be response.js, so try:

response.js = '''$(function() {$(".replacewloading").click(function() 
{$(this).parent().html('Refreshing...')} );} 
);'''

Anthony

On Wednesday, January 11, 2012 12:02:29 PM UTC-5, Liam wrote:
>
> web2py 1.99.4
>
> plugin controller:
> def overview():
> if len(request.args) > 0 and request.args[0] == 'refresh':
> import time
> time.sleep(4)
> body = H2('Component header')
> refresh = DIV(A('Refresh', _class='button replacewloading', 
> _href=URL(c='plugin_test', f='overview.load', args=['refresh']), 
> cid=request.cid))
> 
> request.js = '''