[web2py] Function in view in model less app

2014-11-30 Thread Ruud Schroen
Hi there,

I'm building a webapp with the model less app approach by Bruno Rocha and I 
stumble upon a problem.
Usually when you use models you can define function which can later be used 
inside a view.

How would I do this with a model less approach?

-- 
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 just one instance of a complex class ?

2014-11-30 Thread Stef Mientki

hello,

I've a class, that reads a huge file and parses it.
Therefor I want just one instance per session or even one over all sessions.

# The next code (placed in controler default.py) generates an error

if session.Book_Loaded is None :
  session.Book_Loaded = PuntHoofd_support.PuntHoofd_Doc ( Text )
  session.Test_One_Instance = random.randint ( 0, 1000 )
Book_Source = session.Book_Loaded
Test_One_Instance = session.Test_One_Instance

#Chapters = Test_One_Instance.Get_Chapters ( Book )
#AttributeError: 'str' object has no attribute 'Get_Chapters'

Error: session.Book_Loaded has become a string 


Now I've found a workaround that does work:
try :
  sys.Book_Loaded
except :
  sys.Book_Loaded = PuntHoofd_support.PuntHoofd_Doc ( Text )
  sys.Test_One_Instance = random.randint ( 0, 1000 )
Book_Source = sys.Book_Loaded
Test_One_Instance = sys.Test_One_Instance

Is there a better/cleaner way to realize this ?

thanks,
Stef

--
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: Function in view in model less app

2014-11-30 Thread Niphlod
you're the one choosing an app without models :P there's nothing on modules 
that is available globally on views if not a model.
That being said, the model-less approach was done in a time where the thing 
that hurted performances was table definitions, that later got the 
possibility to be lazy-defined (hence the relatively small adoption of the 
model-less approach). You can still have a model that defines functions 
that you need globally, and it's the perfect place for them to be.

On Sunday, November 30, 2014 12:42:21 PM UTC+1, Ruud Schroen wrote:

 Hi there,

 I'm building a webapp with the model less app approach by Bruno Rocha and 
 I stumble upon a problem.
 Usually when you use models you can define function which can later be 
 used inside a view.

 How would I do this with a model less approach?


-- 
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: are expired session files deleted automatically?

2014-11-30 Thread Niphlod
folders do not create a performance issue on ntfs. if you want to keep it 
clean for aestethical reasons, do it with another step in your batch...

