[web2py] Re: opening new file within controller and uploading to uploads?

2016-05-03 Thread Anthony
Check this section of the book: 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#More-on-uploads

Rather than opening an existing file, you can create a file-like object via 
cStringIO.

Anthony

On Tuesday, May 3, 2016 at 9:53:31 PM UTC-4, aetagot...@gmail.com wrote:
>
> I would like to open and write to a new file after accessing form 
> variables passed from views...
>
> I've been trying to find a similar problem, but not much luck ..
>
> I suppose I can create another table with tempfile field of type uploads, 
> and then do a database controller within the controller..
>
> However I am wondering if there is an alternative way, where I just create 
> the file object and send it to the uploads folder?
>
>
> 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: Enabling Unicode characters in URL

2016-05-03 Thread Kenneth
Hi Leonel,

Thank you for your quick reply.

If that is the case, is it possible to encode the unicode URLs right after 
it hits the server? So, it can be redirected to proper URL after the 
incoming url is encoded in percent.

Best,


On Tuesday, May 3, 2016 at 10:15:36 PM UTC-4, Leonel Câmara wrote:
>
> Unicode characters are not valid in URLs you need to percent encode them.
>

-- 
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: Enabling Unicode characters in URL

2016-05-03 Thread Leonel Câmara
Unicode characters are not valid in URLs you need to percent encode them.

-- 
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] Enabling Unicode characters in URL

2016-05-03 Thread Kenneth
Hello there,

I'd like to create URLs in unicode characters and I get "Invalid Request" 
error when I do. I tried to reconfigure on Nginx side but wasn't able to 
work it properly.

For example, this curl call will output "Invalid Request".

curl http://localhost:8080/与


Grateful if there is a solution to detect and read URLs in unicode 
characters. 

My Web2Py server is currently running Nginx and WSGI.

Cheers,


-- 
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] opening new file within controller and uploading to uploads?

2016-05-03 Thread aetagothno
I would like to open and write to a new file after accessing form variables 
passed from views...

I've been trying to find a similar problem, but not much luck ..

I suppose I can create another table with tempfile field of type uploads, 
and then do a database controller within the controller..

However I am wondering if there is an alternative way, where I just create 
the file object and send it to the uploads folder?


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 can i implement this with web2py?

2016-05-03 Thread Leonel Câmara
Yep web2py does nothing with string output from the controllers - it's 
returned as is. That said you should use response.stream for the download 
of the resulting file.

-- 
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 can i implement this with web2py?

2016-05-03 Thread teld dlet
Thank you for the suggestion, I will be looking at the javascript 
filereader!

Using this method with javascript, if I am working with image files, do you 
know if this will alter the size of the file? I need the size to remain 
consistent, which is why I will not be able to use the provided uploads 
option in web2py forms.

