[web2py] Re: scheduled task not committing

2015-10-01 Thread Leonel Câmara
That's fine Jeremy there's no issue here.

"In models, views and controllers there is no need to ever call commit or 
rollback explicitly."

There's no scheduler mentioned there.

Do note that this is also in the documentation:

Remember to call db.commit() at the end of every task if it involves 
inserts/updates to the database. web2py commits by default at the end of a 
successful action but the scheduler tasks are not actions.

This is basically for the same reason that you need to commit if you do 
this kinds of things in a web2py shell, this is just code running in a 
web2py environment. Lets look at what the book says:

Notice that scripts/functions executed in the web2py environment require a 
manual db.commit() at the end of the function or the transaction will be 
reverted.


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Running threads in Scheduler process

2015-10-01 Thread Niphlod
techinically any scheduler worker is a fresh process spawned with 
multiprocessing.Process, so spawning a thread, albeit counterproductive, is 
allowed.
I'm not that sure that launching a process from inside a spawned process 
play wells with input/output buffers. 
In any case, using multiprocessing.Popen spawns a new thread already under 
the hood

On Friday, October 2, 2015 at 3:44:55 AM UTC+2, Bilal Hasan wrote:
>
> Before I tested this out (I'm running on production environment), I wanted 
> to ask would it be okay to spawn threads in the scheduler function?
>
> Since I need to split some tasks using the Linux command line.
>
> What would be the best way to do this?
>
> Using the threading library? Or just run a bunch of subprocess Popen calls 
> and not wait on those to return?
>
> Any help or feedback ointing me into the right direction on how to use the 
> scheduler with threads would be appreciated.
> Thanks.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] how to get count (number of records) from grid.element('.web2py_counter')

2015-10-01 Thread Niphlod
for anyone's sake, do it client side

On Friday, October 2, 2015 at 7:38:50 AM UTC+2, Alex Glaros wrote:
>
> Thanks Vinicius,
>
> it worked.
>
> if it couldn't find the value, it raised this error:
>
>  list index out of range
>
> Is the below way acceptable way of preventing the error message? Or is 
> there a shorter way?
>
> try:
> num_recs = int(grid.element('.web2py_counter')[0].split()[0])
> except Exception, e:
> num_recs = 0
> else:
> if num_recs > 1:
> response.flash = T('The same zip code exists for more than one 
> country. Choose one.')
>
>
> thanks
>
> Alex
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] how to get count (number of records) from grid.element('.web2py_counter')

2015-10-01 Thread Alex Glaros
Thanks Vinicius,

it worked.

if it couldn't find the value, it raised this error:

 list index out of range

Is the below way acceptable way of preventing the error message? Or is 
there a shorter way?

try:
num_recs = int(grid.element('.web2py_counter')[0].split()[0])
except Exception, e:
num_recs = 0
else:
if num_recs > 1:
response.flash = T('The same zip code exists for more than one 
country. Choose one.')


thanks

Alex

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] How to start a web2py application on another ser

2015-10-01 Thread Vinicius Assef
Read about Services [0]. Maybe it's what you're looking for.

[0] 
http://web2py.com/books/default/chapter/29/10/services?search=rpc#Remote-procedure-calls

--
Vinicius Assef




On 1 October 2015 at 02:00, Chris Andrew  wrote:
> Hi guys,
> I currently have two systems that have web2py installed on them.
> System 1 has app1 installed on web2py and System 2 has app2 installed.
> Is it possible for me to call functions of app2 which is on System 2 using
> app1 which is on System1?
> They are both connected to my home network.
> Thank you in advance.
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] How to remove quotes around a FORM field

2015-10-01 Thread Vinicius Assef
```
assetcustomfield[1:-1]
```

--
Vinicius Assef




On 30 September 2015 at 06:36,   wrote:
> Hi,
>
> I have a form that takes input from the user via a normal input textbox as
> per below
> TR("Asset Custom
> Field",INPUT(_type="text",_name="metadata",value="{'type':'bugs','weight':'250'}",requires=IS_NOT_EMPTY())),
>
> Then i assign the metadata value to a new variable as per below
> assetcustomfield = request.vars.metadata
>
> But when i am using this variable to post to a script it creates the
> following quotes around the value as per below
> "{'type':'bugs','weight':'250'}"
>
> How can i remove the "" around the variable??
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] how to get count (number of records) from grid.element('.web2py_counter')