On Sunday, November 30, 2014 8:23:50 AM UTC+1, Dmitry Ermolaev wrote:

 but folders not deleted ((

 I make .bat file for WIN
 ===
 set sleep=7200
 set /a sleep3=%sleep%/3

 :rep

 c:\python27\python ..\..\web2py.py -S ipay -M -R scripts/sessions2trash.py 
 -A -o -x %sleep% -f -v

 timeout /t %sleep3%

 goto rep
 ==

 вторник, 25 ноября 2014 г., 15:37:36 UTC+3 пользователь Anthony написал:


 http://web2py.com/books/default/chapter/29/13/deployment-recipes#Cleaning-up-sessions

 On Tuesday, November 25, 2014 6:10:17 AM UTC-5, Robin Manoli wrote:

 Hi!

 I noticed that when I'm working alone on a project, the session folder 
 creates quite a lot of sessions. I wonder if web2py deletes expired 
 automatically? Or is there a way to delete them? It wouldn't be so nice to 
 have expired sessions of thousands of users when the site is in production 
 mode, would it?

 Thanks for your time,
 - Robin



-- 
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: jQuery - Examples from book not working.

2014-11-30 Thread Niphlod
something extremely wrong is going on with your javascript. the ready 
call is pretty much the default way of handling events once the document 
has been loaded.

On Sunday, November 30, 2014 7:16:04 AM UTC+1, Jeremiah Peterson wrote:

 Here's the example from the book, which isn't working for me. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script
 jQuery(document).ready(function(){
jQuery('.one').click(function(){jQuery('.two').slideToggle()});
 });
 /script


 This code does work, just removing the ready. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script

jQuery('.one').click(function(){jQuery('.two').slideToggle()});

 /script

 Any ideas?




-- 
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: Function in view in model less app

2014-11-30 Thread Ruud Schroen
Hmm i didnt't know about that, i really need to check out lazy_tables.
Saves me alot of time :P thanks for the info
Op 30-nov.-2014 13:38 schreef Niphlod niph...@gmail.com:

 you're the one choosing an app without models :P there's nothing on
 modules that is available globally on views if not a model.
 That being said, the model-less approach was done in a time where the
 thing that hurted performances was table definitions, that later got the
 possibility to be lazy-defined (hence the relatively small adoption of the
 model-less approach). You can still have a model that defines functions
 that you need globally, and it's the perfect place for them to be.

 On Sunday, November 30, 2014 12:42:21 PM UTC+1, Ruud Schroen wrote:

 Hi there,

 I'm building a webapp with the model less app approach by Bruno Rocha and
 I stumble upon a problem.
 Usually when you use models you can define function which can later be
 used inside a view.

 How would I do this with a model less approach?

  --
 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 a topic in the
 Google Groups web2py-users group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/web2py/1mibYB-hRrE/unsubscribe.
 To unsubscribe from this group and all its topics, 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: add task and wait the result

2014-11-30 Thread Niphlod
when nothing is going wrong, and with default values, you can expect to 
queue a task and have it assigned in 15 seconds. if that's not the case, 
something is going wrong (other tasks are being processed, workers not 
ready, db contention, etc etc etc)

On Friday, November 28, 2014 8:02:15 PM UTC+1, nick name wrote:

 Related, but not exactly the same question:

 I'm submitting an immediate task in a regular (no sleep or anything -- 
 though no special commit either); I can see it's queued for seconds and 
 sometimes minutes before getting assigned and running.

 There are no other tasks waiting or running, there are one or two 
 schedulers running (one starts with app server, one independently - but I 
 tried only one with same results). Before I dig deep into debugging the 
 scehduler - is there something simple I might be missing?

 Other things:

 main app db, auth db and sched db are all different, and all are SQLite 
 files. Running on Linux. Tasks are given a uuid by me (easiest way to track 
 if something was done in a previous run or not - uuid reflects the exact 
 operation needed).

 Thanks in advance.

 On Friday, November 28, 2014 7:30:44 PM UTC+2, Niphlod wrote:

 def test():
  newid = sched.queue_task(, immediate=True)
  db.commit() #the db instance where the scheduler is
  while True:
  rtn = sched.task_status(newid)
  if rtn.status == 'COMPLETED':
...blablabla
break
  time.sleep(3)


 not tested (haven't a web2py to try it on ATM) but you get the idea

 On Friday, November 28, 2014 7:30:18 AM UTC+1, Manuele wrote:

 Hi, 
 I would like to add an immediate task to the scheduler and wait for the 
 result within the same submit. Is it possible? How? 

 Thank you very mutch 

 Manuele 



-- 
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: web2py with bootstrap-slider bootstrap-typeahead

2014-11-30 Thread Niphlod
use some javascript 101 course before digging into javascript. One issue 
with your code is that you're not waiting the document to be ready before 
calling the javascript bit. Use $(document).ready(function() {}) to wrap 
any javascript in the page.

On Friday, November 28, 2014 8:49:35 PM UTC+1, fsp wrote:

 Hy everyone.

 I'm working with web2py since one year. In most cases it's a fine and easy 
 way to develop a nice working web app.

 Now i want to create a new web application in web 2.0 design.
 For this i want to use more bootstrap components

 i need to use the bootstrap slider
 http://seiyria.github.io/bootstrap-slider/

 and the autocomplete extension
 https://twitter.github.io/typeahead.js/examples/

 i've downloaded the java scripts and css files and placed them to the js 
 and css directory.

 After this, i added 
 link href={{=URL('static', 'css/bootstrap-slider.css')}} rel=
 stylesheet type=text/css /
 script src={{=URL('static','js/bootstrap-slider.js')}}/script

 in my view html file.

 i also added a sample in my view file..

 input id=ex1 data-slider-id='ex1Slider' type=text data-slider-min=0 
 data-slider-max=20 data-slider-step=1 data-slider-value=14/


 script
 $('#ex1').slider({
 formatter: function(value) {
 return 'Current value: ' + value;
 }
 });


 /script


 style
 #ex1Slider .slider-selection {
 background: #BABABA;
 }
 /style

 But it does not work.
 Just a empty input filed is displayed..

 I added a alter in the slider.js file. This works - alter call is 
 displayed.

 Can anybody help me??

 Regards 
 Florian


-- 
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: Web2py's included connection pooling VS external pooling software

2014-11-30 Thread Niphlod
did you restart the webserver ? I don't think that changing pool_size at 
runtime when connections are still open will make the number of active 
connection dropped.

On Friday, November 28, 2014 8:48:07 PM UTC+1, Lisandro wrote:

 Mmm... I see. That was my understanding in the first place. 
 At that time I did the maths, I had 10 apps, each one using a 
 pool_size of 3. In postgresql.conf max_connections was set to 80. 
 However this morning, with those numbers, almost every of my websites 
 was throwing intermitent HTTP 500 errors, and the error tickets were 
 all the same: FATAL: remaining connection slots are reserved for 
 non-replication superuser connections. 

 Right now, I have almost 13 websites, all of them with pool_size in 3, 
 and max_connections in 80. 
 However, if I check the table pg_stat_activity I can see 65 
 connections, and I can see there is 5 connections per app. 

 I've tried even setting pool_size to 1 for one of the apps, restarted 
 database server and webserver, but again I check pg_stat_activity and 
 I see 5 connections for that app. ¿Am I missing something too ovbious? 


 2014-11-28 14:25 GMT-03:00 Niphlod nip...@gmail.com javascript:: 
  
  
  On Friday, November 28, 2014 3:31:02 PM UTC+1, Lisandro wrote: 
  
  I go back to this thread because today I ran with the same problem: 
  postgresql reaching max_connection limits and, therefor, some of my 
 websites 
  throwing intermitent HTTP 500 errors (because web2py couldn't connect 
 to the 
  database). 
  
  To remind, we are talking of a VPS with multiple instances of web2py 
  running, all of them serving the same web2py app, each one connecting 
 to a 
  different postgresql database (however the database structure is the 
 same 
  accross all the databases). Each web2py instance is served by a 
 lighttpd 
  virtual host through fastcgi. Each virtual host (that is, each web2py 
  instance) receives a different volume of traffic (that is obvious, they 
 are 
  different websites with different public). 
  
  The original problem (the one that caused I post this question in the 
  first place) was that the postgresql database server was reaching the 
  max_connections limit and, in consecuence, some of the websites were 
  throwing intermitent HTTP 500 errors (web2py couldn't connect to 
 database). 
  
  Then, the user oriented me with pool_size parameter of DAL 
 constructor. 
  Thanks again! 
  I've been reading the web2py documentation about pooling [1] and I 
 notice 
  that it says that When the next http request arrives, web2py tries to 
  recycle a connection from the pool and use that for the new 
 transaction. If 
  there are no available connections in the pool, a new connection is 
  established. 
  So, if I didn't get it wrong, I deduce that with web2py's pooling 
  mechanism I can't overcome the max_connections postgresql limit. That 
 is 
  because, no matter the size of the pool, if the pool is full and the 
 website 
  is receiving a lot of requests, new connetions will be created, and 
  eventually the database server will reach the max_conectios limit. 
  
  
  no, you got it wrong again. pool_size=5 will create AT MOST 5 
 connections . 
  if a 6th is needed, users will wait for a connection to be freed. 
  if your postgresql accept at most 50 connections, do the math. 
  Every db = DAL(, pool_size=5) lying around will create AT MOST 5 
  connections, and that means you can host 10 apps. 
  If you need 50 apps, set pool_size=1 and let users wait, or set 
  max_connections in postgres to a higher value. 
  
  -- 
  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 a topic in the 
  Google Groups web2py-users group. 
  To unsubscribe from this topic, visit 
  https://groups.google.com/d/topic/web2py/5RTO_RqCsus/unsubscribe. 
  To unsubscribe from this group and all its topics, send an email to 
  web2py+un...@googlegroups.com javascript:. 
  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: add task and wait the result

2014-11-30 Thread nick name
Is that true even with immediate=True? If so, what is the recommended way 
to reduce this to 0.5 seconds or so? I have an app in which a user requests 
somethng; that request launches 1-10 other web requests, and the user keeps 
refreshing until they all complete for the summarized result. (I will 
probably replace this with an ajax poll or a ws notification instead later 
on).

Any time before the first assignment is essentially dead time that I 
would like to avoid. What's the best way to do so?
I understand the scheduler might not have been designed for this setting 
(although otherwise it is perfect) - if I want to hack it, to e.g. checkl 
some shared flag (e.g. create a file) that will be signaled on queue_task) 
to try to assign things, would that work? would that be accepted upstream? 
Or should I just implement my own queue/scheduler for this?