On Monday, May 2, 2016 at 6:40:11 AM UTC-4, Mirek Zvolský wrote:
>
> For input you could save the files temporary as upload files,
>
> or without saving them you can use HTML5 javascript FileReader and save 
> the file content to hidden s.
> No idea if web2py will upload something based on file handlers from 
> SQLFORM.factory with upload fields.
> If so, you will upload it twice (from hidden fields and as standard 
> upload), and so you could re-create both file s before the submit 
> via javascript DOM manipulation (because it is not possible set the value 
> of upload field from javascript, nor clear it: the 1-st is clever, but the 
> 2nd stupid :( )
>
> For output you could
> - return the resulting file content as string from the controller (I hope 
> web2py makes nothing with string output),
> - and change http headers for download (Content-Disposition or so) to 
> force Save dialog.
>
> Maybe somebody has much much better answer, but previous is not too 
> difficult, few lines of code for FileReader. FileReader is supported in 
> modern browsers but not IE8. (IE9?)
>
>
>
>
> Dne pondělí 2. května 2016 4:34:40 UTC+2 teld dlet napsal(a):
>>
>> I have a python program where I prompt the user for two files, and I do 
>> some programming and output a new file...
>>
>> How can I make this work with web2py?
>>
>>
>> I was thinking having a form with 2 upload fields, and a text field so 
>> they can give a name to the file that will be generated from the code. 
>> After form submission I access the two uploaded files from form.vars and do 
>> what needs to be done, then not sure how I would output a downloadable file 
>> for the user?
>>
>> None of these files need to be saved in the database for later retrieval 
>> so not sure if I should just use sqlformfactory, this is all something that 
>> would happen during their session and they can choose to save the new file 
>> to their computer. 
>>
>>
>>
>> Any advice will help, 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 can I set the column width of a SQLFORM.grid table?

2016-05-03 Thread Seth J
maxtextlength=500   would make all columns show at most 500 characters.

On Monday, May 2, 2016 at 3:57:37 PM UTC-4, Bernardo Leon wrote:
>
> Hello, I have this table in my model:
>
> db.define_table('data', 
>   Field('description', 'string'), 
>   Field('value', 'integer'))
>
> this controller in default.py:
>
> def index():
>  tableN = SQLFORM.grid(db.data, 
> maxtextlengths={'data.description':500})
>  return locals()
>
> and this view:
>
> 
> {{=tableN}}
> 
>
> Thanks to maxtextlengths I can show all the description texts but since 
> they are large I can't see their respective value in the table that 
> SQLFORM.grid generates unless i use the horizontal scroll. Is there a way I 
> can still show all the description data but in a column with a small width? 
> It doesn't matter if the height of the cell grows but I dont want to use 
> the scroll because the table is big and I dont want to scroll all the time 
> I want to compare a description with their value. How can I achieve this? 
> 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 add response headers to cache file?

2016-05-03 Thread Niphlod
how are you serving the "cachefiles" ? web2py caches - at most - the 
rendered view, not the headers 

On Tuesday, May 3, 2016 at 4:30:46 PM UTC+2, Antonio wrote:
>
> Hello again, 
> I'm not really sure that I fomulated correctly the question, so sorry for 
> that.
> I'm using web2py to get some data with which to create a dictionary that 
> I'll later use on a mobile app. The thing is that it takes a while to get 
> all the information (which will stay the same for long periods of time) so 
> I decided to create an application cache on disk.
>
> Before adding the cache everything worked fine. I just had to add 
> response.headers['Access-Control-Allow-Origin'] = 
> request.env.http_origin
> response.headers['Access-Control-Allow-Origin'] = "*"
> response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
>
> The problem is that once I added the cache, the first time I load the app 
> it worked fine, but the second and the following times I get this error:
> XMLHttpRequest cannot load 
> http://127.0.0.1:8000/Prueba/gfs/index.json?latitude=43.4879176=-3.80055544.
>  
> No 'Access-Control-Allow-Origin' header is present on the requested 
> resource. Origin 'http://localhost:8200 ' is therefore 
> not allowed access. 
>
>
> Is there a way to add headers to the response when getting the information 
> from the cache files?
> Thanks 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] Re: Flash messages not showing correctly

2016-05-03 Thread Anthony
For the most part, you would replace the files in the scaffolding app that 
are not customizable (i.e., web2py.js, web2py_ajax.html, appadmin.py, 
appadmin.html, the generic views, etc.). In some cases, you may also need 
to tweak layout.html, but that depends on how much of its original 
functionality you retained.

Anthony

On Tuesday, May 3, 2016 at 11:47:26 AM UTC-4, Krzysztof Socha wrote:
>
> Worked! Thanks!
>
> BTW: I keep running into issues when updating old web2py applications to 
> new releases of web2py... Is there a recommended way of doing it? It is not 
> very clear which files in my application folder should be 
> changed/replaced/updated/edited when updating web2py.
>
> Krzysztof.
>
> On Tuesday, May 3, 2016 at 5:31:52 PM UTC+2, Anthony wrote:
>>
>> In layout.html, have you tried changing the class of the flash div from 
>> "flash" to "w2p_flash"?
>>
>> Anthony
>>
>> On Tuesday, May 3, 2016 at 11:22:07 AM UTC-4, Krzysztof Socha wrote:
>>>
>>> I have issues with showing "flash"-type messages recently. First I could 
>>> not get them to show at all. I updated several files in my application 
>>> based on the recent version of web2py (R-2.14.5), such as web2py.js, 
>>> web2py-ajax.html, and the like.
>>>
>>> Now it shows the flash message, but the formatting is all wrong. It just 
>>> shows it on top of the page. Some digging revealed that the flash messages 
>>> are put in a DIV with class="flash", while web2py.js is expecting 
>>> class="w2p_flash". Anyone has an idea why it is like that and what to do to 
>>> fix it?
>>>
>>> Krzysztof.
>>>
>>