2015-10-01 Thread Vinicius Assef
You got almost there.

Try this:

```
grid = SQLFORM.grid(my_table)
num_recs = int(grid.element('.web2py_counter')[0].split()[0])
if num_recs > 1:
response.flash = T('The same zip code may exist for one or more countries')
return dict(grid=grid)
```


--
Vinicius Assef




On 1 October 2015 at 22:15, Alex Glaros  wrote:
> how to retrieve the number records in grid.element('.web2py_counter')?
>
> I'm looking for something like
> if grid[0][0] > 1:
> response.flash = T('The same zip code may exist for one or more
> countries')
>
> Thanks,
>
> Alex Glaros
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to start a web2py application on another ser

2015-10-01 Thread 黄祥
had you already try redirect?
e.g.

def function_on_system1(): redirect(URL('function_on_system2') )


best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: IS_IN_DB validation error

2015-10-01 Thread 'DenesL' via web2py-users
The second parameter of IS_IN_DB should be a set not a query:

query: (geo_item.f_collection_id == geo_collection.id) 

set: db(geo_item.f_collection_id == geo_collection.id) 


IS_IN_DB(db, db(geo_item.f_collection_id == geo_collection.id 

),...)

Been there, done that. Not so easy to spot.


On Thursday, October 1, 2015 at 9:44:56 PM UTC-4, John Smidt wrote:
>
>
> Im currently creating a website for a geology museum. Each exhibit in the 
> museum contains different collections (or categories) of minerals, and each 
> collection has a handful of individual minerals that are being shown at 
> this museum. The part that I am currently working on is to allow an admin 
> to select a featured image of a specific item in each collection via a drop 
> down box within the collection table. However, the validation of this field 
> is acting up. Here is the code:
>
> db.geo_collection.f_featured_img.requires=IS_IN_DB(db, 
> (geo_item.f_collection_id == geo_collection.id 
> ),lambda
>  
> row: '%s' % row.f_name)
>
> The comparison in this line of code (geo_item.f_collection_id == 
> geo_collection.id) is not working, stating that I am unpacking too many 
> values. 
>
> Here is the traceback:
>
> Traceback (most recent call last):
>   File "/home/SIRI/web2py/gluon/restricted.py", line 217, in restricted
> exec ccode in environment
>   File "/home/SIRI/web2py/applications/mqr/models/db_wizard.py" 
> , 
> line 148, in 
> db.geo_collection.f_featured_img.requires=IS_IN_DB(db, 
> (db.geo_item.f_collection_id == db.geo_collection.id),lambda row: '%s' % 
> row.f_name)
>   File "/home/SIRI/web2py/gluon/validators.py", line 497, in __init__
> (ktable, kfield) = str(field).split('.')
> ValueError: too many values to unpack
>
>
> I believe that the tuple "(ktable, kfield)" is the reason why I'm 
> unpacking too many values, since it requires one table and one field, and I 
> have a table and *two* fields. The question that I have is 
> *how can I reference these items in my table without breaking the code?*
> Some extra info, I have tried to change the IS_IN_DB to IS_IN_SET, but 
> received an error stating that " 'Query' 
> object does not support indexing".
>
> Any information would be greatly appreciated.
> Thank you,
> John
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: ST_X function on POSTGIS geography() fields

2015-10-01 Thread 'DenesL' via web2py-users

Has anyone tried using the functions?.
They are defined in web2py 2.12.03 pydal/adapters/postgres.py  as ST_X and 
ST_Y.


On Wednesday, September 30, 2015 at 4:56:56 PM UTC-4, wish7...@gmail.com 
wrote:
>
> Done: https://github.com/web2py/pydal/issues/298
>
> Cheers
> Toby
>
> Am Dienstag, 29. September 2015 23:17:37 UTC+2 schrieb wish...@gmail.com:
>>
>> +1 from my side too :-) Was a pydal ticket ever opened?
>> Otherwise I would do now...
>>
>> Cheers 
>> Toby
>>
>> Am Montag, 22. Juni 2015 08:51:59 UTC+2 schrieb Massimo Di Pierro:
>>>
>>> Please open a pydal ticket. I do not think we support this yet but we 
>>> can add it.
>>>
>>> On Wednesday, 23 April 2014 05:44:39 UTC-5, libe...@gmail.com wrote:

 Hi everyone,
 I am trying to extract latitude and longitude from a POSTGIS 
 geography() field. Unfortunately the usual st_x() and st_y() functions 
 normally used
 for geometry() fields won't work.
 How can I extract the required values or transform geography in 
 geometry?

 Thanks