I cannot reproduce the several minute wait right now - I'm now getting the 
expected 10-15 seconds (Possibly there was a database contention or 
something like that that caused database access to stall - but the logging 
looked like things were running). But what could go wrong that would 
cause minutes of delay?

On Sunday, November 30, 2014 2:43:15 PM UTC+2, Niphlod wrote:

 when nothing is going wrong, and with default values, you can expect to 
 queue a task and have it assigned in 15 seconds. if that's not the case, 
 something is going wrong (other tasks are being processed, workers not 
 ready, db contention, etc etc etc)

 On Friday, November 28, 2014 8:02:15 PM UTC+1, nick name wrote:

 Related, but not exactly the same question:

 I'm submitting an immediate task in a regular (no sleep or anything -- 
 though no special commit either); I can see it's queued for seconds and 
 sometimes minutes before getting assigned and running.

 There are no other tasks waiting or running, there are one or two 
 schedulers running (one starts with app server, one independently - but I 
 tried only one with same results). Before I dig deep into debugging the 
 scehduler - is there something simple I might be missing?

 Other things:

 main app db, auth db and sched db are all different, and all are SQLite 
 files. Running on Linux. Tasks are given a uuid by me (easiest way to track 
 if something was done in a previous run or not - uuid reflects the exact 
 operation needed).

 Thanks in advance.

 On Friday, November 28, 2014 7:30:44 PM UTC+2, Niphlod wrote:

 def test():
  newid = sched.queue_task(, immediate=True)
  db.commit() #the db instance where the scheduler is
  while True:
  rtn = sched.task_status(newid)
  if rtn.status == 'COMPLETED':
...blablabla
break
  time.sleep(3)


 not tested (haven't a web2py to try it on ATM) but you get the idea

 On Friday, November 28, 2014 7:30:18 AM UTC+1, Manuele wrote:

 Hi, 
 I would like to add an immediate task to the scheduler and wait for the 
 result within the same submit. Is it possible? How? 

 Thank you very mutch 

 Manuele 



-- 
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] Function in view in model less app

2014-11-30 Thread Anthony
Of course, if you define a function in a module, you will need to explicitly 
import it. You can import it in a model file if you like.

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] Re: jQuery - Examples from book not working.

2014-11-30 Thread Jeremiah Peterson
I did load the example in a new dummy app and it works like it should. Any 
idea what would have changed, or what I could look at in my real app? Could 
this template I used have messed something up? Thanks for looking.

On Sunday, November 30, 2014 6:40:52 AM UTC-6, Niphlod wrote:

 something extremely wrong is going on with your javascript. the ready 
 call is pretty much the default way of handling events once the document 
 has been loaded.

 On Sunday, November 30, 2014 7:16:04 AM UTC+1, Jeremiah Peterson wrote:

 Here's the example from the book, which isn't working for me. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script
 jQuery(document).ready(function(){
jQuery('.one').click(function(){jQuery('.two').slideToggle()});
 });
 /script


 This code does work, just removing the ready. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script

jQuery('.one').click(function(){jQuery('.two').slideToggle()});

 /script

 Any ideas?




-- 
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: Web2py's included connection pooling VS external pooling software

2014-11-30 Thread Lisandro Rostagno
Yes in deed. I've restarted the webserver and the database server.
Recently I've tried setting pool_size to 1 for every app, that is, for
every website. Restarted postgresql and webserver (lighttpd). And then I
used this SQL statement to check the total count of connections for every
database (or what it is the same, for every app, because every app has its
own database):

select datname, count(*) from pg_stat_activity group by datname order by
datname;

Just to remind, I have around 13 apps running, that is, 13 websites, 13
databases.
With this new configuration of every app using a pool size of 1, I
restarted the database server and the webserver, and then I ran the
previous SQL statement to see the total connections for every app, and I
see 5 idle connections for every app, that is, for every website that has
some visitors browsing the site.
A couple of the websites almost never have visitors, so, for those
websites, there were no idle connections. Then I go to the homepage of
those websites, rechecked connections, and there I see 5 idle connections
for those websites.

I already checked and re-checked the code of my app to be shure that I'm
setting pool_size parameter correctly.


In the other hand, I've been testing pgbouncer on localhost, reading about
it, and I'll be setting it for production. For what I've read,
independently of the postgresql max connections, I can set pgbouncer to a
max_client_conn of 2000 (for example) with a default_pool_size of 20. Then
all the apps connect to pgbouncer, and pgbouncer will multiplex connections
to postgres. However I don't want to mix things in this post, regardless of
pgbouncer, I would like to understand why I can't get to work web2py's
pooling mechanism.

I'm really grateful for your help! I'll continue trying to figure it out.
Any comment or suggestion will be appreciated. Thanks!