-- 
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: Flash messages not showing correctly

2016-05-03 Thread Krzysztof Socha
Worked! Thanks!

BTW: I keep running into issues when updating old web2py applications to 
new releases of web2py... Is there a recommended way of doing it? It is not 
very clear which files in my application folder should be 
changed/replaced/updated/edited when updating web2py.

Krzysztof.

On Tuesday, May 3, 2016 at 5:31:52 PM UTC+2, Anthony wrote:
>
> In layout.html, have you tried changing the class of the flash div from 
> "flash" to "w2p_flash"?
>
> Anthony
>
> On Tuesday, May 3, 2016 at 11:22:07 AM UTC-4, Krzysztof Socha wrote:
>>
>> I have issues with showing "flash"-type messages recently. First I could 
>> not get them to show at all. I updated several files in my application 
>> based on the recent version of web2py (R-2.14.5), such as web2py.js, 
>> web2py-ajax.html, and the like.
>>
>> Now it shows the flash message, but the formatting is all wrong. It just 
>> shows it on top of the page. Some digging revealed that the flash messages 
>> are put in a DIV with class="flash", while web2py.js is expecting 
>> class="w2p_flash". Anyone has an idea why it is like that and what to do to 
>> fix it?
>>
>> Krzysztof.
>>
>

-- 
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: Flash messages not showing correctly

2016-05-03 Thread Anthony
In layout.html, have you tried changing the class of the flash div from 
"flash" to "w2p_flash"?

Anthony

On Tuesday, May 3, 2016 at 11:22:07 AM UTC-4, Krzysztof Socha wrote:
>
> I have issues with showing "flash"-type messages recently. First I could 
> not get them to show at all. I updated several files in my application 
> based on the recent version of web2py (R-2.14.5), such as web2py.js, 
> web2py-ajax.html, and the like.
>
> Now it shows the flash message, but the formatting is all wrong. It just 
> shows it on top of the page. Some digging revealed that the flash messages 
> are put in a DIV with class="flash", while web2py.js is expecting 
> class="w2p_flash". Anyone has an idea why it is like that and what to do to 
> fix it?
>
> Krzysztof.
>

-- 
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] Flash messages not showing correctly

2016-05-03 Thread Krzysztof Socha
I have issues with showing "flash"-type messages recently. First I could 
not get them to show at all. I updated several files in my application 
based on the recent version of web2py (R-2.14.5), such as web2py.js, 
web2py-ajax.html, and the like.

Now it shows the flash message, but the formatting is all wrong. It just 
shows it on top of the page. Some digging revealed that the flash messages 
are put in a DIV with class="flash", while web2py.js is expecting 
class="w2p_flash". Anyone has an idea why it is like that and what to do to 
fix it?

Krzysztof.

-- 
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: cache.ram doesnt return a result until a certain request finishes

2016-05-03 Thread Anthony
I don't think this has anything to do with cache.ram. If you're using the 
Pythonanywhere free tier, you only get 1 uWSGI worker, so your app can only 
handle one request at a time. You should observe the same issue if you make 
*any* concurrent requests, whether you're reading/writing to cache.ram or 
not.

Note, switching to a paid plan with multiple workers may not help either -- 
depending on how uWSGI is set up, there may be multiple processes, each 
with its own independent cache.ram (so different requests may hit different 
caches).

Anthony