>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] scheduled task not committing

2015-10-01 Thread Jeremy Martin
Okay, so I have a strange issue. I have a simple database update in a 
function in a file called "scheduler.py" in the "models" folder. When I 
call this function from my website running on Apache, works great, no 
problem. 

However, when a scheduled task runs it (i.e. something like 
"/usr/bin/python /opt/web-apps/web2py/web2py.py -K myapp &" in rc.local on 
centos), the database doesn't get updated. Moreover, if that database 
update runs in a loop, it's only the LAST update that doesn't get committed 
to the database, as if there was an implicit commit before every update 
statement.

My fix is to simply call "db.commit()" after my update, but I don't 
understand why I need to do that. Again, it works great when, for example, 
someone clicks on a link on a webpage, but the same function doesn't give 
the same results when called from the scheduler. The documentation states, 
"In models, views and controllers there is no need to ever call commit or 
rollback explicitly." So I'm puzzled.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Lost Fomatting on new build

2015-10-01 Thread Michael Messmer
S I don't know what Im doing wrong.

Spun up a new Fedora 22 Workstation box.

Ran my normal stuff to get it all running and now I am facing this jacked 
up formatting:


Any Thouhgts?  Like is missing the ability to talk to a CSS or something. 
 I dunno.  Help/pointers?







-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] How to start a web2py application on another ser

2015-10-01 Thread Chris Andrew
Hi guys,
I currently have two systems that have web2py installed on them.
System 1 has app1 installed on web2py and System 2 has app2 installed.
Is it possible for me to call functions of app2 which is on System 2 using 
app1 which is on System1?
They are both connected to my home network.
Thank you in advance.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] How to remove quotes around a FORM field

2015-10-01 Thread lohan . spies
Hi,

I have a form that takes input from the user via a normal input textbox as 
per below
TR("Asset Custom 
Field",INPUT(_type="text",_name="metadata",value="{'type':'bugs','weight':'250'}",requires=IS_NOT_EMPTY())),

Then i assign the metadata value to a new variable as per below
assetcustomfield = request.vars.metadata

But when i am using this variable to post to a script it creates the 
following quotes around the value as per below
"{'type':'bugs','weight':'250'}"

How can i remove the "" around the variable??

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Running threads in Scheduler process

2015-10-01 Thread Bilal Hasan
Before I tested this out (I'm running on production environment), I wanted 
to ask would it be okay to spawn threads in the scheduler function?

Since I need to split some tasks using the Linux command line.

What would be the best way to do this?

Using the threading library? Or just run a bunch of subprocess Popen calls 
and not wait on those to return?

Any help or feedback ointing me into the right direction on how to use the 
scheduler with threads would be appreciated.
Thanks.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Lost Style when deploying

2015-10-01 Thread Michael Messmer


So I spun up the latest web2py source on a Fedora 22 build and when i goto 
the url I get this.


Does anyone know why I can get to it but the formatting looks terrible?  I 
googled to no avail. 

Installed:

yum install httpd mod_ssl mod_wsgi wget python checkpolicy policycoreutils 
policycoreutils-devel 









-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] IS_IN_DB validation error

2015-10-01 Thread John Smidt

Im currently creating a website for a geology museum. Each exhibit in the 
museum contains different collections (or categories) of minerals, and each 
collection has a handful of individual minerals that are being shown at 
this museum. The part that I am currently working on is to allow an admin 
to select a featured image of a specific item in each collection via a drop 
down box within the collection table. However, the validation of this field 
is acting up. Here is the code:

db.geo_collection.f_featured_img.requires=IS_IN_DB(db, 
(geo_item.f_collection_id == geo_collection.id),lambda row: '%s' % 
row.f_name)

The comparison in this line of code (geo_item.f_collection_id == 
geo_collection.id) is not working, stating that I am unpacking too many 
values. 

Here is the traceback:

Traceback (most recent call last):
  File "/home/SIRI/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
  File "/home/SIRI/web2py/applications/mqr/models/db_wizard.py" 
, 
line 148, in 
db.geo_collection.f_featured_img.requires=IS_IN_DB(db, 
(db.geo_item.f_collection_id == db.geo_collection.id),lambda row: '%s' % 
row.f_name)
  File "/home/SIRI/web2py/gluon/validators.py", line 497, in __init__
(ktable, kfield) = str(field).split('.')
ValueError: too many values to unpack


I believe that the tuple "(ktable, kfield)" is the reason why I'm unpacking 
too many values, since it requires one table and one field, and I have a 
table and *two* fields. The question that I have is 
*how can I reference these items in my table without breaking the code?*
Some extra info, I have tried to change the IS_IN_DB to IS_IN_SET, but 
received an error stating that " 'Query' 
object does not support indexing".

Any information would be greatly appreciated.
Thank you,
John

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] update list:string type colum