2014-11-30 9:48 GMT-03:00 Niphlod niph...@gmail.com:

 did you restart the webserver ? I don't think that changing pool_size at
 runtime when connections are still open will make the number of active
 connection dropped.

 On Friday, November 28, 2014 8:48:07 PM UTC+1, Lisandro wrote:

 Mmm... I see. That was my understanding in the first place.
 At that time I did the maths, I had 10 apps, each one using a
 pool_size of 3. In postgresql.conf max_connections was set to 80.
 However this morning, with those numbers, almost every of my websites
 was throwing intermitent HTTP 500 errors, and the error tickets were
 all the same: FATAL: remaining connection slots are reserved for
 non-replication superuser connections.

 Right now, I have almost 13 websites, all of them with pool_size in 3,
 and max_connections in 80.
 However, if I check the table pg_stat_activity I can see 65
 connections, and I can see there is 5 connections per app.

 I've tried even setting pool_size to 1 for one of the apps, restarted
 database server and webserver, but again I check pg_stat_activity and
 I see 5 connections for that app. ¿Am I missing something too ovbious?


 2014-11-28 14:25 GMT-03:00 Niphlod nip...@gmail.com:
 
 
  On Friday, November 28, 2014 3:31:02 PM UTC+1, Lisandro wrote:
 
  I go back to this thread because today I ran with the same problem:
  postgresql reaching max_connection limits and, therefor, some of my
 websites
  throwing intermitent HTTP 500 errors (because web2py couldn't connect
 to the
  database).
 
  To remind, we are talking of a VPS with multiple instances of web2py
  running, all of them serving the same web2py app, each one connecting
 to a
  different postgresql database (however the database structure is the
 same
  accross all the databases). Each web2py instance is served by a
 lighttpd
  virtual host through fastcgi. Each virtual host (that is, each web2py
  instance) receives a different volume of traffic (that is obvious,
 they are
  different websites with different public).
 
  The original problem (the one that caused I post this question in the
  first place) was that the postgresql database server was reaching the
  max_connections limit and, in consecuence, some of the websites were
  throwing intermitent HTTP 500 errors (web2py couldn't connect to
 database).
 
  Then, the user oriented me with pool_size parameter of DAL
 constructor.
  Thanks again!
  I've been reading the web2py documentation about pooling [1] and I
 notice
  that it says that When the next http request arrives, web2py tries to
  recycle a connection from the pool and use that for the new
 transaction. If
  there are no available connections in the pool, a new connection is
  established.
  So, if I didn't get it wrong, I deduce that with web2py's pooling
  mechanism I can't overcome the max_connections postgresql limit.
 That is
  because, no matter the size of the pool, if the pool is full and the
 website
  is receiving a lot of requests, new connetions will be created, and
  eventually the database server will reach the max_conectios limit.
 
 
  no, you got it wrong again. 

[web2py] Re: how to get just one instance of a complex class ?

2014-11-30 Thread Anthony
I think your options are:

   - Make the object pickleable 
   