On Monday, May 2, 2016 at 12:16:27 PM UTC-4, Alfonso Serra wrote:
>
> Im trying to use cache.ram for a progress bar and i have this problem.
>
> I have 2 controllers, 
> progress: that changes cache.ram each second 
> getprog: that retrieves the cache.ram value whenever i like.
>
> import json as Json
>
> #convert a variable into a json response
> def json(var):
> response.headers['Content-Type'] = "application/json; charset=utf-8"
> return Json.dumps(var, ensure_ascii=False)
>
> #get progress status
> def getprog():
> msg = cache.ram('message', lambda: None, None)
> return json({"msg": msg})
>
> #start a process that updates the progress
> def progress():
> from time import sleep
> # when a form is submitted, change progress each second
> if request.ajax:
> for i in range(10):
> cache.ram('message', lambda: i, time_expire=0)
> print "main:", i
> sleep(1)
> return "done"
> else:
> cache.ram('message', lambda: -1, time_expire=0)
> return locals()
>
> When progress is triggered it begins to change cache.ram("message") each 
> second
>
> If i visit getprog when progress is working, on localhost works well, i 
> get the current value, but on pythonanywhere, getprog returns a response 
> when progress is finished, not while at it.
>
> Is there any parameter or way to tell cache.ram to return the current 
> value without waiting for other controllers to finish?
>
> Thanks.
>
> PD: i have tried without time.sleep, but i get the same result, cant ask 
> for the progress until the main controller (the one that updates cache.ram 
> finishes)
>

-- 
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 add response headers to cache file?

2016-05-03 Thread Antonio
Hello again, 
I'm not really sure that I fomulated correctly the question, so sorry for 
that.
I'm using web2py to get some data with which to create a dictionary that 
I'll later use on a mobile app. The thing is that it takes a while to get 
all the information (which will stay the same for long periods of time) so 
I decided to create an application cache on disk.

Before adding the cache everything worked fine. I just had to add 
response.headers['Access-Control-Allow-Origin'] = 
request.env.http_origin
response.headers['Access-Control-Allow-Origin'] = "*"
response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"

The problem is that once I added the cache, the first time I load the app 
it worked fine, but the second and the following times I get this error:
XMLHttpRequest cannot load 
http://127.0.0.1:8000/Prueba/gfs/index.json?latitude=43.4879176=-3.80055544.
 
No 'Access-Control-Allow-Origin' header is present on the requested 
resource. Origin 'http://localhost:8200 ' is therefore 
not allowed access. 


Is there a way to add headers to the response when getting the information 
from the cache files?
Thanks 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] Re: Again unsure about current.xx / singletons - from web app and from script

2016-05-03 Thread Niphlod
once you start a shell with python web2py.py -M -S . you have started 
another completely separated process: no worries about thread-safe(ing) 
anything.

On Monday, May 2, 2016 at 11:16:28 PM UTC+2, Mirek Zvolský wrote:
>
> In modules instead of
>   def modulemethod(db):
> I use
>   def modulemethod():
> db = current.db  # current.db=db is assigned in models
>
> I hope that is correct.
>
>
> Now I want reuse some module methods from script.
> I run script.py from web2py environment like: python web2py.py -M -S app 
> -R script.py
> In the script.py I have
>   from gluon import current
>   current.db = db
>
> This run without errors.
> However is it safe with regard to threads?
> Or I will have fatal problems when running more scripts together, or 
> together with the web?
>
>
> Thank you for 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] Re: cache.ram doesnt return a result until a certain request finishes

2016-05-03 Thread Niphlod
I smashed my head around it too and if the "animation" doesn't take a huge 
variation (i.e. one second OR 60 seconds) I usually get away with animating 
it with javascript until finished.

On Tuesday, May 3, 2016 at 4:50:19 AM UTC+2, Alfonso Serra wrote:
>
> Thanks Niphlod.
>
> With session.forget on both controllers and while progress is working, 
> getprog returns a response right away with the initial value, not the 
> current one. 
>
> It seems that cache.ram acts like the session object, it doesnt change 
> until the initial request (progress) finishes. Which is something that 
> doesnt happen on localhost only on production. Looks like there are some 
> blocking operations on this case.
>
> Any suggestion?
>
> is there any simpler way to implement a progress bar without having to 
> smash the db if posible?
>
>
>
>

-- 
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: A basic problem about threading and time consuming function...

2016-05-03 Thread Niphlod
NP: as everything it's not the silver bullet but with the redis incarnation 
I'm sure you can achieve less than 3 second (if you tune heartbeat even 
less than 1 second) from when the task gets queued to when it gets 
processed.