2015-10-01 Thread arihant daga
Hello, 
I have my table like this,

db.define_table('myTable',
 Field('listfield','list:string'),
)

now i want to update my table and add items into listfield
if i do
db(db.myTable.id==1).validate_and_update(listfield=newList)

it will update the list with newList but i want new List to be appended to 
the earlier value... 
how can i do it.. 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] SQLFORM.grid + count

2015-10-01 Thread Bruno Oliveira


I'm trying to create a SQLFORM.grid in web2py that group 2 fields and count 
them up, but I couldn't figure it out how to do it.


*Model*

db.define_table('invocados',
Field('modulo_servico', 'string', label='Módulo (Serviço)', 
default=IS_LENGTH(2)),
Field('servico', 'string', default=IS_LENGTH(8)),
   )


*Controller*

fields=(db.invocados.modulo_servico, 
db.invocados.servico)Invocados=SQLFORM.grid(db.invocados.modulo_servico != 
db.invocados.modulo_consumidor, details=False, fields=fields, 
groupby=(db.invocados.modulo_servico | db.invocados.servico) , paginate=15)


I'm trying to count all records grouped by modulo_servico and servico. I've 
tried:

fields=(db.invocados.modulo_servico, db.invocados.servico, db.invocados.count())

but it doesn't work.


Can somebody help?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] how to get count (number of records) from grid.element('.web2py_counter')

2015-10-01 Thread Alex Glaros
how to retrieve the number records in grid.element('.web2py_counter')?

I'm looking for something like
if grid[0][0] > 1:
response.flash = T('The same zip code may exist for one or more 
countries')

Thanks,

Alex Glaros

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: IOError(11, 'Resource temporarily unavailable')

2015-10-01 Thread Calvin
I have an error handler within web2py that provides the error trace. 

One hypothesis offered was that nginx is closing the socket as uwsgi is 
taking too long to serve data. I've increased the keepalive_timeout 
parameter from 60 to 600 but this does not help. Where else could the 
problem be?

On Friday, 2 October 2015 03:27:33 UTC+8, Niphlod wrote:
>
> where does this error pop up ?
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: console.log on page reload?

2015-10-01 Thread Tom Campbell
Thank you, Derek, but I'm still flummoxed. I added this new script tag to 
web2py_ajax.html:

console.log('loaded ' + Date.now())

But I'm getting this message even when I use LOAD(). So I'm trying to 
understand whether I am placing this code in the wrong location or what, 
because I think it shouldn't be redrawing the page. The XHR record output 
seems to confirm this.

FWIW the actions are called this way from menu.py:

response.menu = [
('Demo', False, '', [
(T('New task'), False, URL('default', 'new')),
(T('Show all tasks'), False, URL('default', 'all')),
]),
]

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: console.log on page reload?

2015-10-01 Thread Derek
You don't need that, just do this...

console.log('loaded ' + date())

On Thursday, October 1, 2015 at 4:01:14 PM UTC-7, Tom Campbell wrote:
>
> Working on a single-page app and trying to ensure that only part of the 
> page gets refreshed. Doing some tests using LOAD() that look like this:
>
> *file default/new.html:*
>
> {{extend 'layout.html'}}
> {{=LOAD('default', 'new.load',ajax=True)}}
>
> *file default/new.load:*
>
> {{if 'message'in globals():}}
> {{=message}}
> {{pass}}
> {{=form}}
>
> I added this detection code to* web2py_ajax.html*:
>
> 
>
> But the refresh seems to be called every time I choose the action. 
> However, when viewing the console output in Chome I get the hoped-for 
> message starting with:
>
> RELOADED Thu Oct 01 2015 15:36:45 GMT-0700 (PDT)
>
> XHR finished loading: GET "http://127.0.0.1:8000/spa1a/default/new.load";
> etc.
>
> What am I doing wrong?
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] console.log on page reload?