https://docs.python.org/2/library/pickle.html#pickling-and-unpickling-extension-types
 
   and store it in the session (this is only necessary if you really need a 
   separate object for each user's session).
   - Store the object in cache.ram (you can use a key for each user if you 
   need multiple objects, but remember to clear old keys periodically or RAM 
   will fill up).
   - Create a singleton or, if necessary, a multiton (keyed registry of 
   singletons -- e.g., http://stackoverflow.com/a/7493603/440323).

Anthony

On Sunday, November 30, 2014 7:00:48 AM UTC-5, aapaap wrote:

 hello, 

 I've a class, that reads a huge file and parses it. 
 Therefor I want just one instance per session or even one over all 
 sessions. 

 # The next code (placed in controler default.py) generates an error 

 if session.Book_Loaded is None : 
session.Book_Loaded = PuntHoofd_support.PuntHoofd_Doc ( Text ) 
session.Test_One_Instance = random.randint ( 0, 1000 ) 
 Book_Source = session.Book_Loaded 
 Test_One_Instance = session.Test_One_Instance 

 #Chapters = Test_One_Instance.Get_Chapters ( Book ) 
 #AttributeError: 'str' object has no attribute 'Get_Chapters' 

 Error: session.Book_Loaded has become a string  


 Now I've found a workaround that does work: 
 try : 
sys.Book_Loaded 
 except : 
sys.Book_Loaded = PuntHoofd_support.PuntHoofd_Doc ( Text ) 
sys.Test_One_Instance = random.randint ( 0, 1000 ) 
 Book_Source = sys.Book_Loaded 
 Test_One_Instance = sys.Test_One_Instance 

 Is there a better/cleaner way to realize this ? 

 thanks, 
 Stef 



-- 
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: jQuery - Examples from book not working.

2014-11-30 Thread Anthony
Do you accidentally load jQuery twice?

On Sunday, November 30, 2014 9:28:38 AM UTC-5, Jeremiah Peterson wrote:

 I did load the example in a new dummy app and it works like it should. Any 
 idea what would have changed, or what I could look at in my real app? Could 
 this template I used have messed something up? Thanks for looking.

 On Sunday, November 30, 2014 6:40:52 AM UTC-6, Niphlod wrote:

 something extremely wrong is going on with your javascript. the ready 
 call is pretty much the default way of handling events once the document 
 has been loaded.

 On Sunday, November 30, 2014 7:16:04 AM UTC+1, Jeremiah Peterson wrote:

 Here's the example from the book, which isn't working for me. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script
 jQuery(document).ready(function(){
jQuery('.one').click(function(){jQuery('.two').slideToggle()});
 });
 /script


 This code does work, just removing the ready. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script

jQuery('.one').click(function(){jQuery('.two').slideToggle()});

 /script

 Any ideas?




-- 
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: jQuery - Examples from book not working.

2014-11-30 Thread Jeremiah Peterson
I don't believe so. In my app that I'm working on where the .ready isn't 
working, I've created a completely new controller and view with nothing in 
it except for the example code and the example doesn't work there either on 
that. 



On Sunday, November 30, 2014 9:28:30 AM UTC-6, Anthony wrote:

 Do you accidentally load jQuery twice?

 On Sunday, November 30, 2014 9:28:38 AM UTC-5, Jeremiah Peterson wrote:

 I did load the example in a new dummy app and it works like it should. 
 Any idea what would have changed, or what I could look at in my real app? 
 Could this template I used have messed something up? Thanks for looking.

 On Sunday, November 30, 2014 6:40:52 AM UTC-6, Niphlod wrote:

 something extremely wrong is going on with your javascript. the ready 
 call is pretty much the default way of handling events once the document 
 has been loaded.

 On Sunday, November 30, 2014 7:16:04 AM UTC+1, Jeremiah Peterson wrote:

 Here's the example from the book, which isn't working for me. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script
 jQuery(document).ready(function(){
jQuery('.one').click(function(){jQuery('.two').slideToggle()});
 });
 /script


 This code does work, just removing the ready. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script

jQuery('.one').click(function(){jQuery('.two').slideToggle()});

 /script

 Any ideas?




-- 
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: jQuery - Examples from book not working.

2014-11-30 Thread Jeremiah Peterson
It seems to be this layout that's causing the 
issue. 
http://www.web2py.com/layouts/static/plugin_layouts/layouts/Emporium/index.html

1. I created a new app and just used the generic jquery example code and it 
works great. 
2. I upload that layout and then directly after it no longer works. I get 
the same behavior as I am on my app. 

Is it possible that this template is calling the .ready() somewhere 
already, so when I call it it's called twice and not working? Is there a 
way to check this?

If it's true that the template is already calling the .ready() then I can I 
skip that in my views and assume that those jquery actions won't try to run 
until the document is ready?

Thanks again for looking. 
Jeremiah

On Sunday, November 30, 2014 9:42:59 AM UTC-6, Jeremiah Peterson wrote:

 I don't believe so. In my app that I'm working on where the .ready isn't 
 working, I've created a completely new controller and view with nothing in 
 it except for the example code and the example doesn't work there either on 
 that. 



 On Sunday, November 30, 2014 9:28:30 AM UTC-6, Anthony wrote:

 Do you accidentally load jQuery twice?

 On Sunday, November 30, 2014 9:28:38 AM UTC-5, Jeremiah Peterson wrote:

 I did load the example in a new dummy app and it works like it should. 
 Any idea what would have changed, or what I could look at in my real app? 
 Could this template I used have messed something up? Thanks for looking.

 On Sunday, November 30, 2014 6:40:52 AM UTC-6, Niphlod wrote:

 something extremely wrong is going on with your javascript. the ready 
 call is pretty much the default way of handling events once the document 
 has been loaded.

 On Sunday, November 30, 2014 7:16:04 AM UTC+1, Jeremiah Peterson wrote:

 Here's the example from the book, which isn't working for me. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script
 jQuery(document).ready(function(){
jQuery('.one').click(function(){jQuery('.two').slideToggle()});
 });
 /script


 This code does work, just removing the ready. 

 div class=one id=aHello/div
 div class=two id=bWorld/div
 script

jQuery('.one').click(function(){jQuery('.two').slideToggle()});

 /script

 Any ideas?




-- 
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: jQuery - Examples from book not working.

2014-11-30 Thread Jeremiah Peterson
@Anthony, Thanks for the tip. I found this in the layout.html. Since I'm 
not using any drop down menus I've just removed it and everything seems to 
be working as expected now. 

script

 
jQuery(document).ready(function(){jQuery('ul.web2py-menu').superfish({delay:400});});
/script

I think it would be helpful for other newbies such as myself if there was 
some sort of warning about this. I wouldn't assume that if I used a layout 
that was linked directly off of the web2py site that it would make the code 
examples no longer work.  



-- 
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: Web2py's included connection pooling VS external pooling software

2014-11-30 Thread Michele Comitini
pool_size==number of threads in a web2py process.
I  suggest to work around the problem by setting the number of threads to 1
in you flup server.  I.e. no threading.
You should also see smoother performance across applications on higher
loads.

2014-11-30 15:51 GMT+01:00 Lisandro Rostagno rostagnolisan...@gmail.com:

 Yes in deed. I've restarted the webserver and the database server.
 Recently I've tried setting pool_size to 1 for every app, that is, for
 every website. Restarted postgresql and webserver (lighttpd). And then I
 used this SQL statement to check the total count of connections for every
 database (or what it is the same, for every app, because every app has its
 own database):

 select datname, count(*) from pg_stat_activity group by datname order by
 datname;

 Just to remind, I have around 13 apps running, that is, 13 websites, 13
 databases.
 With this new configuration of every app using a pool size of 1, I
 restarted the database server and the webserver, and then I ran the
 previous SQL statement to see the total connections for every app, and I
 see 5 idle connections for every app, that is, for every website that has
 some visitors browsing the site.
 A couple of the websites almost never have visitors, so, for those
 websites, there were no idle connections. Then I go to the homepage of
 those websites, rechecked connections, and there I see 5 idle connections
 for those websites.

 I already checked and re-checked the code of my app to be shure that I'm
 setting pool_size parameter correctly.


 In the other hand, I've been testing pgbouncer on localhost, reading about
 it, and I'll be setting it for production. For what I've read,
 independently of the postgresql max connections, I can set pgbouncer to a
 max_client_conn of 2000 (for example) with a default_pool_size of 20. Then
 all the apps connect to pgbouncer, and pgbouncer will multiplex connections
 to postgres. However I don't want to mix things in this post, regardless of
 pgbouncer, I would like to understand why I can't get to work web2py's
 pooling mechanism.

 I'm really grateful for your help! I'll continue trying to figure it out.
 Any comment or suggestion will be appreciated. Thanks!


 2014-11-30 9:48 GMT-03:00 Niphlod niph...@gmail.com:

 did you restart the webserver ? I don't think that changing pool_size at
 runtime when connections are still open will make the number of active
 connection dropped.

 On Friday, November 28, 2014 8:48:07 PM UTC+1, Lisandro wrote:

 Mmm... I see. That was my understanding in the first place.
 At that time I did the maths, I had 10 apps, each one using a
 pool_size of 3. In postgresql.conf max_connections was set to 80.
 However this morning, with those numbers, almost every of my websites
 was throwing intermitent HTTP 500 errors, and the error tickets were
 all the same: FATAL: remaining connection slots are reserved for
 non-replication superuser connections.

 Right now, I have almost 13 websites, all of them with pool_size in 3,
 and max_connections in 80.
 However, if I check the table pg_stat_activity I can see 65
 connections, and I can see there is 5 connections per app.

 I've tried even setting pool_size to 1 for one of the apps, restarted
 database server and webserver, but again I check pg_stat_activity and
 I see 5 connections for that app. ¿Am I missing something too ovbious?


 2014-11-28 14:25 GMT-03:00 Niphlod nip...@gmail.com:
 
 
  On Friday, November 28, 2014 3:31:02 PM UTC+1, Lisandro wrote:
 
  I go back to this thread because today I ran with the same problem:
  postgresql reaching max_connection limits and, therefor, some of my
 websites
  throwing intermitent HTTP 500 errors (because web2py couldn't connect
 to the
  database).
 
  To remind, we are talking of a VPS with multiple instances of web2py
  running, all of them serving the same web2py app, each one connecting
 to a
  different postgresql database (however the database structure is the
 same
  accross all the databases). Each web2py instance is served by a
 lighttpd
  virtual host through fastcgi. Each virtual host (that is, each web2py
  instance) receives a different volume of traffic (that is obvious,
 they are
  different websites with different public).
 
  The original problem (the one that caused I post this question in the
  first place) was that the postgresql database server was reaching the
  max_connections limit and, in consecuence, some of the websites
 were
  throwing intermitent HTTP 500 errors (web2py couldn't connect to
 database).
 
  Then, the user oriented me with pool_size parameter of DAL
 constructor.
  Thanks again!
  I've been reading the web2py documentation about pooling [1] and I
 notice
  that it says that When the next http request arrives, web2py tries
 to
  recycle a connection from the pool and use that for the new
 transaction. If
  there are no available connections in the pool, a new connection is
  established.
  So, if I didn't get it wrong, I deduce that 

Re: [web2py] Re: Web2py's included connection pooling VS external pooling software

2014-11-30 Thread Michele Comitini
p.s. by no threading I mean to use processes in place of threads.  The
number of processes is something you must tune based on server resources,
2xn where n is the number of cores is a safe choice.

2014-11-30 20:04 GMT+01:00 Michele Comitini michele.comit...@gmail.com:

 pool_size==number of threads in a web2py process.
 I  suggest to work around the problem by setting the number of threads to
 1 in you flup server.  I.e. no threading.
 You should also see smoother performance across applications on higher
 loads.

 2014-11-30 15:51 GMT+01:00 Lisandro Rostagno rostagnolisan...@gmail.com:

 Yes in deed. I've restarted the webserver and the database server.
 Recently I've tried setting pool_size to 1 for every app, that is, for
 every website. Restarted postgresql and webserver (lighttpd). And then I
 used this SQL statement to check the total count of connections for every
 database (or what it is the same, for every app, because every app has its
 own database):

 select datname, count(*) from pg_stat_activity group by datname order by
 datname;

 Just to remind, I have around 13 apps running, that is, 13 websites, 13
 databases.
 With this new configuration of every app using a pool size of 1, I
 restarted the database server and the webserver, and then I ran the
 previous SQL statement to see the total connections for every app, and I
 see 5 idle connections for every app, that is, for every website that has
 some visitors browsing the site.
 A couple of the websites almost never have visitors, so, for those
 websites, there were no idle connections. Then I go to the homepage of
 those websites, rechecked connections, and there I see 5 idle connections
 for those websites.

 I already checked and re-checked the code of my app to be shure that I'm
 setting pool_size parameter correctly.


 In the other hand, I've been testing pgbouncer on localhost, reading
 about it, and I'll be setting it for production. For what I've read,
 independently of the postgresql max connections, I can set pgbouncer to a
 max_client_conn of 2000 (for example) with a default_pool_size of 20. Then
 all the apps connect to pgbouncer, and pgbouncer will multiplex connections
 to postgres. However I don't want to mix things in this post, regardless of
 pgbouncer, I would like to understand why I can't get to work web2py's
 pooling mechanism.

 I'm really grateful for your help! I'll continue trying to figure it out.
 Any comment or suggestion will be appreciated. Thanks!


 2014-11-30 9:48 GMT-03:00 Niphlod niph...@gmail.com:

 did you restart the webserver ? I don't think that changing pool_size at
 runtime when connections are still open will make the number of active
 connection dropped.

 On Friday, November 28, 2014 8:48:07 PM UTC+1, Lisandro wrote:

 Mmm... I see. That was my understanding in the first place.
 At that time I did the maths, I had 10 apps, each one using a
 pool_size of 3. In postgresql.conf max_connections was set to 80.
 However this morning, with those numbers, almost every of my websites
 was throwing intermitent HTTP 500 errors, and the error tickets were
 all the same: FATAL: remaining connection slots are reserved for
 non-replication superuser connections.

 Right now, I have almost 13 websites, all of them with pool_size in 3,
 and max_connections in 80.
 However, if I check the table pg_stat_activity I can see 65
 connections, and I can see there is 5 connections per app.

 I've tried even setting pool_size to 1 for one of the apps, restarted
 database server and webserver, but again I check pg_stat_activity and
 I see 5 connections for that app. ¿Am I missing something too ovbious?


 2014-11-28 14:25 GMT-03:00 Niphlod nip...@gmail.com:
 
 
  On Friday, November 28, 2014 3:31:02 PM UTC+1, Lisandro wrote:
 
  I go back to this thread because today I ran with the same problem:
  postgresql reaching max_connection limits and, therefor, some of my
 websites
  throwing intermitent HTTP 500 errors (because web2py couldn't
 connect to the
  database).
 
  To remind, we are talking of a VPS with multiple instances of web2py
  running, all of them serving the same web2py app, each one
 connecting to a
  different postgresql database (however the database structure is the
 same
  accross all the databases). Each web2py instance is served by a
 lighttpd
  virtual host through fastcgi. Each virtual host (that is, each
 web2py
  instance) receives a different volume of traffic (that is obvious,
 they are
  different websites with different public).
 
  The original problem (the one that caused I post this question in
 the
  first place) was that the postgresql database server was reaching
 the
  max_connections limit and, in consecuence, some of the websites
 were
  throwing intermitent HTTP 500 errors (web2py couldn't connect to
 database).
 
  Then, the user oriented me with pool_size parameter of DAL
 constructor.
  Thanks again!
  I've been reading the web2py documentation about pooling [1] and I
 notice
  

[web2py] PostgreSQL migrate / fake_migrate_all failure with relation does not exists

2014-11-30 Thread Tom Øyvind Hogstad
My migrations suddenly failed with
Error:
class 'gluon.contrib.pg8000.errors.ProgrammingError' ('ERROR', '42P01', 
'relation wiki_page does not exist')

This will happen for any relation trying to commenting them out etc.

Running a fake_migrate_all and the problem still persists, so I can not 
find a way around manually modify my PostgreSQL schema at the moment.

Any suggestions?

Web2Py: 2.9.11
PostrgeSQL: 9.3

Tom Ø.








-- 
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] Form input show decimal fields with 4 decimals? (How to format input field in forms?)

2014-11-30 Thread Tom Øyvind Hogstad
I have the following field declaration

Field('test_BOF', 'decimal(10,2)',
label='BOF (mg/l)',
requires=IS_EMPTY_OR(IS_DECIMAL_IN_RANGE(dot=','))

In a SQLFORM this vil output as a number with a for numbered fraction e.g. 
12,3000

input class=decimal id=plant_service_test_BOF name=test_BOF type=
text value=12,3000

How can i format this value?

Web2Py: 2.9.11
DB: PostgreSQL 9.3

Tom Ø.


(BTW maybe w2p should detect the requested number of decimals from the field 
type in this case?)

-- 
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: Forking/multiprocessing bug triggered by Web2Py launch directory

2014-11-30 Thread Roshan Mathews
It's been a month since my post, so I was wondering if anyone has any hints 
they might want to share about this.

Thanks,
rm

On Friday, 31 October 2014 19:32:06 UTC+5:30, Roshan Mathews wrote:

 Hi,

 I have a weird bug that seems to be triggered when using the multiprocessing 
 module, if web2py is launched from another directory.

 I've tried to isolate the issue.  To reproduce the issue, take a clean 
 web2py source tarball, and make the following changes:

 1. to the end of *applications/welcome/controllers/default.py* add the 
 lines:
 import alpha
 def bravo():
 return alpha.charlie()

 2. create a new file *applications\welcome\modules\alpha.py* with the 
 following content
 from multiprocessing import Process, Manager

 def delta(output):
 output.append('Hello, world!')

 def charlie():
 output = Manager().list()
 p = Process(target=delta, args=(output,))
 p.start()
 p.join()
 return output[0]

 3. run it normally, 
 d:\code\temp\web2pypython web2py.py
 ... hit *http://127.0.0.1:8000/welcome/default/bravo 
 http://127.0.0.1:8000/welcome/default/bravo* ... everything works

 4. change the current working directory, and relaunch
 d:\code\temp\web2pycd ..
 d:\code\temppython web2py\web2py.py
and you get an error.  An unhelpful ticket, but the console has the 
 following traceback:
 Traceback (most recent call last):
   File string, line 1, in module
   File D:\Python27\lib\multiprocessing\forking.py, line 380, in main
 prepare(preparation_data)
   File D:\Python27\lib\multiprocessing\forking.py, line 489, in prepare
 file, path_name, etc = imp.find_module(main_name, dirs)
 ImportError: No module named web2py


 If it helps, I put a print statement before File 
 *D:\Python27\lib\multiprocessing\forking.py*, line 489, and it printed 
 out:
 ['d:\\code\\temp\\web2py\\web2py']

 Something is causing the path to add the directory web2py twice!

 If I run the code from one directory above that:
 d:\code\tempcd ..
 d:\codepython temp\web2py\web2py.py
 then the following is printed:
 ['d:\\code\\temp\\web2py\\temp\\web2py']

 Again the path is repeated twice.

 Can anyone help me understand what is causing this issue?  What is a 
 potential fix?

 If it helps, the real bug got triggered when running web2py behind Apache 
 on Windows (modwsgi), since the wsgi script was launched from some random 
 Apache directory.

 Regards,
 Roshan Mathews

 -- 
 http://about.me/rosh 


-- 
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] form warning

2014-11-30 Thread Alen Cerovic
how to make a warning message in form based on some condition but allow to 
proceed
validator?

thnx

-- 
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: Dynamic Upload Uploadfolder

2014-11-30 Thread Massimo Di Pierro
You cannot do this uploadfolder= lambda r:...
But this is a chicken-egg problem. You want r to be the row but the row is 
not created until after the file is uploaded therefore you cannot specify 
the upload folder as function of something that happens after.

Please explain to us in english of the folder should depend on the upload 
and perhaps we can suggest a way to do it.


On Saturday, 29 November 2014 14:08:20 UTC-6, James Burke wrote:

 How do you create a dynamic uploadfolder for an upload Field?

 I tried using:
 uploadfolder= lambda r: db.repository(r.repository_id).directory

 but i get the error message, I guess it doesn't have the same 
 functionality as compute: 
 cannot concatenate 'str' and 'function' objects

 I'm also using custom_store/retreive to maintain the files original 
 filename

 def store_file(file, filename=None, path=None):
 path = path # applications/init/uploads
 if not os.path.exists(path):
  os.makedirs(path)
 pathfilename = os.path.join(path, filename)
 dest_file = open(pathfilename, 'wb')
 try:
 shutil.copyfileobj(file, dest_file)
 finally:
 dest_file.close()
 return filename


 If I can set the uploadfolder dynamically then it's passed to store_file 
 as path.

 I also tried:
 path = db.repository(db.workbench(db.workbench.name==filename).repository
 ).directory

 But it can't find a record, I guess because store_file is run before the 
 record is created in the db.

 Any suggestions?

 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: Dynamic Upload Uploadfolder

2014-11-30 Thread James Burke
Thank you for your help Massimo.

My model is defined as follows:

## Repository

db.define_table('repository',
Field('name', type='string'),
Field('directory', default='applications/init/uploads'),
format='%(name)s')

## Workbench - workbenches stored in the repository

db.define_table('workbench',
Field('repository', 'reference repository'),
Field('name', compute=lambda r: 
db.workbench.workbench.retrieve(r.workbench)[0]),
Field('workbench', type='upload', required=True, 
custom_store=store_file, custom_retrieve=retrieve_file ),

Field('sequence', 'integer', required=True),
Field('created_date', 'datetime', default=request.now, readable=False, 
writable=False),
Field('modified_date', 'datetime', update=request.now, readable=False, 
writable=False),
format='%(name)s')


I have a Repository table which is joined to the Workbench table (1:M - a 
repository can have many workbenches )

In my controller I have a smartgrid for Repository which has Workbenches as 
a linked table. After a Repository has been created, the user can create 
Workbenches linked to the Repository. When creating the Workbench I want 
the workbench file to be uploaded to the directory in the Repository 
location field.

I hope that makes it clear what I'm trying to achieve.

Thank you.

On Monday, December 1, 2014 11:46:57 AM UTC+13, Massimo Di Pierro wrote:

 You cannot do this uploadfolder= lambda r:...
 But this is a chicken-egg problem. You want r to be the row but the row is 
 not created until after the file is uploaded therefore you cannot specify 
 the upload folder as function of something that happens after.

 Please explain to us in english of the folder should depend on the upload 
 and perhaps we can suggest a way to do it.


 On Saturday, 29 November 2014 14:08:20 UTC-6, James Burke wrote:

 How do you create a dynamic uploadfolder for an upload Field?

 I tried using:
 uploadfolder= lambda r: db.repository(r.repository_id).directory

 but i get the error message, I guess it doesn't have the same 
 functionality as compute: 
 cannot concatenate 'str' and 'function' objects

 I'm also using custom_store/retreive to maintain the files original 
 filename

 def store_file(file, filename=None, path=None):
 path = path # applications/init/uploads
 if not os.path.exists(path):
  os.makedirs(path)
 pathfilename = os.path.join(path, filename)
 dest_file = open(pathfilename, 'wb')
 try:
 shutil.copyfileobj(file, dest_file)
 finally:
 dest_file.close()
 return filename


 If I can set the uploadfolder dynamically then it's passed to store_file 
 as path.

 I also tried:
 path = db.repository(db.workbench(db.workbench.name==filename).repository
 ).directory

 But it can't find a record, I guess because store_file is run before the 
 record is created in the db.

 Any suggestions?

 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: form warning

2014-11-30 Thread Massimo Di Pierro
It depends on where you want to do. Personally I would not do this inside 
the validators. I would instead implement the checks after the form is 
accepted (since you want it to proceed anyway)

form = SQLFORM.factory(Field('number','double'))
if form.process().accepted:
if not form.vars.number == int(form.vars.number):
response.flash = 'ok but you did not insert an integer number'



On Sunday, 30 November 2014 13:43:09 UTC-6, Alen Cerovic wrote:

 how to make a warning message in form based on some condition but allow to 
 proceed
 validator?

 thnx


-- 
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] PostgreSQL migrate / fake_migrate_all failure with relation does not exists