On Tuesday, May 3, 2016 at 12:32:13 PM UTC+2, Mirek Zvolský wrote:
>
> Hi, Niphlod.
>
> After I have read something about scheduler,
> I am definitively sorry for my previous notes
> and I choose web2py scheduler of course.
>
> It will be my first use of it (with much older ~3 years web2py app I have 
> used cron only),
> so it will take some time to learn with scheduler. But it is sure worth to 
> redesign it so.
>
> Thanks you are patient with me.
> Mirek
>
>
>
>
> Dne pondělí 2. května 2016 20:35:05 UTC+2 Mirek Zvolský napsal(a):
>>
>> You are right.
>> At this time it works for me via ajax well and I will look carefully for 
>> problems.
>> If so, I will move to scheduler.
>>
>> I see this is exactly what Massimo(?) writes at the bottom of Ajax 
>> chapter of the book.
>>
>> PS: about times:
>> At notebook with mobile connection it takes 20-40s. So it could be danger.
>> At cloud server with SSD it takes 2-10s. But this will be my case. And I 
>> feel better when the user can have typical response in 3s instead in 8s.
>>
>>
>>
>>
>>
>> Dne neděle 1. května 2016 22:10:31 UTC+2 Niphlod napsal(a):
>>>
>>> the statement "I don't need to use the scheduler, because I want to 
>>> start it as soon as possible" is flaky at best. If your "fetching" varies 
>>> from 2 to 20 seconds and COULD extend further to 60 seconds, waiting a few 
>>> seconds for the scheduler to start the process is  uhm... debatable.
>>> Of course relying to ajax if your "feching" can be killed in the process 
>>> is the only other way.
>>>
>>> On Sunday, May 1, 2016 at 8:09:23 PM UTC+2, Mirek Zvolský wrote:

 Thanks for info and tips, 6 years later.

 What I try to do
 is a form with single input, where user gives a query string
 and then data about (usually ~300) books will be retrieved via z39 and 
 marc protocol/format, parsed and saved into local database.

 Of course this will take a time (2? 5? 20? seconds) and I decided
 not to show the result immediately,
 but show the same form with possibility to enter the next query + there 
 is a list of pending queries (and their status - via ajax testing every 5 
 seconds)

 So my idea was to provide a return from the controller fast and before 
 the return to start a new thread to retrieve/parse/save/commit data.

 From this discussion I understand that open new thread isn't best idea.
 I think it could be still possible, because if my new thread could be 
 killed 60s later from the web server together with the original thread - 
 such possibility is not fatal problem for me here.

 However when (as I read here) this would be a little wild technology,
 and because other technologies mentioned here: 
 https://en.wikipedia.org/wiki/Comet_(programming) -paragraph 
 Aternatives, are too difficult for me,
 and because I don't want use a scheduler, because I need to start as 
 soon as possible,

 I will solve it so,
 that I will make 2 http accesses from my page: one with submit (will 
 validate/save the query to database) and one with ajax/javascript 
 (onSubmit 
 from the old page or better: onPageLoaded from the next page where I give 
 the query in .html DOM as some hidden value), which will start the z39 
 protocol/retrieve/parse/save data.
 This will be much better, because web2py in the ajax call will prepare 
 the db variable with proper db model for me (which otherwise I must handle 
 myselves in the separate thread).
 Callback from this ajax call should/could be some dummy javascript 
 function, because it is not sure, and not important, if the page still 
 exists when the server job will finish.

 So, if somebody is interesting and will read this very old thread, 
 maybe this can give him some idea for time consumming actions.
 And maybe somebody will add other important hints or comments (thanks 
 in advance).






 Dne středa 26. května 2010 0:33:02 UTC+2 Giuseppe Luca Scrofani 
 napsal(a):
>
> Hi all, as promised I'm here to prove you are patient and nice :)
> I' have to make this little app where there is a function that read
> the html content of several pages of another website (like a spider)
> and if a specified keyword is found the app refresh a page where there
> is the growing list of "match".
> Now, the spider part is already coded, is called search(), it uses
> twill to log in the target site, read the html of a list of pages,
> perform some searching procedures and keep adding the result to a
> list. I integrated this in a default.py controller and make a call in
> def index():

[web2py] Re: A basic problem about threading and time consuming function...

2016-05-03 Thread Mirek Zvolský
Hi, Niphlod.

After I have read something about scheduler,
I am definitively sorry for my previous notes
and I choose web2py scheduler of course.

It will be my first use of it (with much older ~3 years web2py app I have 
used cron only),
so it will take some time to learn with scheduler. But it is sure worth to 
redesign it so.

Thanks you are patient with me.
Mirek