2015-10-01 Thread Tom Campbell
Working on a single-page app and trying to ensure that only part of the 
page gets refreshed. Doing some tests using LOAD() that look like this:

*file default/new.html:*

{{extend 'layout.html'}}
{{=LOAD('default', 'new.load',ajax=True)}}

*file default/new.load:*

{{if 'message'in globals():}}
{{=message}}
{{pass}}
{{=form}}

I added this detection code to* web2py_ajax.html*:



But the refresh seems to be called every time I choose the action. However, 
when viewing the console output in Chome I get the hoped-for message 
starting with:

RELOADED Thu Oct 01 2015 15:36:45 GMT-0700 (PDT)

XHR finished loading: GET "http://127.0.0.1:8000/spa1a/default/new.load";
etc.

What am I doing wrong?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: how to access external API

2015-10-01 Thread Alex Glaros
thanks Leonel,  

I get the logic but it didn't work in my configuration, however I'm very 
happy to have it work with the extra "dict" term.  

Appreciate for your patience.  It's my introduction to API and JSON.  

great to have these explanations!

Alex

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: how to access external API

2015-10-01 Thread Leonel Câmara
Alex I think you're slightly confused, let me explain.

This was the original controller function I suggested.

def locateme():
import json
from gluon.tools import fetch
location_data = json.loads(fetch('http://ipinfo.io/%s/json' % request.
client))
return location_data

Note that it returns location_data, what is location data? Well it's a dict 
because that's what the API returns and the json module takes care of that 
for us.

In web2py, controller functions that return dicts make the keys in that 
dictionary available in the view. So in the view you shouldn't be acessing 
location_data directly you should be accessing its keys. 

To further illustrate I could rewrite locateme like this

def locateme():
import json
from gluon.tools import fetch
location_data = json.loads(fetch('http://ipinfo.io/%s/json' % request.
client))
return dict(city=location_data[u'city'], region=location_data[u'region'], 
country=location_data[u'country'],)

But this would be superfluous because location_data is already a dict I can 
perfectly well return.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Wizard inside a LOAD

2015-10-01 Thread Niphlod
proposed fix:

gluon.main : 
just after setting web2py-component-command, set a new 
web2py-component-origaction header = request.url

web2py.js : 
in ajax_page, inside oncomplete, just before web2py.trap_form, handle it

var origaction = xhr.getresponseheader('web2py-component-origaction');
action = (typeof origaction != 'undefined') ? origaction : action;

and it works.
Just for completeness, same type of handling in updatePage to change the 
w2p_remote of the cid to web2py-component-origaction

Of course, this stands as long as there's really no method to extrapolate 
on the oncomplete callback the "final url" that has been loaded, in which 
case, no gluon.main changes necessary.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Wizard inside a LOAD

2015-10-01 Thread Niphlod
umpf. the behaviour is reproducible.
The thing is, handling component redirects with ajax as normal redirects is 
bad because ajax just follow the same convention as browsers and it's 
impossible to intercept a get wich follows a redirect from a normal get in 
any way.

For now the proposed fix/workaround is to pass an explicit _action to the 
FORM, which will prevail if explicitely found.
Its quite easy because _action=URL() gets things done pretty quickly and 
painless.