2014-11-30 Thread Johann Spies

 My migrations suddenly failed with



 Error:
 class 'gluon.contrib.pg8000.errors.ProgrammingError' ('ERROR', '42P01',
 'relation wiki_page does not exist')



If the relation does exist in Postgresql (which is why you want to
migrate), try and move the related file in /app/databases/ for that table
to another destination (say /var/tmp) and try again.

If the relation does not exist in Postgresql and you want the app not to be
able to create tables freely, change the migrate to True (and fake_migrate
to False), run the app once, and change migrate and fake_migrate to their
previous status.

Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

-- 
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: multiple select plugin and list reference

2014-11-30 Thread Johann Spies
On 28 November 2014 at 13:13, Kevin Bethke kevin.bet...@gmail.com wrote:


 How do I open up the console to check for javascript errors?


If you use Firefox, open Firebug (you may have to install it) in the
developer menu.  Chrome also have a menu item for developer tools and so
Opera.

Regards
Johann

-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

-- 
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] syntax for making var appear in view

2014-11-30 Thread Alex Glaros
Question one:   

This is in controller:
vars=dict(Alex=99)

This is in view:
brAlex = {{ =response.get_vars.Alex}} br

error is:  'NoneType' object has no attribute 'Alex'.  I assume this is not 
the way to get a var to show up in view.  What is correct syntax?


Question two:

bAlex var is in controller below:
db.Suggestion.suggestionTitle.represent = lambda v, r: A(v, _href=URL(
'view_specific_suggestion', args=r.id, vars=dict(bAlex=77)))

This is in view:
vars = {{=request.vars}}br
brbAlex = {{request.vars.bAlex}}br

This is results of view:
vars = Storage {'bAlex': '77'}
bAlex = 

why is request.vars.bAlex above blank?

The resulting html address is correct
view_specific_suggestion?bAlex=77

thanks for the syntax assistance,

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.