Dne pondělí 2. května 2016 20:35:05 UTC+2 Mirek Zvolský napsal(a):
>
> You are right.
> At this time it works for me via ajax well and I will look carefully for 
> problems.
> If so, I will move to scheduler.
>
> I see this is exactly what Massimo(?) writes at the bottom of Ajax chapter 
> of the book.
>
> PS: about times:
> At notebook with mobile connection it takes 20-40s. So it could be danger.
> At cloud server with SSD it takes 2-10s. But this will be my case. And I 
> feel better when the user can have typical response in 3s instead in 8s.
>
>
>
>
>
> Dne neděle 1. května 2016 22:10:31 UTC+2 Niphlod napsal(a):
>>
>> the statement "I don't need to use the scheduler, because I want to start 
>> it as soon as possible" is flaky at best. If your "fetching" varies from 2 
>> to 20 seconds and COULD extend further to 60 seconds, waiting a few seconds 
>> for the scheduler to start the process is  uhm... debatable.
>> Of course relying to ajax if your "feching" can be killed in the process 
>> is the only other way.
>>
>> On Sunday, May 1, 2016 at 8:09:23 PM UTC+2, Mirek Zvolský wrote:
>>>
>>> Thanks for info and tips, 6 years later.
>>>
>>> What I try to do
>>> is a form with single input, where user gives a query string
>>> and then data about (usually ~300) books will be retrieved via z39 and 
>>> marc protocol/format, parsed and saved into local database.
>>>
>>> Of course this will take a time (2? 5? 20? seconds) and I decided
>>> not to show the result immediately,
>>> but show the same form with possibility to enter the next query + there 
>>> is a list of pending queries (and their status - via ajax testing every 5 
>>> seconds)
>>>
>>> So my idea was to provide a return from the controller fast and before 
>>> the return to start a new thread to retrieve/parse/save/commit data.
>>>
>>> From this discussion I understand that open new thread isn't best idea.
>>> I think it could be still possible, because if my new thread could be 
>>> killed 60s later from the web server together with the original thread - 
>>> such possibility is not fatal problem for me here.
>>>
>>> However when (as I read here) this would be a little wild technology,
>>> and because other technologies mentioned here: 
>>> https://en.wikipedia.org/wiki/Comet_(programming) -paragraph 
>>> Aternatives, are too difficult for me,
>>> and because I don't want use a scheduler, because I need to start as 
>>> soon as possible,
>>>
>>> I will solve it so,
>>> that I will make 2 http accesses from my page: one with submit (will 
>>> validate/save the query to database) and one with ajax/javascript (onSubmit 
>>> from the old page or better: onPageLoaded from the next page where I give 
>>> the query in .html DOM as some hidden value), which will start the z39 
>>> protocol/retrieve/parse/save data.
>>> This will be much better, because web2py in the ajax call will prepare 
>>> the db variable with proper db model for me (which otherwise I must handle 
>>> myselves in the separate thread).
>>> Callback from this ajax call should/could be some dummy javascript 
>>> function, because it is not sure, and not important, if the page still 
>>> exists when the server job will finish.
>>>
>>> So, if somebody is interesting and will read this very old thread, maybe 
>>> this can give him some idea for time consumming actions.
>>> And maybe somebody will add other important hints or comments (thanks in 
>>> advance).
>>>
>>>
>>>
>>>
>>>
>>>
>>> Dne středa 26. května 2010 0:33:02 UTC+2 Giuseppe Luca Scrofani 
>>> napsal(a):

 Hi all, as promised I'm here to prove you are patient and nice :)
 I' have to make this little app where there is a function that read
 the html content of several pages of another website (like a spider)
 and if a specified keyword is found the app refresh a page where there
 is the growing list of "match".
 Now, the spider part is already coded, is called search(), it uses
 twill to log in the target site, read the html of a list of pages,
 perform some searching procedures and keep adding the result to a
 list. I integrated this in a default.py controller and make a call in
 def index():
 This make the index.html page loading for a long time, because now it
 have to finish to scan all pages before return all results.
 What I want to achieve is to automatically refresh index every 2
 second to keep in touch with what is going on, seeing the list of
 match growing in "realtime". Even better, if I can use some sort of
 ajax magic to not refresh the entire page... but this is not vital, a