Now, for the "real fix", we'd have either to add an header to every ajax or 
we won't be able to distinguish a 200 from a 302+200.
I'm open to possible solutions not involving add an header to every ajax 
request. 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Bulk] Re: [web2py] Re: how to access external API

2015-10-01 Thread 'Diogene Laerce' via web2py-users


Le 01/10/2015 22:30, Alex Glaros a écrit :
> This works.  But is it good programming?
>
> in controller, convert into a dict:
>
> |
> location_data
> =dict(json.loads(fetch('http://ipinfo.io/%s/json'%request.client)))
> |
>
> in view:
>
> |
>   {{=location_data['city']}}
> |

As Leonel said, you should access it with "city" directly.

Kind regards,

-- 
“One original thought is worth a thousand mindless quotings.”
“Le vrai n'est pas plus sûr que le probable.”

  Diogene Laerce


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: [Bulk] Re: [web2py] Re: how to access external API

2015-10-01 Thread Alex Glaros
This works.  But is it good programming?

in controller, convert into a dict:

location_data = dict(json.loads(fetch('http://ipinfo.io/%s/json' % 
request.client)))

in view:

  {{=location_data['city']}}


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Bulk] Re: [web2py] Re: how to access external API

2015-10-01 Thread Alex Glaros
sure, it is the same

maybe I need to define the globals or location_data as a dict?

as a work-around, I can read location_data as string, but seems that a
simple answer might be available

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Bulk] Re: [web2py] Re: how to access external API

2015-10-01 Thread 'Diogene Laerce' via web2py-users


Le 01/10/2015 21:05, Alex Glaros a écrit :
> hi Laer,
>
> it's available as can be seen from displaying contents of "location_data"
>
> {u'loc': u'38.6071,-121.4633', u'city': u'Sacramento', u'country':
> u'US', u'region': u'California', u'hostname': u'No Hostname', u'ip':
> u'159.145.7.104', u'org': u'AS1226 California Technology Agency',
> u'postal': u'95815'}
>
> City
>
> Region
>
> Country
>
>
> but somehow the available data does not go into the var names

I can see that your file is named locate_me.html, is your function
in the controller has the same name ?..

-- 
“One original thought is worth a thousand mindless quotings.”
“Le vrai n'est pas plus sûr que le probable.”

  Diogene Laerce


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


[web2py] Re: Wizard inside a LOAD

2015-10-01 Thread Niphlod
getting on it...

On Thursday, October 1, 2015 at 8:21:50 PM UTC+2, Jose wrote:
>
> I found this [1] and [2]. it seems that with some modifications on an old 
> version 
> of web2py work (web2py.js and web2py_ajax.html), but I can not fix it in new 
> versions
>
> José
>
>
> [1] https://groups.google.com/forum/?fromgroups#!topic/web2py/J7-SD0n8hQQ
> [2] https://groups.google.com/forum/#!msg/web2py/N414q0pH7W0/pB7zIbC-fzMJ
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: IOError(11, 'Resource temporarily unavailable')

2015-10-01 Thread Niphlod
where does this error pop up ?

On Thursday, October 1, 2015 at 8:53:01 PM UTC+2, Calvin wrote:
>
> Hi
>
> We have been experiencing the above error message particularly for calls 
> which require more complex queries. The set up is as follows:
>
> nginx, uwsgi, postgresql-9.1, web2py Version 
> 2.11.2-stable+timestamp.2015.05.30.11.29.46
>
> We have seen this error occur at different controllers/function.
>
> Any suggestions on how to debug/troubleshoot this would be most 
> appreciated!
>
> Calvin
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: how to access external API

2015-10-01 Thread Alex Glaros
hi Laer,

it's available as can be seen from displaying contents of "location_data"

{u'loc': u'38.6071,-121.4633', u'city': u'Sacramento', u'country': u'US', 
u'region': u'California', u'hostname': u'No Hostname', u'ip': 
u'159.145.7.104', u'org': u'AS1226 California Technology Agency', 
u'postal': u'95815'}CityRegionCountry

but somehow the available data does not go into the var names

thanks,

Alex

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] IOError(11, 'Resource temporarily unavailable')

2015-10-01 Thread Calvin
Hi

We have been experiencing the above error message particularly for calls 
which require more complex queries. The set up is as follows:

nginx, uwsgi, postgresql-9.1, web2py Version 
2.11.2-stable+timestamp.2015.05.30.11.29.46

We have seen this error occur at different controllers/function.

Any suggestions on how to debug/troubleshoot this would be most appreciated!

Calvin

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: how to access external API

2015-10-01 Thread 'Diogene Laerce' via web2py-users


Le 01/10/2015 17:26, Alex Glaros a écrit :
> sure, I copied your view exactly, but is there anything different in
> the view that you tested on your side?
> |
> {{extend 'layout.html'}}
> 
>  City
>  {{=city}}
>  Region
>  {{=region}}
>  Country
>  {{=country}}
> 
> |
>
> Do I need to define "city" in my controller?  I get this error:
>
>
>  name 'city' is not defined
>

As a learned lesson, you need to make sure of its availability :

{{city = globals().get('city', '')}}

in the view. I guess you will have the same error with the other
variables.

Good luck,

-- 
“One original thought is worth a thousand mindless quotings.”
“Le vrai n'est pas plus sûr que le probable.”

  Diogene Laerce


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


[web2py] Re: Wizard inside a LOAD

2015-10-01 Thread Jose
I found this [1] and [2]. it seems that with some modifications on an old 
version 
of web2py work (web2py.js and web2py_ajax.html), but I can not fix it in new 
versions

José


[1] https://groups.google.com/forum/?fromgroups#!topic/web2py/J7-SD0n8hQQ
[2] https://groups.google.com/forum/#!msg/web2py/N414q0pH7W0/pB7zIbC-fzMJ

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: how to access external API

2015-10-01 Thread Alex Glaros
sure, I copied your view exactly, but is there anything different in the 
view that you tested on your side?
{{extend 'layout.html'}}

 City
 {{=city}}
 Region
 {{=region}}
 Country
 {{=country}}


Do I need to define "city" in my controller?  I get this error:

 name 'city' is not definedVersionweb2py™Version 
2.9.5-stable+timestamp.2014.03.16.02.35.39PythonPython 2.7.6: 
/usr/local/bin/uwsgi (prefix: /usr)Traceback

1.
2.
3.
4.
5.
6.

Traceback (most recent call last):
  File "/home/alexglaros/web2py/gluon/restricted.py", line 220, in restricted
exec ccode in environment
  File 
"/home/alexglaros/web2py/applications/engagementsquared/views/default/locate_me.html",
 line 83, in 
NameError: name 'city' is not defined

Error snapshot [image: help] 


(name 'city' is not defined)

inspect attributes
Frames
   
   - 
   
   *File /home/alexglaros/web2py/gluon/restricted.py in restricted at line 
   220* code arguments variables
   - 
   
   *File 
   
/home/alexglaros/web2py/applications/engagementsquared/views/default/locate_me.html
 
   in  at line 83* code arguments variables
   Function argument list
   
   ()
   Code listing
   
   74.
   75.
   76.
   77.
   78.
   79.
   80.
   81.
   82.
   83.
   
   84.
   85.
   86.
   87.
   88.
   89.
   90.
   91.
   92.
   93.
   
   response.write('\n\n', escape=False)
   pass
   response.write('\n\n\n', escape=False)
   response.write('\n', escape=False)
   response.write('\n\n', escape=False)
   response.write(location_data)
   response.write('\n\n  City\n  ', escape=False)
   response.write(city)
   
   response.write('\n  Region\n  {=region}}\n  
Country\n  {=country}}\n', escape=False)
   response.write('\n', escape=False)
   response.write('\n\n\n', escape=False)
   if right_sidebar_enabled:
   response.write('\n\n', 
escape=False)
   response.write('\nRight Sidebar\n
\n', escape=False)
   response.write('\n\n', escape=False)
   pass
   response.write('\n\n\n\n\t   \n   \n\n', 
escape=False)
   response.write(' \n\nVersion 1.0 - 
Engagement Squared \n ', escape=False)
   
   
   
thanks,

Alex

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] interpolate table name

2015-10-01 Thread Anthony
You cannot treat Python code like a string. In this case, though, you can use 
dictionary syntax:

db[table_name].validate_and_insert()

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] interpolate table name

2015-10-01 Thread Mark Billion
Following up on my last post--this fails:

db.%s.validate_and_insert(...) %var_containing_table_name

Any thoughts on how to interpolate?


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Any idea about how to interpolate into a dal query string?

2015-10-01 Thread Mark Billion
Works like a charm.  Thanks!

On Wednesday, September 30, 2015 at 3:17:10 PM UTC-4, Leonel Câmara wrote:
>
> Use this instead
>
> query = db[field_array[3]].id ==field_array[1]
> db(query).select()
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Matplotlib

2015-10-01 Thread Laurent Lc
Sorry i found just put the function draw in a model 
and add write in the controller:

def mychart():
response.headers['Content-Type']='image/png'
return draw()

Le jeudi 1 octobre 2015 10:36:27 UTC+2, Laurent Lc a écrit :
>
> I found something :
>
> In a controller (the import is done in a model) :
>
> def mychart():
> return dict(a=IMG(_src=URL('draw'+'.png')))
>
> def draw():
> x = [datetime.date(2014, 1, 29), datetime.date(2014, 4, 15), 
> datetime.date(2014, 3, 29)]
> y = [2, 4, 1]
>
> fig, ax = plt.subplots()
> ax.plot_date(x, y, markerfacecolor='CornflowerBlue', 
> markeredgecolor='white')
> fig.autofmt_xdate()
> ax.set_xlim([datetime.date(2014, 1, 26), datetime.date(2014, 5, 1)])
> ax.set_ylim([0, 5])
> body = cStringIO.StringIO()
> plt.savefig(body)
> return body.getvalue()
>
> View:
> {{=a}}
>
> Now how to run this code if put the function draw in a model (as done in 
> the examples given)
>
> thank you
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Migration of java/tomcat backend

2015-10-01 Thread Leonel Câmara
I definitely think web2py is much more productive than that stack. However, 
it's worth considering if the migration is worth it. In my company we still 
support one app that has a backend like that, I always wanted to migrate it 
because it's the only thing still using Java. Frankly, even though it 
annoys me that I have to keep running tomcat on my server and some Java 
knowledge in my head, I could never justify it because the changes to the 
backend are so rare.  
  
So, really, the first caveat, is it worth it? Are you going to make a lot 
of changes to the backend?  
  
Then, if you'll be migrating one endpoint at a time you will also have to 
deal with routing the requests. You can avoid it completely by running the 
web2py and java versions completely side by side, in different URLs, and as 
the web2py version gains more functionality you can update the mobile app 
to use the web2py version. In a bunch of iterations you would have 
everything converted and you would always be able to downgrade the users to 
the previous version of the app if something went wrong. Of course the 
better option, if you have people experienced configuring the webserver or 
you're willing to learn, is changing the webserver config so that the new 
requests for a given endpoint go to web2py without any changes to the 
mobile app, which is preferable as it's much faster to switch back if 
something goes wrong.   
  
Another thing to watch for are table migrations, make sure to have them 
disabled as you probably don't want web2py changing the tables for the 
application during this transition phase.

Good luck!

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Matplotlib

2015-10-01 Thread Laurent Lc
I found something :

In a controller (the import is done in a model) :

def mychart():
return dict(a=IMG(_src=URL('draw'+'.png')))

def draw():
x = [datetime.date(2014, 1, 29), datetime.date(2014, 4, 15), 
datetime.date(2014, 3, 29)]
y = [2, 4, 1]

fig, ax = plt.subplots()
ax.plot_date(x, y, markerfacecolor='CornflowerBlue', 
markeredgecolor='white')
fig.autofmt_xdate()
ax.set_xlim([datetime.date(2014, 1, 26), datetime.date(2014, 5, 1)])
ax.set_ylim([0, 5])
body = cStringIO.StringIO()
plt.savefig(body)
return body.getvalue()

View:
{{=a}}

Now how to run this code if put the function draw in a model (as done in 
the examples given)

thank you

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: how to access external API

2015-10-01 Thread Leonel Câmara
That's not problem in python 2 a string like this u'' just means it's 
unicode you can convert it to utf-8 but there's no need.

If you notice how I do it in my example I use the dict the API returns as 
the dict my controller returns, so you access it's keys directly in the 
view. 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.