Re: [web2py] Re: Chrome:LOAD and ajax problem

2012-08-03 Thread tomasz bandura
Hello,

After investigation, i added error handler to web2py_ajax_page and the
error's result was:


function AjaxFailed(result) {
  alert("FAILED : " + result.status + ' ' + result.statusText);
}

and the result:

result.status:0
result.statusText): 'error'

It looks rather as a jquery issue...

Regards,
Tomasz


2012/8/3 tomasz bandura 

> Hello,
>
> Application attached.
>
> default.py and advert.py have a function:
>
> def show(): return dict(test_message='show.load - default.py')
>
> and on the index.html there are LOAD declarations:
>
> {{=LOAD('advert','show.load',ajax=True)}}
> |
> {{=LOAD('default','show.load',ajax=True)}}
>
>
> Both show.load files aren't modified ( just created from web editor )
>
> Message headers in FB console:
>
>  GET /test_ajax/advert/show.load
>   HeadersResponse
>  ResponseHeaders
> RequestHeaders
> Accept */* web2py-component-location
> http://localhost:8000/test_ajax/default/index web2py-component-element
> c864146346769 X-Requested-WithXMLHttpRequest
>  GET /test_ajax/default/show.load
>   HeadersResponse
>  ResponseHeaders
> Date Fri, 03 Aug 2012 07:10:52 GMT X-Powered-Byweb2py Connection
> keep-alive Content-Length23 Pragma no-cache ServerRocket 1.2.4
> Python/2.6.6 Content-Typetext/html; charset=utf-8 Cache-Controlno-store,
> no-cache, must-revalidate, post-check=0, pre-check=0 ExpiresFri, 03 Aug
> 2012 07:10:52 GMT
> RequestHeaders
> Accept */* web2py-component-location
> http://localhost:8000/test_ajax/default/index web2py-component-element
> c339346798611 X-Requested-WithXMLHttpRequest
>
>
> The response in firebug chrome console:
>
>
>
>  GET /test_ajax/advert/show.load
>   HeadersResponse
>
>  GET /test_ajax/default/show.load
>   HeadersResponse
>
> show.load - default.py
>
>
>
>
> Regards
>
> Tomasz
>
> 2012/8/2 Anthony 
>
>>
>>> So it looks chrome can show result only when *view* and **.load*component 
>>> are declared in the same controller.
>>>
>>
>> I'm not sure I follow the above statement. Can you pack and attach a
>> minimal app that demonstrates the problem?
>>
>> Anthony
>>
>> --
>>
>>
>>
>>
>
>

-- 





Re: [web2py] Re: A Web2py CMS like Joomla ?

2012-08-03 Thread Luther Goh Lu Feng
In django, the derivaties are called Open Source Django Projects and 
described as stand-alone applications written using Django. They also have 
classifications into categories based on functionalities in the list. Is 
this something that can be useful to web2py?

https://code.djangoproject.com/wiki/DjangoResources#Open-SourceDjangoprojects

On Wednesday, August 1, 2012 11:52:28 PM UTC+8, Anthony wrote:
>
> On Wednesday, August 1, 2012 11:37:03 AM UTC-4, Massimo Di Pierro wrote:
>>
>> We could make that distinction (additional flag) and have two tabs.
>>
>
> We could, though see my other reply. Not all derivatives/distributions 
> have a running demo site, so it's probably best to include those kinds of 
> projects in http://www.web2py.com/appliances. It might make more sense to 
> enhance the appliances site -- (a) let users add projects, (b) enable 
> linking to other repos (besides the github web2py-appliances master repo), 
> (c) enable tagging, (d) enable linking to running demo sites or project 
> sites (in addition to the source code repo), (e) allow flagging of featured 
> sites to be displayed more prominently. Ultimately, it might make sense to 
> have a single site for both appliances and plugins working in this way. 
> Note, I believe web2pyslices 2.0 was originally intended to include this 
> functionality (i.e., in addition to posting recipes, questions, and 
> articles, it was supposed to allow posting of plugins and applications).
>
> Anthony
>

-- 





Re: [web2py] Re: A Web2py CMS like Joomla ?

2012-08-03 Thread Anthony
On Friday, August 3, 2012 5:28:28 AM UTC-4, Luther Goh Lu Feng wrote:
>
> In django, the derivaties are called Open Source Django Projects and 
> described as stand-alone applications written using Django. They also 
> have classifications into categories based on functionalities in the list. 
> Is this something that can be useful to web2py?
>
>
> https://code.djangoproject.com/wiki/DjangoResources#Open-SourceDjangoprojects
>

That's roughly what http://www.web2py.com/appliances is supposed to be, 
though yes, it can use improvement (which apparently is happening).

Anthony 

-- 





Re: [web2py] Re: is_impersonating() as boolean in menu

2012-08-03 Thread Martin Weissenboeck
Sorry, my tests were wrong. Please forget my last mail.
I think I have mixed two versions on my computer. I have tested it again
and now is_imperonating works as expected.
Thank you!

2012/8/3 Massimo Di Pierro 

> Clearly there is a problem with that function. If auth is defined, I'd
> expect
>
> >>> a=dict()
> >>> 'x' in a
> False
> >>> a=dict(x=1)
> >>> 'x' in a
> True
> >>>
>
> The problem I have is that it fails when the user is not logged in.
> Perhaps this is the related to your problem?
>
> I have a possible fix in trunk. Please check that it returns True/False.
> It does for me.
>
> On Friday, 3 August 2012 00:34:05 UTC-5, mweissen wrote:
>>
>> Interesting results (Version 2.00.0 (2012-08-02 21:51:02) dev)
>>
>> From tools.py:
>>
>> def is_impersonating(self):
>> return 'impersonator' in current.session.auth
>>
>> The return value of is_impersonating is not False or True but None or
>> the whole current.session.auth as string.
>> A change in tools.py to
>>
>> def is_impersonating(self):
>> return *(*'impersonator' in current.session.auth*) != None*
>>
>> works, but I cannot understand why the in-operator has not the results False
>> or True.
>>
>>
>> 2012/7/29 Massimo Di Pierro 
>>
>>> I think this should be considered a bug. Than you check trunk?
>>>
>>>
>>> On Sunday, 29 July 2012 05:37:51 UTC-5, weheh wrote:

 I haven't traced through all the code carefully, but
 is_impersonating() returns current.session.auth.**impersona**tor,
 which is based on a cPickle. So you're not getting a boolean, as you might
 be led to expect from the name of the function.


 On Sunday, July 29, 2012 1:38:42 PM UTC+8, mweissen wrote:
>
> I am using "impersonate" (great idea!) and I have a menu item which
> should only appear when somebody is impersonated. I wrote
>
> ('end impersonate', False, URL('endimpersonate'),[],*auth.
> is_impersonating()*)
>
> This did notwork, I had to write
>
> ('end impersonate', False, URL('endimpersonate'),[],*auth.
> is_impersonating()!=None*)
>
> Why?
> Regards, Martin
>
>
>>>

-- 





Re: [web2py] Re: LEFT JOIN query issues

2012-08-03 Thread Larry G. Wapnitsky

grrr ...there's always something in a programming language!

Thanks, Limedrop

On 8/2/2012 5:43 PM, Limedrop wrote:

This gets me every now and then...

In python it should be "==" rather than "="

|left=db.mr_link.on(db.mr_link.recipID==db.recipient.id))|


On Friday, August 3, 2012 8:08:38 AM UTC+12, Larry Wapnitsky wrote:

I'm trying to take the following MySQL query

|
SELECT recipient.emailAddress
FROM recipient
LEFT JOIN mr_link ON recipient.id =mr_link.recipID
|



and turn it into a DAL query, but I keep running into 'keyword' issues

My code is as such:

|
rows

=db().select(db.recipient.emailAddress,db.mr_link.ALL,left=db.mr_link.on(db.mr_link.recipID=db.recipient.id))
|

but I keep receiving


 keyword can't be an
expression (default.py, line 25)


Assistance in solving this would be very helpful

Thanks


--





--





[web2py] Re: Can't run web2py because of socket.gethostbyname problem

2012-08-03 Thread Mobility
I am not getting host name. I can run web2py on local host. When I go to my 
test deployment machine with ML Server I first get an error saying that 
wsgihandler.py file does not have exec permission. After I give permission 
on the file, chmod a+x, it says gives me an error saying premature end of 
script headers. On ML Server, I am using the same include configuration 
file on the virtual host as I used with success on LION Server. I will try 
the trunk version now as suggested by Massimo Di Pierro.

Here is the a copy of the log error:

[Tue Jul 31 18:18:07 2012] [error] [client 10.0.1.18] Premature end of 
script headers: wsgihandler.py
[Tue Jul 31 18:19:10 2012] [info] mod_wsgi (pid=6388): Shutdown requested 
'web2py443'.
[Tue Jul 31 18:19:10 2012] [info] mod_wsgi (pid=6388): Stopping process 
'web2py443'.
[Tue Jul 31 18:19:10 2012] [info] mod_wsgi (pid=6388): Destroying 
interpreters.
[Tue Jul 31 18:19:10 2012] [info] mod_wsgi (pid=6388): Cleanup interpreter 
''.
[Tue Jul 31 18:19:10 2012] [info] mod_wsgi (pid=6388): Terminating Python.
[Tue Jul 31 18:19:10 2012] [info] mod_wsgi (pid=6388): Python has shutdown.
[Tue Jul 31 18:19:10 2012] [notice] caught SIGTERM, shutting down
[Tue Jul 31 18:19:14 2012] [notice] Apache/2.2.22 (Unix) mod_wsgi/3.3 
Python/2.7.2 mod_ssl/2.2.22 OpenSSL/0.9.8r DAV/2 configured -- resuming 
normal operations

Thank you for your help.
Em sexta-feira, 27 de julho de 2012 03h16min30s UTC-3, pbreit escreveu:
>
> This change is preventing me from starting web2py because of a problem 
> with socket.gethostbyname():
>
> http://code.google.com/p/web2py/source/detail?r=36139e7a6c9c14983e0d09f626959beb8fcf9320
>
> I'm on a Mac where I'm not exactly sure how hostnaming 
> works. socket.getfqdn() is returning some weird stuff, possibly IPv6 
> addresses.
>
> Right now, socket.getfqdn() returns 'pb-dev' which socket.gethostbyname_ex 
> is choking on. I tried changing the HostName with scutil but got an even 
> weirded 
> hostname: 
> '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'
>
> Note, this is on Mountain Lion with Xcode 4.4 installed.
>
>
> Traceback (most recent call last):
>   File "web2py.py", line 25, in 
> gluon.widget.start(cron=True)
>   File "/Users/pbreit/web2py/gluon/widget.py", line 895, in start
> (options, args) = console()
>   File "/Users/pbreit/web2py/gluon/widget.py", line 803, in console
> options.ips = [ip for ip in 
> socket.gethostbyname_ex(socket.getfqdn())[2]
> socket.gaierror: [Errno 8] nodename nor servname provided, or not known
>

-- 





Re: [web2py] Re: is_impersonating() as boolean in menu

2012-08-03 Thread Jonathan Lundell
On 3 Aug 2012, at 4:50 AM, Martin Weissenboeck  wrote:
> Sorry, my tests were wrong. Please forget my last mail.
> I think I have mixed two versions on my computer. I have tested it again and 
> now is_imperonating works as expected.
> Thank you!

That's good. I've been trying to reproduce it in a test case, and failing. I 
thought maybe that Storage needed to implement __contains__, but I couldn't 
figure out why...

> 
> 2012/8/3 Massimo Di Pierro 
> Clearly there is a problem with that function. If auth is defined, I'd expect
> 
> >>> a=dict()
> >>> 'x' in a
> False
> >>> a=dict(x=1)
> >>> 'x' in a
> True
> >>> 
> 
> The problem I have is that it fails when the user is not logged in.
> Perhaps this is the related to your problem?
> 
> I have a possible fix in trunk. Please check that it returns True/False. It 
> does for me.
> 
> On Friday, 3 August 2012 00:34:05 UTC-5, mweissen wrote:
> Interesting results (Version 2.00.0 (2012-08-02 21:51:02) dev)
> 
> From tools.py:
> 
> def is_impersonating(self):
> return 'impersonator' in current.session.auth
> 
> The return value of is_impersonating is not False or True but None or the 
> whole current.session.auth as string.
> A change in tools.py to 
> 
> def is_impersonating(self):
> return ('impersonator' in current.session.auth) != None
> 
> works, but I cannot understand why the in-operator has not the results False 
> or True.


-- 





Re: [web2py] Re: LEFT JOIN query issues

2012-08-03 Thread Jonathan Lundell
On 3 Aug 2012, at 5:08 AM, "Larry G. Wapnitsky"  wrote:
> grrr ...there's always something in a programming language!

I blame SQL...

> 
> Thanks, Limedrop
> 
> On 8/2/2012 5:43 PM, Limedrop wrote:
>> This gets me every now and then...
>> 
>> In python it should be "==" rather than "="
>> 
>>   left=db.mr_link.on(db.mr_link.recipID==db.recipient.id))
>> 
>> 
>> On Friday, August 3, 2012 8:08:38 AM UTC+12, Larry Wapnitsky wrote:
>> I'm trying to take the following MySQL query
>> 
>> SELECT recipient.emailAddress
>> FROM recipient
>> LEFT JOIN mr_link ON recipient.id = mr_link.recipID
>> 
>> 
>> 
>> and turn it into a DAL query, but I keep running into 'keyword' issues
>> 
>> My code is as such:
>> 
>> rows = db().select(db.recipient.emailAddress, db.mr_link.ALL, 
>> left=db.mr_link.on(db.mr_link.recipID=db.recipient.id))
>> 
>> but I keep receiving
>> 
>>  keyword can't be an expression (default.py, 
>> line 25)
>> 
>> Assistance in solving this would be very helpful
>> 
>> Thanks
>> 
>> 


-- 





Re: [web2py] Re: web2py still unable to create application on WebFaction

2012-08-03 Thread Alan Etkin

>
> On Thursday, June 7, 2012 6:35:19 PM UTC-7, JoeCodeswell wrote:
>>
>> Hi Noel,
>>
>> I had this problem occur AGAIN, TODAY on WebFaction, when I upgraded to 
>> Version 1.99.7 (2012-03-04 22:12:08) stable, Running on Apache/2.2.17 
>> (Unix) mod_wsgi/3.3 Python/2.7.3. When creating a new simple app from 
>> the web admin interface i get "unable to create application "newapp" (it 
>> may exist already)"
>>
>> I checked and there is NO  *welcome.w2p *in the  *web2py* directory. 
>> Here are the ssh commands i used. 
>>
>
The same issue but with an installation script on CentOS. The web2py daemon 
does not seem to create the .w2p file, so the NEWINSTALL file remains 
whenever web2py is started and creating new apps from the admin fails. 

I'd like to start and stop the rocket server within the installation .sh 
script as a workaround, but there is no web2py.py option to start and stop 
the builtin server.

Perhaps I can download a stable welcome.w2p package during installation 
from somewhere and remove the NEWINSTALL. Would be that possible?

-- 





Re: [web2py] Re: web2py still unable to create application on WebFaction

2012-08-03 Thread Jonathan Lundell
On 3 Aug 2012, at 7:13 AM, Alan Etkin  wrote:
> On Thursday, June 7, 2012 6:35:19 PM UTC-7, JoeCodeswell wrote:
> Hi Noel,
> 
> I had this problem occur AGAIN, TODAY on WebFaction, when I upgraded to 
> Version 1.99.7 (2012-03-04 22:12:08) stable, Running on Apache/2.2.17 (Unix) 
> mod_wsgi/3.3 Python/2.7.3. When creating a new simple app from the web admin 
> interface i get "unable to create application "newapp" (it may exist already)"
> 
> I checked and there is NO  welcome.w2p in the  web2py directory. Here are the 
> ssh commands i used.
> 
> The same issue but with an installation script on CentOS. The web2py daemon 
> does not seem to create the .w2p file, so the NEWINSTALL file remains 
> whenever web2py is started and creating new apps from the admin fails. 
> 
> I'd like to start and stop the rocket server within the installation .sh 
> script as a workaround, but there is no web2py.py option to start and stop 
> the builtin server.
> 
> Perhaps I can download a stable welcome.w2p package during installation from 
> somewhere and remove the NEWINSTALL. Would be that possible?

I didn't check the shell syntax, but you get the idea.

if [ -f NEWINSTALL -a -d applications/welcome ]; then
python -c "from gluon.fileutils import w2p_pack; 
w2p_pack('welcome.w2p','applications/welcome')"
rm NEWINSTALL
fi


-- 





[web2py] Webservice for web widgets: security

2012-08-03 Thread Tito Garrido
Hi Folks,

I have created a jsonp function that will be used on a script so some other
people could use widgets with just 2 lines like:

http://example.com/widget/script.js";
type="text/javascript">

This script will call the jsonp function using:

$.getJSON(widget_url, function(data) {
  $('#example-widget-container').html(data.html);
});


How could I prevent people from execute my webservice funtion from another
"js" file or a modified version?

I have checked request.env variable but I didn't find anything that I could
say:

*This call is from a javascript located in example.com, otherwise ignore.*

Thanks in advance!

Tito

-- 

Linux User #387870
.
 _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:___

-- 





Re: [web2py] Re: Question about a section of the book.

2012-08-03 Thread Toby Shepard

On 08/02/2012 12:29 PM, Niphlod wrote:

formname='something' serializes within the form a hidden input, so
web2py can distinguish what form is being submitted. If the submitted
values were to be serialized as urlencoded, just to explain, for the
first form would be

name=value&formname=form_one

and for the second

name=value&formname=form_two


Ok, I'm starting to understand.  So looking at the manual
exceprt:

def two_forms():
form1 = FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),
   INPUT(_type='submit'))
form2 = FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),
   INPUT(_type='submit'))
if form1.process(formname='form_one').accepted:
response.flash = 'form one accepted'
if form2.process(formname='form_two').accepted:
response.flash = 'form two accepted'
return dict(form1=form1, form2=form2)

I would have to assume that the hiddens are only generated
because of the call to FORM.accepted().  Should I assume then
that the 'formname' keyword is only necessary when there is
more than one form in the page?

Thanks,

Toby

--





Re: [web2py] Re: Subclass FORM?

2012-08-03 Thread Toby Shepard

def __init__(self):
super(Document, self).__init__(self)


Don't pass self to __init__() -- should be:



Ahh... much better.  Thanks!

Tobiah

--





Re: [web2py] Re: web2py still unable to create application on WebFaction

2012-08-03 Thread Alan Etkin


> > I didn't check the shell syntax, but you get the idea. 
>
> > if [ -f NEWINSTALL -a -d applications/welcome ]; then 
> >python -c "from gluon.fileutils import w2p_pack; 
> w2p_pack('welcome.w2p','applications/welcome')" 
> >rm NEWINSTALL 
> > fi 
>

Looks ok, I found this alternative (which is almost identical, but imports 
widget.py):

sudo -u uwsgi python$PREFIX -c "from gluon.main import save_password;from 
gluon import widget;save_password('$PW',443);widget.console()"


Borrowed from the ubuntu deployment script to create the admin password, 
adding the console() call from the web2py start
At least It works if tested separately

Thanks

-- 





Re: [web2py] Re: Question about a section of the book.

2012-08-03 Thread Anthony

>
> I would have to assume that the hiddens are only generated 
> because of the call to FORM.accepted().


Correct. FORM.process() ultimately calls FORM.accepts(), which adds a 
"formname" attribute. When the form is serialized in the view, the 
FORM.xml() method calls FORM.hidden_fields(), which creates a _formname 
hidden field and, optionally, a _formkey hidden field (the latter is 
created when session is passed to .accepts() and is used to protect against 
CSRF and double submission). For a FORM object, _formname defaults to 
"default", and for a SQLFORM, it defaults to "[table_name]/create" or 
"[table_name]/[record_id]".
 

>  Should I assume then 
> that the 'formname' keyword is only necessary when there is 
> more than one form in the page?
>

Yes, though as noted above, when the formname argument isn't specified, 
there will still be a default _formname.

Anthony

-- 





[web2py] run code only if you are a worker

2012-08-03 Thread Vincenzo Ampolo
Hi,

I've an import that takes too much time and resources. Basically it sets
up a NLTK tagger.

I need this feature imported only if I'm runing as a worker. If I'm
running the webserver or the shell I don't need that import at all.

Is there a way to detect if I'm a worker when the models/modules are
imported?

Thank you.
-- 
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com

-- 





[web2py] Apache vhost configuration for web2py with mod_wsgi and SSL

2012-08-03 Thread Daniel Gonzalez
Hi,

I am trying to setup an apache vhost with SSL to serve web2py. I have 
succeeded in setting up mod_wsgi, with the following vhost configuration 
file:


  ServerName www.example.com


  WSGIDaemonProcess web2py user=www-data group=www-data \
   display-name=%{GROUP}
  WSGIProcessGroup web2py
  WSGIScriptAlias / /var/www/web2py/wsgihandler.py


  
AllowOverride None
Order Allow,Deny
Deny from all

  Allow from all

  


  AliasMatch ^/([^/]+)/static/(.*) \
   /var/www/web2py/applications/$1/static/$2
  
Order Allow,Deny
Allow from all
  


  
Deny from all
  


  
Deny from all
  





Now I need to setup the SSL part. I am trying with this:

NameVirtualHost *:443

ServerName portal.wavilon.com


WSGIDaemonProcess web2py user=www-data group=www-data display-name=%{
GROUP}
WSGIScriptAlias   / /var/www/web2py/wsgihandler.py


 # static files do not need WSGI
 
 Order Allow,Deny
 Allow from all
 


# everything else goes to web2py via wsgi
 
 Order deny,allow
 Allow from all
 WSGIProcessGroup web2py
 


AliasMatch ^/([^/]+)/static/(.*) 
/var/www/web2py/applications/$1/static/$2



Order Allow,Deny
Allow from all




Deny from all




Deny from all



SSLEngine On
SSLCertificateKeyFile /etc/ssl/private/server.insecure.key
SSLCertificateFile/etc/ssl/certs/server.selfsigned.crt


# SSL workaround for MS Internet Explorer
BrowserMatch "MSIE [2-6]"  nokeepalive ssl-unclean-shutdown 
downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown


But this is not yet working. Can somebody comment, or better yet, can 
somebody provide an example of a vhost configuration for mod_wsgi + ssl + 
web2py?

Thanks,
Daniel

-- 





Re: [web2py] Webservice for web widgets: security

2012-08-03 Thread Bruno Rocha
I think you can generate a KEY in script.js (you need to generate this file
dynamically)

So you will have a key to check back when the widget gets rendered.

On Fri, Aug 3, 2012 at 12:31 PM, Tito Garrido  wrote:

> Hi Folks,
>
> I have created a jsonp function that will be used on a script so some
> other people could use widgets with just 2 lines like:
>
> http://example.com/widget/script.js"; 
> type="text/javascript">
>
> This script will call the jsonp function using:
>
> $.getJSON(widget_url, function(data) {
>   $('#example-widget-container').html(data.html);
> });
>
>
> How could I prevent people from execute my webservice funtion from another
> "js" file or a modified version?
>
> I have checked request.env variable but I didn't find anything that I
> could say:
>
> *This call is from a javascript located in example.com, otherwise ignore.*
>
> Thanks in advance!
>
> Tito
>
> --
>
> Linux User #387870
> .
>  _/_õ|__|
> ..º[ .-.___.-._| . . . .
> .__( o)__( o).:___
>
> --
>
>
>
>

-- 





Re: [web2py] Apache vhost configuration for web2py with mod_wsgi and SSL

2012-08-03 Thread Alec Taylor
You should be able to find all the relevant information here:
http://web2py.com/book/default/chapter/13

On Sat, Aug 4, 2012 at 2:58 AM, Daniel Gonzalez  wrote:

> Hi,
>
> I am trying to setup an apache vhost with SSL to serve web2py. I have
> succeeded in setting up mod_wsgi, with the following vhost configuration
> file:
>
> 
>   ServerName www.example.com
>
>
>   WSGIDaemonProcess web2py user=www-data group=www-data \
>display-name=%{GROUP}
>   WSGIProcessGroup web2py
>   WSGIScriptAlias / /var/www/web2py/wsgihandler.py
>
>
>   
> AllowOverride None
> Order Allow,Deny
> Deny from all
> 
>   Allow from all
> 
>   
>
>
>   AliasMatch ^/([^/]+)/static/(.*) \
>/var/www/web2py/applications/$1/static/$2
>   
> Order Allow,Deny
> Allow from all
>   
>
>
>   
> Deny from all
>   
>
>
>   
> Deny from all
>   
>
>
> 
>
>
> Now I need to setup the SSL part. I am trying with this:
>
> NameVirtualHost *:443
> 
> ServerName portal.wavilon.com
>
>
> WSGIDaemonProcess web2py user=www-data group=www-data display-name=%{
> GROUP}
> WSGIScriptAlias   / /var/www/web2py/wsgihandler.py
>
>
>  # static files do not need WSGI
>  
>  Order Allow,Deny
>  Allow from all
>  
>
>
> # everything else goes to web2py via wsgi
>  
>  Order deny,allow
>  Allow from all
>  WSGIProcessGroup web2py
>  
>
>
> AliasMatch ^/([^/]+)/static/(.*)
> /var/www/web2py/applications/$1/static/$2
>
>
> 
> Order Allow,Deny
> Allow from all
> 
>
>
> 
> Deny from all
> 
>
>
> 
> Deny from all
> 
>
>
> SSLEngine On
> SSLCertificateKeyFile /etc/ssl/private/server.insecure.key
> SSLCertificateFile/etc/ssl/certs/server.selfsigned.crt
>
>
> # SSL workaround for MS Internet Explorer
> BrowserMatch "MSIE [2-6]"  nokeepalive ssl-unclean-shutdown
> downgrade-1.0 force-response-1.0
> BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
> 
>
> But this is not yet working. Can somebody comment, or better yet, can
> somebody provide an example of a vhost configuration for mod_wsgi + ssl +
> web2py?
>
> Thanks,
> Daniel
>
> --
>
>
>
>

-- 





[web2py] Re: Webservice for web widgets: security

2012-08-03 Thread Anthony
You might consider using CORS: http://www.html5rocks.com/en/tutorials/cors/

Anthony

On Friday, August 3, 2012 11:31:04 AM UTC-4, Tito Garrido wrote:
>
> Hi Folks,
>
> I have created a jsonp function that will be used on a script so some 
> other people could use widgets with just 2 lines like:
>
> http://example.com/widget/script.js"; 
> type="text/javascript">
>
> This script will call the jsonp function using:
>
> $.getJSON(widget_url, function(data) {
>   $('#example-widget-container').html(data.html);
> });
>
>
> How could I prevent people from execute my webservice funtion from another 
> "js" file or a modified version?
>
> I have checked request.env variable but I didn't find anything that I 
> could say:
>
> *This call is from a javascript located in example.com, otherwise ignore.*
>
> Thanks in advance!
>
> Tito
>
> -- 
>
> Linux User #387870
> .
>  _/_õ|__|
> ..º[ .-.___.-._| . . . .
> .__( o)__( o).:___
>

-- 





[web2py] Re: run code only if you are a worker

2012-08-03 Thread Niphlod
never had this kind of requirement, so at the moment there's no such 
possibility.
Just my 2 cents (and if this results unfeasible I'll think about more, 
please bear with me for a moment)

For my current understanding, if you put that "megacall" into modules, when 
the webserver is started (i.e. you are not a worker) the module is imported 
only at the first access.
Assuming that in fact this is what happens, this "workaround" is not 
feasible ?

Also, if you need "totally-separated" environments (i.e. you use some kind 
of functions and/or modules ONLY in workers and NEVER in the web 
application) why don't you use the "external" mode of the scheduler ?

i.e.

outside web2py folder , create tasks.py

import mysuperdupermodule
def mysuperfunction(args):
  mysupderdupermodule.dothatwork(args)

tasks = dict(mytask=mysuperfunction)


and then start the scheduler NOT in embedded mode: cd to the web2py.py 
folder and
python gluon/scheduler.py -u dburi -f applications/myapp/databases/ -t /path
/to/tasks.py

PS: in order to access the scheduler tables on the webapplication (i.e. you 
queue there your tasks) you still need to have a models/scheduler.py with 
from gluon.scheduler import Scheduler; mysched = Scheduler(db, migrate=False
)

That would remain a "dumb" call just to have the table definitions in place 
and to be able to access them.


-- 





[web2py] IS_DATETIME_IN_RANGE validation error datetime format

2012-08-03 Thread Shane Tzen
There seems to be a unexpected behavior regarding the form validation
error datetime format.

In languages/en-us.py, I redefined '%Y-%m-%d %H:%M:%S' to '%m-%d-%Y
%I:%M %p'.  views/web2py_ajax.html says var w2p_ajax_datetime_format =
"{{=T('%Y-%m-%d %H:%M:%S')}}";.

Even though the calendar widget generates the expected datetime
format, upon validation, if there is an validation error, the datetime
format doesn't seem to be translated (i.e. it's still %Y-%m-%d
%H:%M:%S).

I've also to set db.table.field.requires to
IS_DATETIME_IN_RANGE(format=T('%Y-%m-%d
%H:%M:%S'),minimum=datetime.datetime.now()) with no effect.  However,
if instead I set requires to IS_DATETIME(format=T('%Y-%m-%d
%H:%M:%S')), then the validation error message displays the proper
time format.

Please let me know if I'm doing something wrong.

Thanks.

-- 





[web2py] Re: run code only if you are a worker

2012-08-03 Thread Anthony
I think when you run web2py with the -K option, 
request.global_settings.scheduler exists and is set to the name/names of 
the apps passed after the -K option (otherwise, it should be None).

Anthony

On Friday, August 3, 2012 12:50:33 PM UTC-4, Vincenzo Ampolo wrote:
>
> Hi, 
>
> I've an import that takes too much time and resources. Basically it sets 
> up a NLTK tagger. 
>
> I need this feature imported only if I'm runing as a worker. If I'm 
> running the webserver or the shell I don't need that import at all. 
>
> Is there a way to detect if I'm a worker when the models/modules are 
> imported? 
>
> Thank you. 
> -- 
> Vincenzo Ampolo 
> http://vincenzo-ampolo.net 
> http://goshawknest.wordpress.com 
>

-- 





[web2py] Re: run code only if you are a worker

2012-08-03 Thread Niphlod
the nicest feature! TY Anthony, I didn't know about request.global_settings!

PS: could we add that on the wiki at the 
http://web2py.com/books/default/chapter/29/4#request section so we don't 
forget about it ?

On Friday, August 3, 2012 10:16:36 PM UTC+2, Anthony wrote:
>
> I think when you run web2py with the -K option, 
> request.global_settings.scheduler exists and is set to the name/names of 
> the apps passed after the -K option (otherwise, it should be None).
>
> Anthony
>
> On Friday, August 3, 2012 12:50:33 PM UTC-4, Vincenzo Ampolo wrote:
>>
>> Hi, 
>>
>> I've an import that takes too much time and resources. Basically it sets 
>> up a NLTK tagger. 
>>
>> I need this feature imported only if I'm runing as a worker. If I'm 
>> running the webserver or the shell I don't need that import at all. 
>>
>> Is there a way to detect if I'm a worker when the models/modules are 
>> imported? 
>>
>> Thank you. 
>> -- 
>> Vincenzo Ampolo 
>> http://vincenzo-ampolo.net 
>> http://goshawknest.wordpress.com 
>>
>

-- 





[web2py] Web2py service won't start on Windows

2012-08-03 Thread joe

Hello

I am running apache on a dedicated windows server (2008).  As of this 
morning, it was running successfully as a process.  But it needs to be a 
service, and that is causing me a 404 error.  Basically, apache runs just 
fine as a service, but when I install and start web2py as a service, it 
starts, and then immediately stops, no matter what I do.  Here is my 
options.py:

import socket, os
ip = socket.gethostname()
port = 443
password = ''
pid_filename = 'httpserver.pid'
log_filename = 'httpserver.log'
ssl_certificate = "
ssl_private_key = "
numthreads = 10
server_name = socket.gethostname()
request_queue_size = 5
timeout = 10
shutdown_timeout = 5
folder = os.getcwd()

-- 





[web2py] Re: run code only if you are a worker

2012-08-03 Thread Anthony
There's also request.global_settings.cronjob.

On Friday, August 3, 2012 4:52:28 PM UTC-4, Niphlod wrote:
>
> the nicest feature! TY Anthony, I didn't know about 
> request.global_settings!
>
> PS: could we add that on the wiki at the 
> http://web2py.com/books/default/chapter/29/4#request section so we don't 
> forget about it ?
>
> On Friday, August 3, 2012 10:16:36 PM UTC+2, Anthony wrote:
>>
>> I think when you run web2py with the -K option, 
>> request.global_settings.scheduler exists and is set to the name/names of 
>> the apps passed after the -K option (otherwise, it should be None).
>>
>> Anthony
>>
>> On Friday, August 3, 2012 12:50:33 PM UTC-4, Vincenzo Ampolo wrote:
>>>
>>> Hi, 
>>>
>>> I've an import that takes too much time and resources. Basically it sets 
>>> up a NLTK tagger. 
>>>
>>> I need this feature imported only if I'm runing as a worker. If I'm 
>>> running the webserver or the shell I don't need that import at all. 
>>>
>>> Is there a way to detect if I'm a worker when the models/modules are 
>>> imported? 
>>>
>>> Thank you. 
>>> -- 
>>> Vincenzo Ampolo 
>>> http://vincenzo-ampolo.net 
>>> http://goshawknest.wordpress.com 
>>>
>>

-- 





[web2py] Re: Web2py service won't start on Windows

2012-08-03 Thread LightDot
My guess is that you have Apache and Rocket (web2py's internal web server) 
both claiming port 443 at the same time. Do you want to use Apache to run 
web2py or..?

Regards,
Ales


On Friday, August 3, 2012 11:40:34 PM UTC+2, joe wrote:
>
>
> Hello
>
> I am running apache on a dedicated windows server (2008).  As of this 
> morning, it was running successfully as a process.  But it needs to be a 
> service, and that is causing me a 404 error.  Basically, apache runs just 
> fine as a service, but when I install and start web2py as a service, it 
> starts, and then immediately stops, no matter what I do.  Here is my 
> options.py:
>
> import socket, os
> ip = socket.gethostname()
> port = 443
> password = ''
> pid_filename = 'httpserver.pid'
> log_filename = 'httpserver.log'
> ssl_certificate = "
> ssl_private_key = "
> numthreads = 10
> server_name = socket.gethostname()
> request_queue_size = 5
> timeout = 10
> shutdown_timeout = 5
> folder = os.getcwd()
>

-- 





[web2py] strange response.flash

2012-08-03 Thread Martin Weissenboeck
I have tried:* response.flash="Auswählen"* (German for "select") and I got *
"Ausw%C3%A4hlen"*. Looks like urllib.quote, but why?
And in some other contexts  I got "*Auswählen*" as expected. I could not
find any rule.

I am using the trunk from yesterday.

Then I wrote some test functions. I have written the results after each
block:

def flash1():
redirect (URL('flash1a', args=['hello there']))

def flash1a():
response.flash=request.args[0]
return dict(text='done')

Result:  *hello_there*  (with an underscore in place of the space)
--

def flash2():
redirect (URL('flash2a', args=['hello there äöü']))

def flash2a():
response.flash=request.args[0]
return dict(text='done')

Result: *Invalid request*. I thought "args" uses urllib.quote?
--

def flash3():
redirect (URL('flash3a', vars=dict(t='hello there äöü')))

def flash3a():
response.flash=request.vars['t']
return dict(text='done')

Result: *hello there äöü*  ok!
--

import urllib

def flash4():
response.flash='hello there äöü'
return dict(text='done')

Result:  *hello there äöü*  ok
--

def flash4a():
response.flash=urllib.quote('hello there äöü')
return dict(text='done')

Result: *hello%20there%20%C3%A4%C3%B6%C3%BC*  ok
--

def flash5():
redirect (URL('flash5a', args=[urllib.quote('hello there äöü')]))

def flash5a():
response.flash=urllib.unquote(request.args[0])
return dict(text='done')

Result*: invalid request*
--

def flash6():
return dict(load=LOAD('default', 'flash6a.load'))

def flash6a():
response.flash='hello there äöü'
return dict()

Result: nothing!!
--

def flash7():
return dict(load=LOAD('default', 'flash7a.load', vars=dict(t='hello
there äöü')))

def flash7a():
response.flash=request.vars['t']
return dict()

Result: nothing!

Some strange results, isn't it?

All functions again if someone wants to try it himself:

def flash1():
redirect (URL('flash1a', args=['hello there']))

def flash1a():
response.flash=request.args[0]
return dict(text='done')

def flash2():
redirect (URL('flash2a', args=['hello there äöü']))

def flash2a():
response.flash=request.args[0]
return dict(text='done')

def flash3():
redirect (URL('flash3a', vars=dict(t='hello there äöü')))

def flash3a():
response.flash=request.vars['t']
return dict(text='done')

def flash4():
response.flash='hello there äöü'
return dict(text='done')

import urllib

def flash4a():
response.flash=urllib.quote('hello there äöü')
return dict(text='done')

def flash5():
redirect (URL('flash5a', args=[urllib.quote('hello there äöü')]))

def flash5a():
response.flash=urllib.unquote(request.args[0])
return dict(text='done')

def flash6():
return dict(load=LOAD('default', 'flash6a.load'))

def flash6a():
response.flash='hello there äöü'
return dict()

def flash7():
return dict(load=LOAD('default', 'flash7a.load', vars=dict(flash='hello
there äöü')))

def flash7a():
response.flash=request.vars.flash
return dict()

Any answers welcome!
Regards, Martin

-- 





[web2py] Re: strange response.flash

2012-08-03 Thread Anthony
This issue is not with response.flash but with request.args. The characters 
allowed in args are fairly restrictive -- here are the regexes used: 
http://code.google.com/p/web2py/source/browse/gluon/rewrite.py#51, 
http://code.google.com/p/web2py/source/browse/gluon/rewrite.py#575.

In the LOAD() examples, try setting ajax=True and the flash should work.

Anthony

On Friday, August 3, 2012 6:23:53 PM UTC-4, mweissen wrote:
>
> I have tried:* response.flash="Auswählen"* (German for "select") and I 
> got *"Ausw%C3%A4hlen"*. Looks like urllib.quote, but why?
> And in some other contexts  I got "*Auswählen*" as expected. I could not 
> find any rule.
>
> I am using the trunk from yesterday.
>
> Then I wrote some test functions. I have written the results after each 
> block:
>
> def flash1():
> redirect (URL('flash1a', args=['hello there']))
> 
> def flash1a():
> response.flash=request.args[0]
> return dict(text='done')
>
> Result:  *hello_there*  (with an underscore in place of the space)
> --
>
> def flash2():
> redirect (URL('flash2a', args=['hello there äöü']))
> 
> def flash2a():
> response.flash=request.args[0]
> return dict(text='done')
>
> Result: *Invalid request*. I thought "args" uses urllib.quote?
> --
>
> def flash3():
> redirect (URL('flash3a', vars=dict(t='hello there äöü')))
> 
> def flash3a():
> response.flash=request.vars['t']
> return dict(text='done')
>
> Result: *hello there äöü*  ok!
> --
>
> import urllib
> 
> def flash4():
> response.flash='hello there äöü'
> return dict(text='done')
> 
> Result:  *hello there äöü*  ok
> --
>
> def flash4a():
> response.flash=urllib.quote('hello there äöü')
> return dict(text='done')
> 
> Result: *hello%20there%20%C3%A4%C3%B6%C3%BC*  ok
> --
>
> def flash5():
> redirect (URL('flash5a', args=[urllib.quote('hello there äöü')]))
> 
> def flash5a():
> response.flash=urllib.unquote(request.args[0])
> return dict(text='done')
>
> Result*: invalid request*
> --
>
> def flash6():
> return dict(load=LOAD('default', 'flash6a.load'))
> 
> def flash6a():
> response.flash='hello there äöü'
> return dict()
>
> Result: nothing!!
> --
>
> def flash7():
> return dict(load=LOAD('default', 'flash7a.load', vars=dict(t='hello 
> there äöü')))
> 
> def flash7a():
> response.flash=request.vars['t']
> return dict()
>
> Result: nothing!
>
> Some strange results, isn't it?
>
> All functions again if someone wants to try it himself:
>
> def flash1():
> redirect (URL('flash1a', args=['hello there']))
> 
> def flash1a():
> response.flash=request.args[0]
> return dict(text='done')
>
> def flash2():
> redirect (URL('flash2a', args=['hello there äöü']))
> 
> def flash2a():
> response.flash=request.args[0]
> return dict(text='done')
>
> def flash3():
> redirect (URL('flash3a', vars=dict(t='hello there äöü')))
> 
> def flash3a():
> response.flash=request.vars['t']
> return dict(text='done')
> 
> def flash4():
> response.flash='hello there äöü'
> return dict(text='done')
>
> import urllib
> 
> def flash4a():
> response.flash=urllib.quote('hello there äöü')
> return dict(text='done')
> 
> def flash5():
> redirect (URL('flash5a', args=[urllib.quote('hello there äöü')]))
> 
> def flash5a():
> response.flash=urllib.unquote(request.args[0])
> return dict(text='done')
> 
> def flash6():
> return dict(load=LOAD('default', 'flash6a.load'))
> 
> def flash6a():
> response.flash='hello there äöü'
> return dict()
>
> def flash7():
> return dict(load=LOAD('default', 'flash7a.load', 
> vars=dict(flash='hello there äöü')))
> 
> def flash7a():
> response.flash=request.vars.flash
> return dict()
>
> Any answers welcome!
> Regards, Martin
>

-- 





[web2py] Re: Centos 5 script for Nginx with Uwsgi and Web2py

2012-08-03 Thread Alan Etkin
Updated the script to:

- Write port 443 admin password
- Create welcome.w2p package (for solving admin create app feature error)
- Patch Python2.7.3 code for sqlite3 issue before installing

It was tested with a clean CentOS 5.8 vbox and is working. Needs 
improvement: it stops a few times for user confirmation

El jueves, 2 de agosto de 2012 13:16:18 UTC-3, peter escribió:
>
> Someone else has provided a script for centos 6. There are plenty of 
> webservers out there based on centos 5 I believe because of its stability. 
> So it is useful to have a script for Centos 5. Particularly as this seems 
> to be the most tricky Linux for web2py because it uses and needs python 2.4
> Massimo: it depends how long Alan will take to come up with a tested 
> script for python 2.7. A working python2.6 script is better than an almost 
> working 2.7 one.
>
>
> Peter
>
> On Thursday, 2 August 2012 15:22:27 UTC+1, Alan Etkin wrote:
>>
>> > The script I attached in my previous email is your script but with 
>> python set to be 2.6. I tested this and it works.
>>
>> My concern is that 2.7 is said to be the last supported 2.x version of 
>> Python. I agree that testing in a raw install saves time and all kinds of 
>> issues. I will deploy in a virtual machine and debug the script so I can 
>> come back with a working one.
>>
>> Shouldn't we provide the working script for the lastest CentOS 
>> distribution (which I supposse is not what we are using), instead of basing 
>> in a previous one?
>>
>>

-- 



#!/bin/bash

# Script for installing Web2py with Nginx and Uwsgi on Centos 5
# Created By Hutchinson
# Modified by spametki
# License: BSD

# It was originally posted in this web2py-users group thread:
# https://groups.google.com/forum/?fromgroups#!topic/web2py/O4c4Jfr18tM

# There are lots of subtleties of ownership, and one has to take care
# when installing python 2.6 not to stop the systems python2.4 from working.

# NOTE: The only thing that should need changing for
# each installation is the $BASEARCH (base architecture) of the machine.
# This is determined by doing uname -i. This is needed for the nginx installation.

# Retrieve base architecture
BASEARCH=$(uname -i)

# Get Web2py Admin Password
echo -e "Enter a password for web2py admin app: \c "
read  PW

echo 'Install development tools (it should take a while)'
yum install gcc gdbm-devel readline-devel ncurses-devel zlib-devel \
bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel

#=

# You can change Python and uWSGI options
# to fit your deployment needs.

# Python options
PREFIX=2.7
VERSION=2.7.3

# uWSGI options
version=uwsgi-1.2.4

echo "Install python $PREFIX without overwriting python 2.4 (no, really, this will take a while too)"

mkdir ~/src
chmod 777 ~/src
cd ~/src
wget http://www.python.org/ftp/python/$VERSION/Python-$VERSION.tgz
tar xvfz Python-$VERSION.tgz
cd Python-$VERSION

echo "Applying patch for sqlite3 bug from post http://bugs.python.org/msg161076";
curl -sk https://raw.github.com/gist/2727063/ | patch -p1

./configure --prefix=/opt/python$PREFIX --with-threads --enable-shared
make

#The altinstall ensures that python2.4 is left okay

make altinstall
echo "/opt/python$PREFIX/lib">/etc/ld.so.conf.d/opt-python$PREFIX.conf
ldconfig

#create alias so that python 2.x can be run with 'python2.x'

alias -p python$PREFIX="/opt/python$/bin/python$PREFIX"
ln -s /opt/python$PREFIX/bin/python$PREFIX /usr/bin/python$PREFIX

echo 'Install uwsgi' $version
cd ~
curl -O http://projects.unbit.it/downloads/$version.tar.gz
tar zxvf $version.tar.gz
mkdir /opt/uwsgi-python
cp -R ./$version/* /opt/uwsgi-python
cd /opt/uwsgi-python

echo "build using python $PREFIX"

python$PREFIX uwsgiconfig.py --build
useradd uwsgi

echo "Create and own uwsgi log"
# Note this log will need emptying from time to time

touch /var/log/uwsgi.log
chown uwsgi /var/log/uwsgi.log

echo "Install web2py"

cd /opt
mkdir ./web-apps
cd ./web-apps
curl -O http://www.web2py.com/examples/static/web2py_src.zip
unzip web2py_src.zip

echo "Set the ownership for web2py application to uwsgi"
chown -R uwsgi /opt/web-apps/web2py
cd /opt/web-apps/web2py
chmod -R u+rwx ./applications

echo "Now creating the admin password and creating the scaffolding app package"
sudo -u uwsgi python$PREFIX -c "from gluon.main import save_password;from gluon import widget;save_password('$PW',443);widget.console()"

echo "Now install nginx"
cd /etc/yum.repos.d
echo "[nginx]">nginx.repo

echo "baseurl=http://nginx.org/packages/centos/5/$BASEARCH/";>>nginx.repo
echo "gpgcheck=0">>nginx.repo
echo "enabled=1">>nginx.repo
yum install nginx

echo "We don't want the defaults, so remove them"
cd /etc/nginx/conf.d
mv default.conf default.conf.o
mv example_ssl.conf example_ssl.conf.o

echo "
The following configuration files are also needed
The options for uwsgi are in the following file.
Other options could be included.
"

echo "uwsgi_for_nginx.conf"

echo "
[uwsgi]
uuid=uwsgi
pyt

[web2py] if statement with multiple conditions in view

2012-08-03 Thread adohertyd
Just wondering if anyone has a solution to this. I have an if statement in 
a view:

{{if conditionA == True:}}
{{for obj in ListA:}}
{{=obj}}
{{pass}}
{{pass}}



This works fine. Now, if I add another condition to the if statement, that 
I know exists:

{{if conditionA == True and conditionB==True:}}
{{for obj in ListB:}}
{{=obj}}
{{pass}}
{{pass}}



It gives me no output but it definitely should. Am I missing something 
here? I can't see any similar examples in the docs

-- 





Re: [web2py] if statement with multiple conditions in view

2012-08-03 Thread Jonathan Lundell
On 3 Aug 2012, at 4:34 PM, adohertyd  wrote:
> Just wondering if anyone has a solution to this. I have an if statement in a 
> view:
> 
> {{if conditionA == True:}}
> {{for obj in ListA:}}
> {{=obj}}
> {{pass}}
> {{pass}}
> 
> 
> 
> This works fine. Now, if I add another condition to the if statement, that I 
> know exists:
> 
> {{if conditionA == True and conditionB==True:}}
> {{for obj in ListB:}}
> {{=obj}}
> {{pass}}
> {{pass}}
> 
> 
> 
> It gives me no output but it definitely should. Am I missing something here? 
> I can't see any similar examples in the docs
> 

Are you sure that conditionB is a boolean value? For example, (1 == True) is 
True, but (2 == True) is False.

-- 





Re: [web2py] if statement with multiple conditions in view

2012-08-03 Thread adohertyd
Yes that's correct. The data comes from a radio button so the 2 conditions 
are always true or false (boolean)

On Saturday, 4 August 2012 00:40:53 UTC+1, Jonathan Lundell wrote:
>
> On 3 Aug 2012, at 4:34 PM, adohertyd wrote:
>
> Just wondering if anyone has a solution to this. I have an if statement in 
> a view:
>
> {{if conditionA == True:}}
> {{for obj in ListA:}}
> {{=obj}}
> {{pass}}
> {{pass}}
>
>
>
> This works fine. Now, if I add another condition to the if statement, that 
> I know exists:
>
> {{if conditionA == True and conditionB==True:}}
> {{for obj in ListB:}}
> {{=obj}}
> {{pass}}
> {{pass}}
>
>
>
> It gives me no output but it definitely should. Am I missing something 
> here? I can't see any similar examples in the docs
>
>
> Are you sure that conditionB is a boolean value? For example, (1 == True) 
> is True, but (2 == True) is False.
>

-- 





Re: [web2py] if statement with multiple conditions in view

2012-08-03 Thread Jonathan Lundell
On 3 Aug 2012, at 4:45 PM, adohertyd  wrote:
> Yes that's correct. The data comes from a radio button so the 2 conditions 
> are always true or false (boolean)

Just for laughs you could try

if conditionA and conditionB:




> 
> On Saturday, 4 August 2012 00:40:53 UTC+1, Jonathan Lundell wrote:
> On 3 Aug 2012, at 4:34 PM, adohertyd wrote:
>> Just wondering if anyone has a solution to this. I have an if statement in a 
>> view:
>> 
>> {{if conditionA == True:}}
>> {{for obj in ListA:}}
>> {{=obj}}
>> {{pass}}
>> {{pass}}
>> 
>> 
>> 
>> This works fine. Now, if I add another condition to the if statement, that I 
>> know exists:
>> 
>> {{if conditionA == True and conditionB==True:}}
>> {{for obj in ListB:}}
>> {{=obj}}
>> {{pass}}
>> {{pass}}
>> 
>> 
>> 
>> It gives me no output but it definitely should. Am I missing something here? 
>> I can't see any similar examples in the docs
>> 
> 
> Are you sure that conditionB is a boolean value? For example, (1 == True) is 
> True, but (2 == True) is False.
> 
> 


-- 





Re: [web2py] if statement with multiple conditions in view

2012-08-03 Thread adohertyd
Woops! I've done a double check, the results are not boolean. I've assigned 
'Yes' and 'No' to each button. Still though, the error remains. 

{{if conditionA=="Yes" and conditionB=="Yes"}}

returns nothing but 

{{if conditionA=="Yes"}}

returns output. The problem is definitely the multiple condition

On Saturday, 4 August 2012 00:47:19 UTC+1, Jonathan Lundell wrote:
>
> On 3 Aug 2012, at 4:45 PM, adohertyd wrote:
>
> Yes that's correct. The data comes from a radio button so the 2 conditions 
> are always true or false (boolean)
>
>
> Just for laughs you could try
>
> if conditionA and conditionB:
>>
>>
>
>
>
> On Saturday, 4 August 2012 00:40:53 UTC+1, Jonathan Lundell wrote:
>>
>> On 3 Aug 2012, at 4:34 PM, adohertyd wrote:
>>
>> Just wondering if anyone has a solution to this. I have an if statement 
>> in a view:
>>
>> {{if conditionA == True:}}
>> {{for obj in ListA:}}
>> {{=obj}}
>> {{pass}}
>> {{pass}}
>>
>>
>>
>> This works fine. Now, if I add another condition to the if statement, 
>> that I know exists:
>>
>> {{if conditionA == True and conditionB==True:}}
>> {{for obj in ListB:}}
>> {{=obj}}
>> {{pass}}
>> {{pass}}
>>
>>
>>
>> It gives me no output but it definitely should. Am I missing something 
>> here? I can't see any similar examples in the docs
>>
>>
>> Are you sure that conditionB is a boolean value? For example, (1 == True) 
>> is True, but (2 == True) is False.
>>
>
>
>
>
>

-- 





Re: [web2py] if statement with multiple conditions in view

2012-08-03 Thread Jonathan Lundell
On 3 Aug 2012, at 4:55 PM, adohertyd  wrote:
> Woops! I've done a double check, the results are not boolean. I've assigned 
> 'Yes' and 'No' to each button. Still though, the error remains. 
> 
> {{if conditionA=="Yes" and conditionB=="Yes"}}
> 
> returns nothing but 
> 
> {{if conditionA=="Yes"}}
> 
> returns output. The problem is definitely the multiple condition

Please try: if conditionB == "Yes"

and perhaps: if True and True

(just to make the test case dirt-simple)

> 
> On Saturday, 4 August 2012 00:47:19 UTC+1, Jonathan Lundell wrote:
> On 3 Aug 2012, at 4:45 PM, adohertyd wrote:
>> Yes that's correct. The data comes from a radio button so the 2 conditions 
>> are always true or false (boolean)
> 
> Just for laughs you could try
> 
> if conditionA and conditionB:
>> 


-- 





[web2py] Re: if statement with multiple conditions in view

2012-08-03 Thread Anthony
Multiple condition if statements work fine in views. Try:

{{if 'yes'=='yes' and 'yes'=='yes':}}

The problem is likely in your code -- conditionB probably isn't equal to 
"Yes" when you think it is. Perhaps if you show more code we can figure it 
out.

Anthony

On Friday, August 3, 2012 7:34:50 PM UTC-4, adohertyd wrote:
>
> Just wondering if anyone has a solution to this. I have an if statement in 
> a view:
>
> {{if conditionA == "Yes":}}
> {{for obj in ListA:}}
> {{=obj}}
> {{pass}}
> {{pass}}
>
>
>
> This works fine. Now, if I add another condition to the if statement, that 
> I know exists:
>
> {{if conditionA == "Yes" and conditionB=="Yes":}}
> {{for obj in ListB:}}
> {{=obj}}
> {{pass}}
> {{pass}}
>
>
>
> It gives me no output but it definitely should. Am I missing something 
> here? I can't see any similar examples in the docs
>
>

-- 





[web2py] Re: if statement with multiple conditions in view

2012-08-03 Thread adohertyd
I'm sorry guys I'm an idiot. I've just spotted my mistake in the code. It 
was a naming error leaving ConditionB not being assigned. Sorry for wasting 
your time thanks for the help.

On Saturday, 4 August 2012 00:34:50 UTC+1, adohertyd wrote:
>
> Just wondering if anyone has a solution to this. I have an if statement in 
> a view:
>
> {{if conditionA == "Yes":}}
> {{for obj in ListA:}}
> {{=obj}}
> {{pass}}
> {{pass}}
>
>
>
> This works fine. Now, if I add another condition to the if statement, that 
> I know exists:
>
> {{if conditionA == "Yes" and conditionB=="Yes":}}
> {{for obj in ListB:}}
> {{=obj}}
> {{pass}}
> {{pass}}
>
>
>
> It gives me no output but it definitely should. Am I missing something 
> here? I can't see any similar examples in the docs
>
>

-- 





Re: [web2py] Re: run code only if you are a worker

2012-08-03 Thread Vincenzo Ampolo
On 08/03/2012 02:53 PM, Anthony wrote:
> There's also request.global_settings.cronjob.

Cool but where do I've request available? It's not at import time but
i've a request object in web2py.py -M -S milo

So when can i know that request is a valid object?

Thanks Niphlod for your help but the workaround of letting staff like
it's now is not feasible or i should wait 2 mins for each shell i open.
The external scheduler can be a solution though. But I want to try this
request method first...


-- 
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com

-- 





Re: [web2py] run code only if you are a worker

2012-08-03 Thread Jonathan Lundell
On 3 Aug 2012, at 5:23 PM, Vincenzo Ampolo  wrote:
> 
> On 08/03/2012 02:53 PM, Anthony wrote:
>> There's also request.global_settings.cronjob.
> 
> Cool but where do I've request available? It's not at import time but
> i've a request object in web2py.py -M -S milo
> 
> So when can i know that request is a valid object?
> 
> Thanks Niphlod for your help but the workaround of letting staff like
> it's now is not feasible or i should wait 2 mins for each shell i open.
> The external scheduler can be a solution though. But I want to try this
> request method first...

At least for cron jobs, web2py constructs a fake request object. Have a look at 
request.env for some distinguishing characteristics. Maybe request should have 
a documented standard way of determining the source of the invocation.

-- 





Re: [web2py] Re: run code only if you are a worker

2012-08-03 Thread Anthony

>
> On 08/03/2012 02:53 PM, Anthony wrote: 
> > There's also request.global_settings.cronjob. 
>
> Cool but where do I've request available? It's not at import time but 
> i've a request object in web2py.py -M -S milo 
>
> So when can i know that request is a valid object?
>

When you said "worker", I assumed you were using the web2py Scheduler -- is 
that the case? If so, you can put something like the following in the model 
or controller that does the import:

if request.global_settings.scheduler:
[do the time-consuming import]

If you're not using the Scheduler, what do you mean by "worker"?

Anthony 

-- 





Re: [web2py] Re: run code only if you are a worker

2012-08-03 Thread Anthony
In general, have a look at the contents of 
request.global_settings.cmd_options -- it includes the various command line 
options specified when starting web2py.

Anthony

On Friday, August 3, 2012 9:13:56 PM UTC-4, Anthony wrote:
>
> On 08/03/2012 02:53 PM, Anthony wrote: 
>> > There's also request.global_settings.cronjob. 
>>
>> Cool but where do I've request available? It's not at import time but 
>> i've a request object in web2py.py -M -S milo 
>>
>> So when can i know that request is a valid object?
>>
>
> When you said "worker", I assumed you were using the web2py Scheduler -- 
> is that the case? If so, you can put something like the following in the 
> model or controller that does the import:
>
> if request.global_settings.scheduler:
> [do the time-consuming import]
>
> If you're not using the Scheduler, what do you mean by "worker"?
>
> Anthony 
>

-- 





Re: [web2py] Re: run code only if you are a worker

2012-08-03 Thread Vincenzo Ampolo
On 08/03/2012 06:13 PM, Anthony wrote:
> When you said "worker", I assumed you were using the web2py Scheduler --
> is that the case? If so, you can put something like the following in the
> model or controller that does the import:
> 
> |
> ifrequest.global_settings.scheduler:
> [dothe time-consuming import]
> |
> 
> If you're not using the Scheduler, what do you mean by "worker"?

I was referring of a module in applications/milo/modules that is used in
a applications/milo/models

When the import is done, the request object is not yet created in either
web2py server or shell or worker (web2py.py -K milo)

It gets created elsewhere after. Because after the shell is loaded i've
a request object.

Btw I've fixed my issue using a class like this:

class Tagger(object):
tagger = None
@classmethod
def create(cls):
if not cls.tagger:
import nltk
from nltk.corpus import brown
brown_tagged = brown.tagged_sents()
cls.tagger = nltk.UnigramTagger(brown_tagged)

@classmethod
def get(cls):
if not cls.tagger:
cls.create()
return cls.tagger

When I call Tagger.get() the huge import is executed once only :)

Thanks anyway.
-- 
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com

-- 





Re: [web2py] Re: run code only if you are a worker

2012-08-03 Thread Anthony

>
> I was referring of a module in applications/milo/modules that is used in 
> a applications/milo/models 
>
> When the import is done, the request object is not yet created in either 
> web2py server or shell or worker (web2py.py -K milo) 
>

Sorry, it should be request.global_settings.cmd_options.scheduler. If you 
do:

python web2py.py -K milo

Then in the model where you important and instantiate the Tagger object, 
the request object will be available, and you should be able to do:

if request.global_settings.cmd_options.scheduler:
[do the import]

In that case, the import will only happen with the -K call.

Anthony

-- 





[web2py] Re: web2py on appfog

2012-08-03 Thread spiffytech
Followup:

I contacted AppFog support via their live chat to get a few questions 
answered:

   - Confirmed: You can't buy more storage (yet). It's a priority for them, 
   though.
   - An app's instances don't all see the same copy of the filesystem. 
   That's less of a problem than the fact that:
   - Your writable filesystem isn't persistent. AppFog recommend it be 
   devoted strictly to your codebase, with any static assets being placed on 
   something like S3.
   - Confirmed: They don't provide cron. I attempted to use web2py cron in 
   my AppFog app, but I can't make it work. I haven't tried very hard to 
   figure out why.

I was also able to get my app running on their Rackspace instances- it 
seems their `af` command doesn't work right with the --debug flag, which I 
was using to see why things weren't working :P `af start ` worked fine.

Lastly, the Apache Benchmark numbers I presented last time lasted through 
at least Monday night. When I tested tonight, they had fallen to around 1 
second average load time- far more reasonable. I asked AppFog support about 
the high load times last weekend, and they couldn't pinpoint a specific 
issue, but said they had been fiddling with things in response to opening 
to the public and I might have just caught them at a bad time. I'll give 
them the benefit of the doubt on that, but I'd still keep an eye on those 
load times for a while before assuming an app will perform reasonably on 
their service. 

So, now that I got a Rackspace deployment working, and their hosting isn't 
slower than molasses, I'm a little more optimistic about AppFog. 


On Sunday, July 29, 2012 12:04:06 AM UTC-4, spiffytech wrote:
>
> Tonight I threw up a copy of my personal site, just to see if AppFog is 
> worth looking into. Perhaps my experience would have been better if I tried 
> during business hours while their live chat support was open, but I don't 
> plan to use AppFog after this experience.
>
> The highlights:
>
>- They advertise unlimited apps, but you're limited by how many apps 
>you can squeeze into the RAM your account gets. Sure, you don't have the 
>hard cap of 10 apps like App Engine (still?) gives you, but "unlimited" 
>isn't really true
>- AppFog's founder wants you to 
> believethey're
>  proving PaaS doesn't have to be slow and expensive, but I found 
>AppFog to be slow, and their pricing 
> gets 
>nutty-expensive very fast
>- Getting my app working at all was a trying experience, and AppFog 
>doesn't offer much in the way of documentation or debug output to help you
>- No sign of a cron system, so you'll be relying on web2py's built-in 
>cron (didn't check if it works there, but I assume so)
>- All apps have a 100MB disk limit, and I don't see a way to buy more. 
>Better hope you're apps don't get very big!
>- You do have a writable filesystem, for what that's worth with the 
>100MB disk use limit. I didn't check whether all instances access the same 
>FS (that's kind of an important way so design the service)
>
> My conclusion: If you want a free place to host something that (really, 
> really) doesn't need to be performant, AppFog is a decent choice because:
>
>- It has a writable filesystem, which sets it apart from App Engine
>- It has free MySQL (App Engine started charging for MySQL in June), 
>which sets it apart from App Engine
>- It looks more likely to stick around than some of the other free web 
>host services that I've seen mentioned here
>
> However, to get that free hosting you'll have to put up with terrible 
> performance (or highly variable performance if it magically speeds up by 
> tomorrow morning), poor documentation, and a tricky and opaque setup 
> procedure.
>
> On to doing stuff, and statistics!
>
> First off, I could not find any links on their site instructing me on how 
> to configure a Python app to work on AppFog. I eventually gave up and 
> resorted to Googling for a tutorial, which led me to this 
> sectionin AppFog's docs. Not sure 
> how you are supposed to find that.
>
> That link isn't too helpful, though- it shows how to make a Flask site 
> that works on AppFog, and links to working Bottle and Django sites, but 
> doesn't spell out how to make a generic WSGI site work. To make my simple 
> web2py site work, I had to do the following:
>
> mv wsgihandler.py wsgi.py  # AppFog needs wsgi.py. I tried a symlink 
> instead of a move, but couldn't make AppFog work in that arrangement
> ln -s wsgi.py wsgihandler.py  # This ensures updates to web2py affect 
> your wsgi.py
> gem install af
> af login
> af push   # This gives you an Amazon East app. I can't figure 
> out how to use `af` to deploy to a different infrastructure
>
> I tried creating an app on the Rackspace infrastructure through AppFog

[web2py] GAE Cloud SQL local dev server problem

2012-08-03 Thread Alexei Vinidiktov
Hello,

I'm need hep figuring out how to set up a local GAE development server with
MySQL.

MySQL connection parameters are specified via App Launcher application
settings: --mysql_user=root --mysql_password=xx --mysql_host=localhost
--mysql_port=3306

When I launch my web2py app with GAE Launcher on my local Windows box I get
this erorr message:


ERROR2012-08-04 06:28:43,515 dal.py:5962] DEBUG: connect attempt 0,
connection error:
Traceback (most recent call last):
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\dal.py", line 5955,
in __init__
self._adapter = ADAPTERS[self._dbname](*args)
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\dal.py", line 3310,
in __init__
self.folder = folder or
'$HOME/'+thread.folder.split('/applications/',1)[1]
IndexError: list index out of range
#

What does the following line do?

self.folder = folder or '$HOME/'+thread.folder.split('/applications/',1)[1]

If I comment out "or '$HOME/'+thread.folder.split('/applications/',1)[1]"
in DAL.py and relaunch the dev server, the application appears to be able
to connect to MySQL but then I get a different error message:


INFO 2012-08-04 06:42:35,142 rdbms_mysqldb.py:102] Connecting to MySQL
with kwargs {'passwd': 'xx', 'unix_socket': '', 'host': 'localhost',
'port': 3306, 'user': 'root'}
ERROR2012-08-04 06:42:35,153 warnings.py:29] C:\Users\alexei\Dev\web2py\
vocabilis.net\gluon\dal.py:1386: Warning: Can't create database
'vocabilis'; database exists
  ret = self.cursor.execute(*a, **b)

ERROR2012-08-04 06:42:35,575 restricted.py:155] Traceback (most recent
call last):
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\main.py", line 510,
in wsgibase
session._try_store_in_db(request, response)
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\globals.py", line
561, in _try_store_in_db
record_id = table.insert(**dd)
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\dal.py", line 6829,
in insert
return self._db._adapter.insert(self,self._listify(fields))
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\dal.py", line 928,
in insert
raise e
ProgrammingError: (1146, "Table 'vocabilis.web2py_session_vocabilis'
doesn't exist")
#

The vocabilis database does exist. It was created earlier when I connected
to MySQL from a non GAE environment.

If I specify a different non-existent database in the connection string,
then after relaunching the application vith the GAE Launcher I get this
error message:

###
INFO 2012-08-04 06:44:45,415 rdbms_mysqldb.py:102] Connecting to MySQL
with kwargs {'passwd': 'xx', 'unix_socket': '', 'host': 'localhost',
'port': 3306, 'user': 'root'}
ERROR2012-08-04 06:44:45,828 restricted.py:155] Traceback (most recent
call last):
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\main.py", line 510,
in wsgibase
session._try_store_in_db(request, response)
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\globals.py", line
561, in _try_store_in_db
record_id = table.insert(**dd)
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\dal.py", line 6829,
in insert
return self._db._adapter.insert(self,self._listify(fields))
  File "C:\Users\alexei\Dev\web2py\vocabilis.net\gluon\dal.py", line 928,
in insert
raise e
ProgrammingError: (1146, "Table 'vocabilis3.web2py_session_vocabilis'
doesn't exist")
###

So the application  appears to be unable to create the session table.

I'm running Windows, Python 2.7, web2py 1.99.7, MySQL 5.5



-- 
Alexei Vinidiktov

--