[web2py] Re: Check

2011-07-07 Thread beedge
Apologises.

Stupid.  Double (differeing) definition of db in the model file,
before and after some custom auth tables.  Hence, app was pulling in
my apps tables, but I couldn't see the auth stuff and odd behaviour.



[web2py] headers argument behavior in v1.97.1

2011-07-07 Thread niknok
While using crud, I sometimes define headers for *some* fields listed in
the fields argument. This works until I upgraded to 1.97.1 and now I get
an error if I do not define the headers for *all* fields listed in the
fields argument.

For example, the following code no longer works

rows=crud.select(db.address
,query=((db.address.owner_is==address_owner)

(db.address.owner_is_person==address_owner_is_person))
,fields=['address.id'
,'address.line_1'
,'address.is_type'
,'address.country']
,headers={'address.id':'#'
,'address.line_1':'Street address'
,'address.country':'Country'})


until I add a header for address.is_type, too. 

Is this a bug or a new feature?


Re: [web2py] headers argument behavior in v1.97.1

2011-07-07 Thread Bruno Rocha
Can you share some example app or model + controller code t reproduce the
bug.

Do you have a Traceback ticket error? what message, what file/line?

The erro occurs when running the mentioned controller, or qhen doing some
other action on this?

Need more onfo to help tracking this issue.

[]'s

On Thu, Jul 7, 2011 at 2:50 AM, niknok nikolai...@gmail.com wrote:

 **
 While using crud, I sometimes define headers for *some* fields listed in
 the fields argument. This works until I upgraded to 1.97.1 and now I get an
 error if I do not define the headers for *all* fields listed in the fields
 argument.

 For example, the following code no longer works

 rows=crud.select(db.address
 ,query=((db.address.owner_is==address_owner)
 
 (db.address.owner_is_person==address_owner_is_person))
 ,fields=['address.id'
 ,'address.line_1'
 ,'address.is_type'
 ,'address.country']
 ,headers={'address.id':'#'
 ,'address.line_1':'Street address'
 ,'address.country':'Country'})


 until I add a header for address.is_type, too.

 Is this a bug or a new feature?




-- 



--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]
[ Aprenda a programar: http://CursoDePython.com.br ]
[ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ]
[ Consultoria em desenvolvimento web: http://www.blouweb.com ]


Re: [web2py] Re: Metaprogramming in controller

2011-07-07 Thread Miguel Lopes
I see closures are not even necessary. The solution is using routes.

For the interested routes is ok for production (the embargo was old-news).
Here's some info:
https://mail.google.com/mail/?shva=1#search/routes+production/12a53a18e7f6b2d5

Miguel

On Wed, Jul 6, 2011 at 4:03 PM, Miguel Lopes mig.e.lo...@gmail.com wrote:

 Humm,

 Nice. Yes, closures are enough, and cleaner too.
 Is routes OK for production mode?
 Txs,
 Miguel


 On Wed, Jul 6, 2011 at 3:54 PM, Massimo Di Pierro 
 massimo.dipie...@gmail.com wrote:

 Jonathan is right. Here is a simple way around.

 Create a single controller called dynamical. use request.args(0) to
 parse the name of one of the dynamical actions and remap

 def dynamical():
 actionname, request.args[:] = request.args(0), request.args[1:]
 # call actionname and pass request.args and request.vars

 use routes to remove the 'dynamical/' part form the URL.

 This allows you to do what you want without necessarily meta-
 programming.

 On Jul 6, 9:35 am, Miguel Lopes mig.e.lo...@gmail.com wrote:
  Thanks. In conjunction with routes could supply a solution (shortening
 the
  urls).
  I think I should rethink the payoff (see my reply to Massimo regarding
 my
  goals).
  Thanks,
  Miguel
 
 
 
 
 
 
 
  On Wed, Jul 6, 2011 at 3:12 PM, Jonathan Lundell jlund...@pobox.com
 wrote:
   On Jul 6, 2011, at 1:23 AM, Miguel Lopes wrote:
 
   I'm experimenting with dynamically generating functions, aka 'actions'
 in
   controllers. However, I've been unsuccessful. I can use exec and
 closures
   successfully in regular Python code, but I can't make it work with
 web2py.
   Any thoughts on how to achieve this?
 
   web2py finds functions by reading the (static) controller file itself.
 See
   gluon.compileapp.run_controller_in, in particular this line:
 
   exposed = regex_expose.findall(code)
 
   So, no dynamically generated controller actions, at least not
 directly.
 
   I haven't given this much thought, but one way you might accomplish
 the
   same effect would be to push the dynamic function name down one level
 in the
   URL, something like:http://domain.com/app/dynamic/index/function/...
 
   ...where 'dynamic' is the controller with dynamic functions, and index
 is a
   (static) function that calls function dynamically. You might optimize
 the
   lookup function to extract only the one desired function from your
 page
   table.
 
   Depending on your overall URL structure, you could rewrite the URLs to
   shorten them up.
 
   A closure example - FAILS in web2py:
   top_pages = db(db.page.id  0).select()
   def add_actions(top_pages):
   for page in top_pages:
   def inneraction(msg):
   sidebar = None
   return dict(message=msg, sidebar=sidebar)
   inneraction.__name__ = page.link_name
   globals()[page.link_name] = inneraction
 
   add_actions(top_pages)
 
   A exec example - FAILS in web2py:
 
   ACTION_TEMPLATE = 
def NEW_ACTION():
   sidebar = None
   return dict(message='s', sidebar=sidebar)

   top_pages = db(db.page.id  0).select()
   def makePages(pages):
   for page in top_pages:
   exec ACTION_TEMPLATE
   NEW_ACTION.__name__ = page.link_name
   globals()[page.link_name] = NEW_ACTION
 
   makePages(pages)
 
   Miguel





Re: [web2py] cron Too many open files regression?

2011-07-07 Thread ron_m
The code running this is in gluon/newcron.py
From your stack trace you are using hard cron which is a class at line 44. 
It runs launch once a minute
This runs crondance which puts a wrapper on the tasks that should be run 
adding web2py run line parameters if * or ** is at the beginning of the 
command. The crondance function then uses class cronlauncher which in turn 
uses subprocess.Popen to launch the task.

If you have web2py like processes building up do these processes have other 
processes with the web2py process pid listed as the parent process. You 
should be able to do a ps -ef pick the pid of one of the web2py processes 
and run another ps -ef with grep pid to filter. The process started with the 
Popen will have to close the pipe usually by exiting to release the thread 
from cronlauncher.

Do these cron tasks run okay if you just launch them from the shell. That is 
a good test to determine that there are no problems outside the cron 
environment.

Do you use a SQLite database? This database performs a global lock to 
protect from multiple access.

Do the cron tasks take more than their scheduling interval to complete. The 
launcher will run another copy without regard for an existing copy still 
running.

Do any of the tasks have locking code such as a file lock that other tasks 
depend on gaining access to. Two file locks shared by two processes with 
crossed access, one process locks a then b, other locks b then a will 
deadlock if the timing is right.

Do any tasks read stdin, the subprocess.Popen call opens the stdin of the 
process to the launcher but will never write to it so a read on stdin would 
hang preventing exit.

I hope this is some help, looks like a difficult one to find but likely 
something fairly simple to fix once you find it.

Could you post your crontab file, it would be a start of something to look 
at.




[web2py] A catchall action per controller - would be proposal

2011-07-07 Thread Miguel Lopes
Yesterday I posted about implementing dynamic actions (functions) in a
controller.
This is interesting because one can achieve clean urls, instead of passing
the names of the dynamic pages in args or vars. In a system with a cms this
has the benefit of user defined pages being indistinguishable from extant
hard-coded actions (if any).

However, given the static nature of controllers (they are compiled with
web2py) this cannot be achieved with closures or metaprogramming. The
solution is to use routes to hide a dispatching action. It maybe possible to
add to the controller namespace at runtime (but it is beyond my knowledge to
explore this).

This made me think that controllers might allow for the implementation
(override?) a single dynamic action that would serve as a catchall for calls
to non defined actions. I wonder if there as been any debate on this sort of
built-in default action? This would supply a way to dealt with all calls
that have no defined action per controller (including errors) without having
to use routes. A small idea that perhaps does not bring enough benefits to
be argued for. What do you think?

Miguel


Re: [web2py] Re: PowerFormWizard 0.1.4 - Bug Fixes and auto_validation (+ a new plugin for grids)

2011-07-07 Thread Bruno Rocha
Massimo Di Pierro massimo.dipie...@gmail.com wrote:

 Do we have a method to upload plugins in web2pyslices? If not, I will
 extend web2py.com/plugins it is becoming hard for me to keep track


Not yet, but I am writing 2.0 and this will allow some cool options for
plugins!


[web2py] Re: PowerFormWizard 0.1.4 - Bug Fixes and auto_validation (+ a new plugin for grids)

2011-07-07 Thread Bruno Rocha
UPDATE:

auto_validate renamed to .validate()

Now we have another method that allows this:

return dict(form=PowerFormWizard(db.table).process(messages=['Sucess!','Fail
try again']))

which creates and auto validate the form returning the form itsef.

Other thing I guess no one tought about is the use for single step forms:

http://labs.blouweb.com/powerformwizard/default/singlestep

You can use the plugin for one step (normal) forms, use the client side
validation and layout!

More comming...

On Tue, Jul 5, 2011 at 6:53 AM, Bruno Rocha rochacbr...@gmail.com wrote:

 HI,

 I just finished the refactoring for PFWizard plugin, major bug fixes
 (thanks everyone testing and reporting)

 *# NOTES*
 - It works only wih web2py 1.97+
 - It works only for SQLFORM based forms, you have to pass a db.table
 - It does not works for Crud() , does not allows editing or delete yet (can
 you contribute?)
 - It receives any arg that SQLFORM receives

 *# FIXES*
 - Fixed Issue #2 - Now it works with tables which has '_' or '__' in
 fieldnames.
 - Fixed Issue #1 - Now it works with Python  2.6 - removed enumerate()
 - Ommit fields - Fixed issue, now you cam ommit fields with no break in
 validation (client and server side)
 - Code cleanup, PEP8 checkups # But I really does not matter about it :P

 *# FEATURES*
 - Added form.auto_validation method
 Now you don t need to always write if form.accepts()elif
 form.errors.
 Just use in this way:

  form = PowerFormWizard(db, steps)
 form.auto_validate()
 return dict(form=form)

 or
 # define flash message
 form.auto_validate(messages=['Yeah it works', 'Ops, error'])

 or

 #execute a function after validation
 def myfunction(success, x,y,z):
  #first argument receives True or False
 

 form.auto_validate(flash=my_function, args=[x, y, z])


 DEMO  DOWNLOAD : http://labs.blouweb.com/powerformwizard
 REPO:https://bitbucket.org/rochacbruno/powerformwizard


 *# Whats next?*
 working on a new plugin for the 'Power' family, it is a JSON based
 tableless grid (which is much more than a grid)
 hope to release with examples, by the end of the week, preview -
 http://labs.blouweb.com/PowerGrid


 Need help, contribution, test..

 []'s
 --
 Bruno Rocha
 [ About me: http://zerp.ly/rochacbruno ]




-- 



--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]
[ Aprenda a programar: http://CursoDePython.com.br ]
[ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ]
[ Consultoria em desenvolvimento web: http://www.blouweb.com ]


Re: [web2py] headers argument behavior in v1.97.1

2011-07-07 Thread Martín Mulone
Did you use trunk version?, I submitted recently some changes there.-

2011/7/7 Bruno Rocha rochacbr...@gmail.com

 Can you share some example app or model + controller code t reproduce the
 bug.

 Do you have a Traceback ticket error? what message, what file/line?

 The erro occurs when running the mentioned controller, or qhen doing some
 other action on this?

 Need more onfo to help tracking this issue.

 []'s


 On Thu, Jul 7, 2011 at 2:50 AM, niknok nikolai...@gmail.com wrote:

 **
 While using crud, I sometimes define headers for *some* fields listed in
 the fields argument. This works until I upgraded to 1.97.1 and now I get an
 error if I do not define the headers for *all* fields listed in the fields
 argument.

 For example, the following code no longer works

 rows=crud.select(db.address
 ,query=((db.address.owner_is==address_owner)
 
 (db.address.owner_is_person==address_owner_is_person))
 ,fields=['address.id'
 ,'address.line_1'
 ,'address.is_type'
 ,'address.country']
 ,headers={'address.id':'#'
 ,'address.line_1':'Street address'
 ,'address.country':'Country'})


 until I add a header for address.is_type, too.

 Is this a bug or a new feature?




 --



 --
 Bruno Rocha
 [ About me: http://zerp.ly/rochacbruno ]
 [ Aprenda a programar: http://CursoDePython.com.br ]
 [ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ]
 [ Consultoria em desenvolvimento web: http://www.blouweb.com ]




-- 
 http://martin.tecnodoc.com.ar


Re: [web2py] headers argument behavior in v1.97.1

2011-07-07 Thread Martín Mulone
Yes you need to define all the headers.

2011/7/7 niknok nikolai...@gmail.com

 **
 While using crud, I sometimes define headers for *some* fields listed in
 the fields argument. This works until I upgraded to 1.97.1 and now I get an
 error if I do not define the headers for *all* fields listed in the fields
 argument.

 For example, the following code no longer works

 rows=crud.select(db.address
 ,query=((db.address.owner_is==address_owner)
 
 (db.address.owner_is_person==address_owner_is_person))
 ,fields=['address.id'
 ,'address.line_1'
 ,'address.is_type'
 ,'address.country']
 ,headers={'address.id':'#'
 ,'address.line_1':'Street address'
 ,'address.country':'Country'})


 until I add a header for address.is_type, too.

 Is this a bug or a new feature?




-- 
 http://martin.tecnodoc.com.ar


[web2py] gluon.cache on functions with arguments

2011-07-07 Thread PhE
Hello,

I'm trying to use gluon.cache and @cache decorator in my web2py
application.
It works fine for decorating controller methods.

Now, I would like to use web2py cache in my modules :

@cache('fct1_key', time_expire=5, cache_model=cache.ram)
def my_function1(a, b, c):
  #...
  return 'something'

I look inside gluon/cache.py but the caching code seems to not allow
functions with arguments :-/
How to use argument with @cache decorator ?

How to make the cache aware of arguments values ?
It could be usefull to have web2py cache with a pure function cache
behaviour for the models/modules layer.


[web2py] web2py added on PyPy compatibility page

2011-07-07 Thread cjrh
Hi group

I added compatibility details for web2py here (list page):

https://bitbucket.org/pypy/compatibility/wiki/Home

and here (detail page):

https://bitbucket.org/pypy/compatibility/wiki/web2py

I have successfully run web2py on PyPy 1.5, on Windows XP for several days. 
  I have noticed that somewhere, handles are still accumulating and not 
being freed (using the Welcome app).  I am assuming these are file handles. 
 Please, if other contributors can find places where files are opened and 
not explicitly closed, please either report them to me or submit the patch 
yourself.  Note that there are utility functions in gluon/fileutils.py 
called readfile() and writefile() that make it easy to perform those tasks 
with the file handle closing being done for you.

I have recently (though maybe not so recently--several releases ago!) fixed 
a whole bunch of places where file handles were not explicitly being closed, 
and I'll take another crack at it sometime soon.

regards
cjrh  




[web2py] Re: web2py added on PyPy compatibility page

2011-07-07 Thread cjrh
On further examination, it looks like leaking file descriptors is enough to 
mark a library as incompatible (this happened with mercurial), so I have 
changed web2py's to incompatible until we can fix all the leaks.

[web2py] Google App Engine datastor

2011-07-07 Thread stargate
is Google App Engine datastor supported in web2py?


[web2py] Re: web2py hosting

2011-07-07 Thread stargate
For hosting I would use https://www.dotcloud.com/ But only for big
projects.


On Jul 1, 1:17 pm, DenesL denes1...@yahoo.ca wrote:
 Information collected from actual users of the service.
 Comments can belong to several people,
 and can be positive (+), negative (-) or other (~).
 This post will be updated periodically.

 Hosting company: Webfaction
 Type of service: latest
  web2py version:
  Python version: 2.4/3.2
    OS  version: Linux 2.6.18
     Aprox. cost: 8 dollars/month (depends on plan)
    Geo location: USA

 + great control panel, great support, feature rich,
   many auxiliary services available.
 + I am very happy with them.
 - Personally, my experience with webfaction WAS NOT GOOD.
   My web2py websites, often were slow or down.
 - recently changed my 20 web2py apps from webfaction.
 ~ is very nice if you have only one low traffic website.
 + I have a webfaction account with around 3-4 apps at the
   cheapest plan which is really low and it works very well.
   Until now, a great experience with them, almost 2 years.

 Hosting company: vps.net
 Type of service: vps
  web2py version: they provide ubuntu images, I install web2py myself
  Python version: depends on the ubuntu image
    OS  version: ubuntu
     Aprox. cost: $20/month + $5/month for backups
    Geo location: USA + England

 Hosting company: IPage
 Type of service:
  web2py version: web2py (with CGI)
  Python version:
    OS  version:
     Aprox. cost:
    Geo location:

 - very poor technical support, VERY slow, I would not recommend it !

 Hosting company: linode.com
 Type of service:
  web2py version:
  Python version:
    OS  version:
     Aprox. cost: $19 512RAM
    Geo location:

 + In 10 minutes you have a web2py app running on Linode
   with Uwsgi and Nginx, just need to use the script that
   comes with web2py as a stack script on Linode.

 Hosting company: alwaysdata.com
 Type of service: free
  web2py version:
  Python version: 2.6
    OS  version:
     Aprox. cost: 9 euros/mo alwaysdata.com/plans/shared
    Geo location: servers are located in France

 ~ ssh, phpmyadmin

 Other hosting companies from web2py powered sites:

 123-reg.co.uk
 amazonaws.com
 dreamhost.com
 GAE
 gandi.net
 godaddy.com
 jiffybox.de
 prgmr.com
 slicehost.net


[web2py] Re: web2py added on PyPy compatibility page

2011-07-07 Thread cjrh
On Jul 7, 1:27 pm, cjrh caleb.hatti...@gmail.com wrote:
 On further examination, it looks like leaking file descriptors is enough to
 mark a library as incompatible (this happened with mercurial), so I have
 changed web2py's to incompatible until we can fix all the leaks.

I should also point out, to those not familiar with the background, is
that the issue of file descriptors leaking is to some extent a PyPy
issue, not a web2py issue!  cPython automatically closes file handles
when their references go out of scope, which means that in cPython it
is safe to omit closing a file handle explicitly near the end of
functions, or short functions, etc.   cPython can do this because it
uses a reference-counting approach to memory management, whereas PyPy
implements a garbage collector, and requires (apparently) the file
handle to be closed explicitly in order to collect the handle.   This
is one of the published incompatibilities between cPython and PyPy.

So: there are no leaks in web2py running on cPython, this is purely
a compatibility issue with PyPy.


Re: [web2py] Re: web2py added on PyPy compatibility page

2011-07-07 Thread danto
2011/7/7 cjrh caleb.hatti...@gmail.com

 On Jul 7, 1:27 pm, cjrh caleb.hatti...@gmail.com wrote:
  On further examination, it looks like leaking file descriptors is enough
 to
  mark a library as incompatible (this happened with mercurial), so I
 have
  changed web2py's to incompatible until we can fix all the leaks.

 I should also point out, to those not familiar with the background, is
 that the issue of file descriptors leaking is to some extent a PyPy
 issue, not a web2py issue!  cPython automatically closes file handles
 when their references go out of scope, which means that in cPython it
 is safe to omit closing a file handle explicitly near the end of
 functions, or short functions, etc.   cPython can do this because it
 uses a reference-counting approach to memory management, whereas PyPy
 implements a garbage collector, and requires (apparently) the file
 handle to be closed explicitly in order to collect the handle.   This
 is one of the published incompatibilities between cPython and PyPy.

 So: there are no leaks in web2py running on cPython, this is purely
 a compatibility issue with PyPy.


Thank you very much for the info.
Kind regards.


[web2py] Re: A catchall action per controller - would be proposal

2011-07-07 Thread pbreit
The 404 and error functionality works pretty well for that. Are you 
suggesting that something could be done in a clean install of Web2py?

[web2py] Re: A catchall action per controller - would be proposal

2011-07-07 Thread Anthony
Are you suggesting the possibility of defining a function like:
 
def __catchall():
# do stuff
return dict(...)
 
in a controller, and any time a request comes in for a function that doesn't 
exist in the controller, web2py looks for a function called __catchall, and 
if it exists, passes the request to that function (and converts the function 
part of the url to the first argument, so the __catchall function knows what 
to do with the request)?
 
What is the benefit of that over using routes and simply specifying a 
default function (which would then not have to appear in URLs)?
 
Anthony
 

On Thursday, July 7, 2011 3:52:08 AM UTC-4, miguel wrote:

 Yesterday I posted about implementing dynamic actions (functions) in a 
 controller.
 This is interesting because one can achieve clean urls, instead of passing 
 the names of the dynamic pages in args or vars. In a system with a cms this 
 has the benefit of user defined pages being indistinguishable from extant 
 hard-coded actions (if any).

 However, given the static nature of controllers (they are compiled with 
 web2py) this cannot be achieved with closures or metaprogramming. The 
 solution is to use routes to hide a dispatching action. It maybe possible to 
 add to the controller namespace at runtime (but it is beyond my knowledge to 
 explore this).

 This made me think that controllers might allow for the implementation 
 (override?) a single dynamic action that would serve as a catchall for calls 
 to non defined actions. I wonder if there as been any debate on this sort of 
 built-in default action? This would supply a way to dealt with all calls 
 that have no defined action per controller (including errors) without having 
 to use routes. A small idea that perhaps does not bring enough benefits to 
 be argued for. What do you think?

 Miguel



[web2py] Passing JavaScript variable to web2py session variable?

2011-07-07 Thread Vasil Petkov
Hello!

I am having that JavaScript function inside a web2py view:

function submit_form(input_number, input_goal) {
$('input#user_input_number').val(input_number);
$('input#user_input_goal').val(input_goal);
$('form:first').submit();
return false;
}

I would like to assign the value of input_number to the web2py
session.my_var-variable.

As much as i know, to pass input_number to the session.my_var
variable, first an AJAX call must be made. After that, the value of
input_number could be called from web2py request.vars[input_number],
for example.
The end result should look like:

function submit_form(input_number, input_goal) {
$('input#user_input_number').val(input_number);
$('input#user_input_goal').val(input_goal);
THE AJAX CALL
{{session.my_var = request.vars[input_number]}}
$('form:first').submit();
return false;
}

The problem is that i do not know how to make that THE AJAX CALL
from inside the web2py view.

Could you please give me examles of such a JavaScript to Python
variable passing?


[web2py] FORM helper - formstyle='table2cols'

2011-07-07 Thread Jim Steil

Hi

Looking for help with form generation.  I have:

form = FORM(LABEL('Name', _for='permissionName'),
INPUT(_type='text', __name='permissionName',
  _id='permissionName',
  _style=width:150px;, _class='listPanelRow'),
LABEL('Table', _for='tableName'),
INPUT(_type='text', __name='tableName',
  _id='tableName',
   _style=width:150px;, _class='listPanelRow'),
INPUT(_type='submit', _value='Add'),
_id='permissionForm',
formstyle='table2cols')

I want my form to display with the label above the input field.  The 
above code is producing a form with the label ahead of the input field.  
I know that formstyle is supported for SQLFORM, but is it available in 
just the FORM helper as I'm trying to use it here?


Thanks

-Jim




[web2py] can a login_onaccept callback open another view?

2011-07-07 Thread Luis Goncalves
Hello!!

As part of the login process, I need the user to make a choice (select one 
of the multiple versions of the site he has access to, for example), before 
being redirected to whatever  _login_next  is.

Is it possible for a  login_onaccept  callback  to present a  view with a 
form?

My naive approach does not seem to work.  What is the proper way to augment 
the login process with user interaction?

Thanks!!!
Luis.

Here is the barebones code, to illustrate what I am trying to do:

def user_choice(form_login):
  
  form = SQLFORM.factory(
  Field('choices', requires=IS_IN_SET(['a','b','c'])))
  
  if form.accepts( request.vars, session ):
  session.flash='It works!'
  redirect(auth.settings.login_next)
  
  return dict(form=form)

  auth.settings.login_onaccept = user_choice

# views/default/user_choice.html
{{=form}}


[web2py] Re: Passing JavaScript variable to web2py session variable?

2011-07-07 Thread Vasil Petkov
I tried the following:

function submit_form(input_number, input_egn) {
$('input#user_input_number').val(input_number);
$('input#user_input_egn').val(input_egn);
$.ajax({
url: http://127.0.0.1:8000/games/xs-software/vaucher.html;,
method: POST,
data: {input_n: input_number}
});
$('form:first').submit();
return false;
}


[web2py] Re: Google App Engine datastor

2011-07-07 Thread pbreit
I'm not sure what datastor is but GAE is explicitly supported:
http://web2py.com/book/default/chapter/11#Google-App-Engine


[web2py] Re: Passing JavaScript variable to web2py session variable?

2011-07-07 Thread Vasil Petkov
On Jul 7, 9:47 pm, Vasil Petkov petko...@dir.bg wrote:
 I tried the following:

     function submit_form(input_number, input_egn) {
         $('input#user_input_number').val(input_number);
         $('input#user_input_egn').val(input_egn);
         $.ajax({
                 url: http://127.0.0.1:8000/games/xs-software/vaucher.html;,
                 method: POST,
                 data: {input_n: input_number}});

         $('form:first').submit();
         return false;
 }

, but apperantly nothing happened.

PS: sorry for the double post. Was a glitch from my side.


Re: [web2py] Re: replace delete with inactive

2011-07-07 Thread Richard Vézina
Hello,

But how to implement db foreign key constraint at web2py model level??

Thank you.

Richard

On Thu, Nov 18, 2010 at 2:41 PM, mdipierro mdipie...@cs.depaul.edu wrote:

 good point.

 This will work:

if request.post_vars.delete_this_record:
del request.post_vars.delete_this_record
db.t_person.active.update=False

 there are two problems in your example:
 - you are using request.vars and not request.post_vars which crud uses
 and therefore the variable is not deleted
 - web2py actually deletes the record but that breaks the references,
 the db raises an exception, web2py catches it and rollsback, so the
 record is still there.

 Massimo

 On Nov 18, 1:14 pm, Carlos carlosgali...@gmail.com wrote:
  Hi,
 
  I'm trying to replace the built-in delete behavior in crud.update
  (deletable=True) with a boolean active field instead, in order to NOT
  do a hard-delete of any records but instead a soft-delete via the
  active flag.
 
  I'm also using onaccept=crud.archive.
 
  I successfully manage to cancel the delete operation (currently in all
  cases for testing purposes) via the following just before the
  crud.update:
 
 if request.vars: del request.vars.delete_this_record
 
  But when the crud.update is executed (with crud.archive) and the
  delete checkbox is on, I get the following error:
 
  class 'psycopg2.IntegrityError'(insert or update on table
  entity_archive violates foreign key constraint
  entity_archive_current_record_fkey
  DETAIL:  Key (current_record)=(6) is not present in table entity.)
 
  Note that the record is NOT deleted (as expected), and therefore I
  don't understand why crud.archive is complaining about it.
 
  Also note that crud.update (with crud.archive) works ok when the
  delete checkbox is off.
 
  I've checked request.vars and I don't see any problems.
 
  Can you please help?.
 
  Thanks,
 
 Carlos



Re: [web2py] FORM helper - formstyle='table2cols'

2011-07-07 Thread Richard Vézina
try formstyle='divs'

Then if still not above you can make it above by css and the appropriate div
class of id... Look at you generate html view source file. Ctrl+U in most
nav

;-)

Richard

On Thu, Jul 7, 2011 at 2:09 PM, Jim Steil j...@qlf.com wrote:

  Hi

 Looking for help with form generation.  I have:

 form = FORM(LABEL('Name', _for='permissionName'),
 INPUT(_type='text', __name='permissionName',
   _id='permissionName',
   _style=width:150px;, _class='listPanelRow'),
 LABEL('Table', _for='tableName'),
 INPUT(_type='text', __name='tableName',
   _id='tableName',
_style=width:150px;, _class='listPanelRow'),
 INPUT(_type='submit', _value='Add'),
 _id='permissionForm',
 formstyle='table2cols')

 I want my form to display with the label above the input field.  The above
 code is producing a form with the label ahead of the input field.  I know
 that formstyle is supported for SQLFORM, but is it available in just the
 FORM helper as I'm trying to use it here?

 Thanks

 -Jim





[web2py] how to enforce foreign key constraint at w2p model level

2011-07-07 Thread Richard Vézina
Hello,

I would like to avoid this traceback :


IntegrityError: ERREUR:  UPDATE ou DELETE sur la table « ref_fnaregistry »
viole la contrainte de clé étrangère
« fnaregistry_id » de la table « ref_vregistry »
DETAIL:  La clé (fnaregistry_id)=(1) est toujours référencée à partir de la
table « ref_vregistry ».

ERROR SNAPSHOT
class 'psycopg2.IntegrityError'(ERREUR:  UPDATE ou DELETE sur la table «
ref_fnaregistry » viole la contrainte de clé étrangère
« fnaregistry_id » de la table « ref_vregistry »
DETAIL:  La clé (fnaregistry_id)=(1) est toujours référencée à partir de la
table « ref_vregistry ».


Sorry for the french traceback ;-)

How to tell web2py that a record can't be delete cause it is referenced by
an other record in an other tables...

Do I have to write a proper function to manage that scenario or there is a
way to add delete validator or something to the model??

If there is no deletion validators at all, it could be a GREAT new feature
;-)

Thank you

Richard


[web2py] Script to deploy Python in Linux (CentOS)

2011-07-07 Thread Alfonso de la Guarda
Hello,

I have published under a free license, some scripts that let you install
python, mongoand nginx on CentOS.
Nginx configurations apply load balancing to Tornado (but can set it to
uwsgi or any other).
Supervisor is also added to manage the services installed.

You can review the project, which is in production, here:

https://bitbucket.org/alfonsodg/python-deploy/


Saludos,


Alfonso de la Guarda
Centro Open Source(COS)
http://www.cos-la.net
http://alfonsodg.net
   Telef. 991935157
1024D/B23B24A4
5469 ED92 75A3 BBDB FD6B  58A5 54A1 851D B23B 24A4


[web2py] Re: found it

2011-07-07 Thread JorgeH
cool ;)
Now,  in the future, consider using more appropriate and specific titles for 
your posts.


Re: [web2py] Re: web2py added on PyPy compatibility page

2011-07-07 Thread Richard Vézina
Does it speed up web2py?

Richard

On Thu, Jul 7, 2011 at 11:28 AM, danto web2py.n...@gmail.com wrote:

 2011/7/7 cjrh caleb.hatti...@gmail.com

 On Jul 7, 1:27 pm, cjrh caleb.hatti...@gmail.com wrote:
  On further examination, it looks like leaking file descriptors is enough
 to
  mark a library as incompatible (this happened with mercurial), so I
 have
  changed web2py's to incompatible until we can fix all the leaks.

 I should also point out, to those not familiar with the background, is
 that the issue of file descriptors leaking is to some extent a PyPy
 issue, not a web2py issue!  cPython automatically closes file handles
 when their references go out of scope, which means that in cPython it
 is safe to omit closing a file handle explicitly near the end of
 functions, or short functions, etc.   cPython can do this because it
 uses a reference-counting approach to memory management, whereas PyPy
 implements a garbage collector, and requires (apparently) the file
 handle to be closed explicitly in order to collect the handle.   This
 is one of the published incompatibilities between cPython and PyPy.

 So: there are no leaks in web2py running on cPython, this is purely
 a compatibility issue with PyPy.


 Thank you very much for the info.
 Kind regards.



[web2py] Re: FORM helper - formstyle='table2cols'

2011-07-07 Thread Anthony
No, formstyle is not an option with the FORM helper. The FORM helper simply 
generates the opening and closing form tags:
 
 print FORM()
form action= enctype=multipart/form-data method=post/form
 
 
If you want to use the FORM helper, you'll have to figure out the 
appropriate HTML/CSS to generate the layout you want within the form tags. 
To see how SQLFORM generates table-based forms, you can look at the source 
code:

   - Individual field input widgets and labels are generated in this for 
   loop of the __init__ method: 
   http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#727 
   - The field widgets are then inserted into a table, divs, or unordered 
   list (depending on the formstyle chosen) in the createform() method: 
   http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#904

Anthony

On Thursday, July 7, 2011 2:09:30 PM UTC-4, Jim S wrote:

 Hi

 Looking for help with form generation.  I have:

 form = FORM(LABEL('Name', _for='permissionName'),
 INPUT(_type='text', __name='permissionName',
   _id='permissionName', 
   _style=width:150px;, _class='listPanelRow'),
 LABEL('Table', _for='tableName'),
 INPUT(_type='text', __name='tableName', 
   _id='tableName',
_style=width:150px;, _class='listPanelRow'),
 INPUT(_type='submit', _value='Add'),
 _id='permissionForm',
 formstyle='table2cols')

 I want my form to display with the label above the input field.  The above 
 code is producing a form with the label ahead of the input field.  I know 
 that formstyle is supported for SQLFORM, but is it available in just the 
 FORM helper as I'm trying to use it here?

 Thanks

 -Jim




[web2py] Re: FORM helper - formstyle='table2cols'

2011-07-07 Thread Anthony
Also, if you want to take advantage of the SQLFORM functionality, but your 
form is not based on a database table, you can use SQLFORM.factory. See 
http://web2py.com/book/default/chapter/07#SQLFORM.factory.
 
Anthony

On Thursday, July 7, 2011 3:27:51 PM UTC-4, Anthony wrote:

 No, formstyle is not an option with the FORM helper. The FORM helper simply 
 generates the opening and closing form tags:
  
  print FORM()
 form action= enctype=multipart/form-data method=post/form
  
  
 If you want to use the FORM helper, you'll have to figure out the 
 appropriate HTML/CSS to generate the layout you want within the form tags. 
 To see how SQLFORM generates table-based forms, you can look at the source 
 code:

- Individual field input widgets and labels are generated in this for 
loop of the __init__ method: 
http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#727 
- The field widgets are then inserted into a table, divs, or unordered 
list (depending on the formstyle chosen) in the createform() method: 
http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#904

 Anthony

 On Thursday, July 7, 2011 2:09:30 PM UTC-4, Jim S wrote:

 Hi

 Looking for help with form generation.  I have:

 form = FORM(LABEL('Name', _for='permissionName'),
 INPUT(_type='text', __name='permissionName',
   _id='permissionName', 
   _style=width:150px;, _class='listPanelRow'),
 LABEL('Table', _for='tableName'),
 INPUT(_type='text', __name='tableName', 
   _id='tableName',
_style=width:150px;, _class='listPanelRow'),
 INPUT(_type='submit', _value='Add'),
 _id='permissionForm',
 formstyle='table2cols')

 I want my form to display with the label above the input field.  The above 
 code is producing a form with the label ahead of the input field.  I know 
 that formstyle is supported for SQLFORM, but is it available in just the 
 FORM helper as I'm trying to use it here?

 Thanks

 -Jim




[web2py] confused on routes.py

2011-07-07 Thread kasapo
Hi,

So I think I might not really understand routes.py.

Here is my problem: my web2py app is run at a url like:
http://host.domain.tld/meetings/2011/MYAPP

But, there is a proxypass rule for /meetings/2011/MYAPP to go to
localhost:8180/MYAPP (which is what web2py is running on)

So, I think I need to make routes_out prepend /meetings/2011/ to all
generated URLs, so I do this:

(file: routes.py)

routes_out = (
  ('/MYAPP/(.*)', '/meetings/2011/$1')
)

But nothing happens. Also, I'm not sure if I need to mess with
routes_in when I do this? I don't think I should since apache is
proxying all requests directly to web2py with the appname hardcoded.

Lastly, I can't seem to do ANYTHING with routes. I've tried:

routes_in (
 (.*, /nothing)
)
routes_out (
 (.*, /nothing)
)

And the URL behavior does not change at all. What am I missing?

PS: I am restarting the web2py rocket webserver, but I see no reason
to restart the apache server, though I have anyway.

Thanks in advance for any assistance.


[web2py] Re: Integrity error with IS_NOT_IN_DB [Solved]

2011-07-07 Thread Lenkaster
In the following link(1) bellow, Massimo explains how validation
mechanism works:

   db.table.field2.requires=IS_NOT_IN_DB(db
 (db.table.field1==request.vars.field1),db.table.field2)

[1]
http://groups.google.com/group/web2py/browse_thread/thread/e5ddcfc6ca019568/a143eb919c92735b?lnk=gstq=unique+multiple+columns#a143eb919c92735b

I didn't noticed that the correct field to validate is n4
  db.account_attributes.n4requires=IS_IN_DB(
      db, 'account_attributes.account_attribute', '%(n4)s'
      )
Instead account_attribute field:
  db.account_attributes.account_attribbute(
      db, 'account_attributes.account_attribute', '%(n4)s'
      )

After edit this part of code, the validation of form level worked
correctly.

It would be good in Web2py book an exemple that shows a case to
validate uniqueness constraint of multiple fields.
[2] http://www.web2py.com/book/default/chapter/07#Database-Validators

Until to the next challenge! ;-)

Greetings.

Lenkaster

On 26 maio, 16:27, Lenkaster lenkast...@gmail.com wrote:
 Hi,

 I have some problems to validate in the form layer when a table has
 uniqueness constraint with more than one column. The exemple following
 explains the problem.

 I have a table where I need to store accounting numbers. Ex.:

 +==+==+==+==+
 |N1 |N2  |N3 |N4  |
 +==+==+==+==+
 |1    |2    |3   |40  |
 |1    |2    |3   |41  |
 

 In the model
 --
 (with postgres or mysql)

   ::
   db.define_table(
       'account_attributes',
       Field('n1', length=10, required=True, notnull=True),
       Field('n2', length=30, required=True, notnull=True),
       Field('n3', length=40, required=True, notnull=True),
       Field('n4', length=100, required=True, notnull=True),
       Field(
           'account_attribute',
           length=255,
           notnull=True,
           unique=True,
           readable=False,
           writable=False,
           compute=lambda r: ('%s.%s.%s.%s' % (r.n1, r.n2, r.n3,
 r.n4)).upper(),
           ),
       format=%(account_attribute)s,
       )

 Validations in the form layer are:

   ::
   db.account_attributes.n1.requires=IS_NOT_EMPTY()
   db.account_attributes.n2.requires=IS_NOT_EMPTY()
   db.account_attributes.n3.requires=IS_NOT_EMPTY()
   db.account_attributes.n4.requires=IS_NOT_EMPTY()

   db.account_attributes.account_attribute.requires=IS_IN_DB(
       db, 'account_attributes.account_attribute', '%(n4)s'
       )

 In controller and view I use the Crud way, but if I try to insert the
 same values without use  admin interface,  the application is broken
 with database error:

   ::
   IntegrityError:
   ERRO:  duplicar valor da chave viola a restrição de unicidade
 account_attributes_account_attribute_key
   DETAIL:  Chave (account_attribute)=(1.2.3.40) já existe.

 Web2Py book shows how to validate single column, and in this forum I
 see solutions to validate with a column that computes the values of
 other four columns as above mentioned.

 I try too validates this way:

   ::
   account_attribute_form='.'.join(
       [request.vars.n1, request.vars.n2, request.vars.n3,
 request.vars.n4]
       ).upper()
   db.account_attributes.account_attribute.requires=[
       IS_NOT_EMPTY(),
       IS_NOT_IN_DB(

 db(db.account_attributes.account_attribute==account_attribute_form),
           db.account_attributes.account_attribute
           )
       ]

 Source consulted:
 -http://www.web2py.com/book/default/chapter/07#Database-Validators

 -http://groups.google.com/group/web2py/browse_thread/thread/caaf68de3f...

 -http://groups.google.com/group/web2py/browse_thread/thread/e5ddcfc6ca...

 Obs:
 In this case it is important to keep uniqueness constraint in database
 layer. So I would like see your sugestions and opinions about that,
 and where is my mistake?

 GreetingsLenkaster


Re: [web2py] FORM helper - formstyle='table2cols'

2011-07-07 Thread Jim Steil

Richard

Thanks for the tip.  I've switched to using SQLFORM with no data updates 
for my purpose now and it is much closer to what I want.  Only problem 
now is that the input field lengths are getting set to 280px and I can't 
find how to override them.  I'm just trying a bunch of different things 
now to see if I can control it.  More tips always welcome


Thanks again.

-Jim

On 7/7/2011 1:59 PM, Richard Vézina wrote:

try formstyle='divs'

Then if still not above you can make it above by css and the 
appropriate div class of id... Look at you generate html view source 
file. Ctrl+U in most nav


;-)

Richard

On Thu, Jul 7, 2011 at 2:09 PM, Jim Steil j...@qlf.com 
mailto:j...@qlf.com wrote:


Hi

Looking for help with form generation.  I have:

form = FORM(LABEL('Name', _for='permissionName'),
INPUT(_type='text', __name='permissionName',
  _id='permissionName',
  _style=width:150px;, _class='listPanelRow'),
LABEL('Table', _for='tableName'),
INPUT(_type='text', __name='tableName',
  _id='tableName',
   _style=width:150px;, _class='listPanelRow'),
INPUT(_type='submit', _value='Add'),
_id='permissionForm',
formstyle='table2cols')

I want my form to display with the label above the input field. 
The above code is producing a form with the label ahead of the

input field.  I know that formstyle is supported for SQLFORM, but
is it available in just the FORM helper as I'm trying to use it here?

Thanks

-Jim





Re: [web2py] FORM helper - formstyle='table2cols'

2011-07-07 Thread Anthony
On Thursday, July 7, 2011 3:46:10 PM UTC-4, Jim S wrote: 

  Only problem now is that the input field lengths are getting set to 280px 
 and I can't find how to override them.

 
I think that's set in the /static/css/base.css file:
 
input[type=text], input[type=password], textarea, select {
margin: 2px 15px 2px 5px;
width: 280px;  
background: #fff;
color: #555;
border: 1px solid #dedede; 
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;   
font-size: 12px;
}
 
Also, see http://web2py.com/book/default/chapter/07#CSS-Conventions for 
details on css-based customization.
 
Anthony
 


Re: [web2py] Re: FORM helper - formstyle='table2cols'

2011-07-07 Thread Jim Steil
Thanks for all the advice.  SQLFORM has a lot little things built in 
that make it more attractive than just a form.  I modified what I needed 
and now having it working with a little css in the component .load 
file.  Thanks again, still playing with it but I think everything I need 
is there.


-Jim

On 7/7/2011 2:30 PM, Anthony wrote:
Also, if you want to take advantage of the SQLFORM functionality, but 
your form is not based on a database table, you can use 
SQLFORM.factory. See 
http://web2py.com/book/default/chapter/07#SQLFORM.factory.

Anthony

On Thursday, July 7, 2011 3:27:51 PM UTC-4, Anthony wrote:

No, formstyle is not an option with the FORM helper. The FORM
helper simply generates the opening and closing form tags:
 print FORM()
form action= enctype=multipart/form-data method=post/form
If you want to use the FORM helper, you'll have to figure out the
appropriate HTML/CSS to generate the layout you want within the
form tags. To see how SQLFORM generates table-based forms, you can
look at the source code:

  * Individual field input widgets and labels are generated in
this for loop of the __init__ method:
http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#727
http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#727
  * The field widgets are then inserted into a table, divs,
or unordered list (depending on the formstyle chosen) in the
createform() method:
http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#904
http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#904

Anthony

On Thursday, July 7, 2011 2:09:30 PM UTC-4, Jim S wrote:

Hi

Looking for help with form generation.  I have:

form = FORM(LABEL('Name', _for='permissionName'),
INPUT(_type='text', __name='permissionName',
  _id='permissionName',
  _style=width:150px;,
_class='listPanelRow'),
LABEL('Table', _for='tableName'),
INPUT(_type='text', __name='tableName',
  _id='tableName',
   _style=width:150px;,
_class='listPanelRow'),
INPUT(_type='submit', _value='Add'),
_id='permissionForm',
formstyle='table2cols')

I want my form to display with the label above the input
field.  The above code is producing a form with the label
ahead of the input field.  I know that formstyle is supported
for SQLFORM, but is it available in just the FORM helper as
I'm trying to use it here?

Thanks

-Jim




Re: [web2py] Re: web2py added on PyPy compatibility page

2011-07-07 Thread cjrh
That is a complicated question:

1) Single page load: no.  This is generally an IO-bound kind of system, e.g. 
an infinitely fast processor would have almost no effect on response time.

2) Concurrency/Scaling: generally, no.  This is dominated by the DB backend, 
and (generally) the speed at which the DB can serve concurrent queries 
becomes limiting well before cPython gets too slow.

3) Any code that gets execed by python: no.  AFAIK PyPy doesn't do 
anything to exec() code, and that pretty much means your whole app. (I had a 
look---I can't find this mentioned anywhere, but I seem to have this idea 
stuck in my head from somewhere.  Perhaps it was a limitation of an earlier 
PyPy version and no longer applies?)

What remains is the internal stuff, such as markmin, templating and other 
gluon/* code (and rocket!).  So the final answer is a tentative no, PyPy 
probably won't have too much impact on performance for web2py.  So why 
bother?  Because PyPy is the future of Python.


[web2py] Re: OffTopic Google+

2011-07-07 Thread cjrh
If you've submitted a patch, then you're no lurker, you're part of the 
team...

[web2py] How to display 'complete strings' in a view table ?

2011-07-07 Thread Valter Foresto
I use the view :
   {{extend 'layout.html'}}
   {{=records}}
to display a records table.
One field in the record report the date and time :
*logs.event_time_stamp*
2011-07-07 23...
but the date and time is 2011-07-07 23... instead of  the complete 
2011-07-07 23:01:15 string.

What can I do to have the complete string displayed on the view table ?


[web2py] Re: How to display 'complete strings' in a view table ?

2011-07-07 Thread Anthony
Rows objects are rendered via the SQLTABLE helper (see 
http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#1229). It 
takes a 'truncate' argument that defaults to 16 (i.e., it truncates text at 
16 characters). Try:
 
{{=SQLTABLE(records, truncate=xx)}}
 
where xx is 19 or greater in your case (to accommodate a date-time string). 
I think you can also set truncate=None to avoid truncation altogether.
 
Anthony

On Thursday, July 7, 2011 5:39:36 PM UTC-4, Valter Foresto wrote:

 I use the view :
{{extend 'layout.html'}}
{{=records}}
 to display a records table.
 One field in the record report the date and time :
 *logs.event_time_stamp*
 2011-07-07 23...
 but the date and time is 2011-07-07 23... instead of  the complete 
 2011-07-07 23:01:15 string.

 What can I do to have the complete string displayed on the view table ?



[web2py] Re: Temporary changing default values of a Form

2011-07-07 Thread Massimo Di Pierro
Please open a ticket in google code. If this is a web2py but will fix
asap.

On Jul 6, 11:24 pm, Luis Goncalves lgoncal...@gmail.com wrote:
 In fact, just to make sure there wasn't something hidden in my app affecting
 the behavior,
 I downloaded a fresh install of web2py,

 and get the same error:

   File /home/pierluigi/web2py/gluon/tools.py, line 1796, in register

     user = self.db(table_user[username] == 
 form.vars[username]).select().first()
 KeyError: 'email'

 Adding just this code to the 'welcome' app:

  def user():
       if request.args(0)=='register':

           auth.settings.table_user.email.default = 'l...@vision.caltech.edu'

           auth.settings.table_user.email.writable=False

           auth.settings.registration_requires_verification = False

       return dict(form=auth())

 L.







 On Wed, Jul 6, 2011 at 8:35 PM, Luis Goncalves lgoncal...@gmail.com wrote:
  Yes, when I click on the invite and go to the website I get the
  registration form filled out with email (and name (excluded from my
  shortened example)) visible and non-editable.

  Luis.

  —«sent by mobile»—
  On Jul 6, 2011 8:17 PM, Massimo Di Pierro massimo.dipie...@gmail.com
  wrote:
   Are you sure your db.registrant has an email?

   On Jul 6, 10:04 pm, Luis Goncalves lgoncal...@gmail.com wrote:
   I still get the same error:

     File /home/ubuntu/web2py/gluon/tools.py, line 1683, in register
       user = self.db(table_user[username] ==
  form.vars[username]).select().first()
   KeyError: 'email'

   I don't know if it makes a difference or not, but I'm using emails for
  login
   (not a username) -- as is probably clear to you from the above error.

   Code is now:

     def user():

         if request.args(0)=='register':

             registrant = db( db.registrant.token == request.vars.token
   ).select().first()

             auth.settings.table_user.email.default = registrant.email
             auth.settings.table_user.email.writable=False

             auth.settings.registration_requires_verification = False

         return dict(form=auth())


[web2py] Re: Metaprogramming in controller

2011-07-07 Thread Massimo Di Pierro
yes. even better use router (vs routes)

On Jul 6, 10:03 am, Miguel Lopes mig.e.lo...@gmail.com wrote:
 Humm,

 Nice. Yes, closures are enough, and cleaner too.
 Is routes OK for production mode?
 Txs,
 Miguel

 On Wed, Jul 6, 2011 at 3:54 PM, Massimo Di Pierro 







 massimo.dipie...@gmail.com wrote:
  Jonathan is right. Here is a simple way around.

  Create a single controller called dynamical. use request.args(0) to
  parse the name of one of the dynamical actions and remap

  def dynamical():
      actionname, request.args[:] = request.args(0), request.args[1:]
      # call actionname and pass request.args and request.vars

  use routes to remove the 'dynamical/' part form the URL.

  This allows you to do what you want without necessarily meta-
  programming.

  On Jul 6, 9:35 am, Miguel Lopes mig.e.lo...@gmail.com wrote:
   Thanks. In conjunction with routes could supply a solution (shortening
  the
   urls).
   I think I should rethink the payoff (see my reply to Massimo regarding my
   goals).
   Thanks,
   Miguel

   On Wed, Jul 6, 2011 at 3:12 PM, Jonathan Lundell jlund...@pobox.com
  wrote:
On Jul 6, 2011, at 1:23 AM, Miguel Lopes wrote:

I'm experimenting with dynamically generating functions, aka 'actions'
  in
controllers. However, I've been unsuccessful. I can use exec and
  closures
successfully in regular Python code, but I can't make it work with
  web2py.
Any thoughts on how to achieve this?

web2py finds functions by reading the (static) controller file itself.
  See
gluon.compileapp.run_controller_in, in particular this line:

        exposed = regex_expose.findall(code)

So, no dynamically generated controller actions, at least not directly.

I haven't given this much thought, but one way you might accomplish the
same effect would be to push the dynamic function name down one level
  in the
URL, something like:http://domain.com/app/dynamic/index/function/...

...where 'dynamic' is the controller with dynamic functions, and index
  is a
(static) function that calls function dynamically. You might optimize
  the
lookup function to extract only the one desired function from your page
table.

Depending on your overall URL structure, you could rewrite the URLs to
shorten them up.

A closure example - FAILS in web2py:
top_pages = db(db.page.id  0).select()
def add_actions(top_pages):
    for page in top_pages:
        def inneraction(msg):
            sidebar = None
            return dict(message=msg, sidebar=sidebar)
        inneraction.__name__ = page.link_name
        globals()[page.link_name] = inneraction

add_actions(top_pages)

A exec example - FAILS in web2py:

ACTION_TEMPLATE = 
 def NEW_ACTION():
    sidebar = None
    return dict(message='s', sidebar=sidebar)
 
top_pages = db(db.page.id  0).select()
def makePages(pages):
    for page in top_pages:
        exec ACTION_TEMPLATE
        NEW_ACTION.__name__ = page.link_name
        globals()[page.link_name] = NEW_ACTION

makePages(pages)

Miguel


[web2py] Re: Google App Engine datastor

2011-07-07 Thread Massimo Di Pierro
datastor[e] is supported.

On Jul 7, 8:40 am, stargate kyoukh...@gmail.com wrote:
 is Google App Engine datastor supported in web2py?


Re: [web2py] Re: Temporary changing default values of a Form

2011-07-07 Thread Luis Goncalves
Done!

Thank you!!!

Luis.

On Thu, Jul 7, 2011 at 6:24 PM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 Please open a ticket in google code. If this is a web2py but will fix
 asap.

 On Jul 6, 11:24 pm, Luis Goncalves lgoncal...@gmail.com wrote:
  In fact, just to make sure there wasn't something hidden in my app
 affecting
  the behavior,
  I downloaded a fresh install of web2py,
 
  and get the same error:
 
File /home/pierluigi/web2py/gluon/tools.py, line 1796, in register
 
  user = self.db(table_user[username] ==
 form.vars[username]).select().first()
  KeyError: 'email'
 
  Adding just this code to the 'welcome' app:
 
   def user():
if request.args(0)=='register':
 
auth.settings.table_user.email.default = '
 l...@vision.caltech.edu'
 
auth.settings.table_user.email.writable=False
 
auth.settings.registration_requires_verification = False
 
return dict(form=auth())
 
  L.
 
 
 
 
 
 
 
  On Wed, Jul 6, 2011 at 8:35 PM, Luis Goncalves lgoncal...@gmail.com
 wrote:
   Yes, when I click on the invite and go to the website I get the
   registration form filled out with email (and name (excluded from my
   shortened example)) visible and non-editable.
 
   Luis.
 
   —«sent by mobile»—
   On Jul 6, 2011 8:17 PM, Massimo Di Pierro 
 massimo.dipie...@gmail.com
   wrote:
Are you sure your db.registrant has an email?
 
On Jul 6, 10:04 pm, Luis Goncalves lgoncal...@gmail.com wrote:
I still get the same error:
 
  File /home/ubuntu/web2py/gluon/tools.py, line 1683, in register
user = self.db(table_user[username] ==
   form.vars[username]).select().first()
KeyError: 'email'
 
I don't know if it makes a difference or not, but I'm using emails
 for
   login
(not a username) -- as is probably clear to you from the above
 error.
 
Code is now:
 
  def user():
 
  if request.args(0)=='register':
 
  registrant = db( db.registrant.token == request.vars.token
).select().first()
 
  auth.settings.table_user.email.default = registrant.email
  auth.settings.table_user.email.writable=False
 
  auth.settings.registration_requires_verification = False
 
  return dict(form=auth())



[web2py] Re: headers argument behavior in v1.97.1

2011-07-07 Thread niknok
Thanks for looking.

Code runs without errors in v1.96.1 but throws an error on 1.97.1.
Here's the traceback:

Traceback (most recent call last):
  File /home/rwn/Projects/web2py/gluon/restricted.py, line 192, in
restricted
exec ccode in environment
  File /home/rwn/Projects/web2py/applications/bbc/controllers/
donor.py, line 418, in module
  File /home/rwn/Projects/web2py/gluon/globals.py, line 137, in
lambda
self._caller = lambda f: f()
  File /home/rwn/Projects/web2py/gluon/tools.py, line 2415, in f
return action(*a, **b)
  File /home/rwn/Projects/web2py/applications/bbc/controllers/
donor.py, line 62, in address
,'address.country':'Country'})
  File /home/rwn/Projects/web2py/gluon/tools.py, line 3225, in
select
return SQLTABLE(rows,headers=headers,**attr)
  File /home/rwn/Projects/web2py/gluon/sqlhtml.py, line 1453, in
__init__
if isinstance(headers[colname],dict):
KeyError: 'address.line_3'

In prior versions, web2py will not complain about missing label and
just use the field name (or label in table definition) instead. I
suppose this new behavior is the right way of doing it and I should
just adjust the code accordingly, but IMO the old behavior handles the
issue more elegantly.


On Jul 7, 3:11 pm, Bruno Rocha rochacbr...@gmail.com wrote:
 Can you share some example app or model + controller code t reproduce the
 bug.

 Do you have a Traceback ticket error? what message, what file/line?

 The erro occurs when running the mentioned controller, or qhen doing some
 other action on this?

 Need more onfo to help tracking this issue.

 []'s









 On Thu, Jul 7, 2011 at 2:50 AM, niknok nikolai...@gmail.com wrote:
  **
  While using crud, I sometimes define headers for *some* fields listed in
  the fields argument. This works until I upgraded to 1.97.1 and now I get an
  error if I do not define the headers for *all* fields listed in the fields
  argument.

  For example, the following code no longer works

  rows=crud.select(db.address
                      ,query=((db.address.owner_is==address_owner)
                              
  (db.address.owner_is_person==address_owner_is_person))
                      ,fields=['address.id'
                                  ,'address.line_1'
                                  ,'address.is_type'
                                  ,'address.country']
                      ,headers={'address.id':'#'
                                  ,'address.line_1':'Street address'
                                  ,'address.country':'Country'})

  until I add a header for address.is_type, too.

  Is this a bug or a new feature?

 --

 --
 Bruno Rocha
 [ About me:http://zerp.ly/rochacbruno]
 [ Aprenda a programar:http://CursoDePython.com.br]
 [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
 [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] Re: headers argument behavior in v1.97.1

2011-07-07 Thread niknok
Nope, I'm not using trunk.

And yes, now I know that I have do define *all* the headers while in
the old versions, that isn't a requirement. I guess it's part of being
explicit..

On Jul 7, 6:36 pm, Martín Mulone mulone.mar...@gmail.com wrote:
 Did you use trunk version?, I submitted recently some changes there.-

 2011/7/7 Bruno Rocha rochacbr...@gmail.com









  Can you share some example app or model + controller code t reproduce the
  bug.

  Do you have a Traceback ticket error? what message, what file/line?

  The erro occurs when running the mentioned controller, or qhen doing some
  other action on this?

  Need more onfo to help tracking this issue.

  []'s

  On Thu, Jul 7, 2011 at 2:50 AM, niknok nikolai...@gmail.com wrote:

  **
  While using crud, I sometimes define headers for *some* fields listed in
  the fields argument. This works until I upgraded to 1.97.1 and now I get an
  error if I do not define the headers for *all* fields listed in the fields
  argument.

  For example, the following code no longer works

  rows=crud.select(db.address
                      ,query=((db.address.owner_is==address_owner)
                              
  (db.address.owner_is_person==address_owner_is_person))
                      ,fields=['address.id'
                                  ,'address.line_1'
                                  ,'address.is_type'
                                  ,'address.country']
                      ,headers={'address.id':'#'
                                  ,'address.line_1':'Street address'
                                  ,'address.country':'Country'})

  until I add a header for address.is_type, too.

  Is this a bug or a new feature?

  --

  --
  Bruno Rocha
  [ About me:http://zerp.ly/rochacbruno]
  [ Aprenda a programar:http://CursoDePython.com.br]
  [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
  [ Consultoria em desenvolvimento web:http://www.blouweb.com]

 --
  http://martin.tecnodoc.com.ar


[web2py] ww response.files.append(URL('static','css/menu.css'))

2011-07-07 Thread tazjel

On 02/17/2011 01:13 AM, Ahmed Bani wrote:



  Problem solved:


  {{ # (CSS) -) import random
  response.files.append(URL('static','css/menu.css'))
  response.files.append(URL('static','css/home.css')) #
  (JavaScript) ---
  response.files.append(URL('static','js/ajquery.scrollTo-min.js')) 
response.files.append(URL('static','js/bjquery.localscroll-1.2.7-min.js'))
  response.files.append(URL('static','js/zexamples.scroll.js'))
  #-- include web2py specific js code (jquery, calendar, form
  stuff) -- }} {{include 'web2py_ajax.html'}}
  {{=toggle_menuclass()}}

  {{=response.flash or ''}}

  /web2py Enterprise web framework/
  %7B%7B=URL%28%27default%27,%27index%27%29%7D%7D
  /{{=T('Home')}}/
  %7B%7B=URL%28%27default%27,%27index%27%29%7D%7D
  /{{=T('About')}}/
  %7B%7B=URL%28%27default%27,%27what%27%29%7D%7D
  /{{=T('Download')}}/
  %7B%7B=URL%28%27default%27,%27download%27%29%7D%7D
  /{{=T('Staff')}}/
  %7B%7B=URL%28%27default%27,%27who%27%29%7D%7D
  /{{=T('Support')}}/
  %7B%7B=URL%28%27default%27,%27support%27%29%7D%7D
  /{{=T('Documentation')}}/
  %7B%7B=URL%28%27default%27,%27documentation%27%29%7D%7D
  {{include}} {{block sidebar}}
  {{=T('Download')}} {{=T('Latest Stable
  ')}}{{=request.env.web2py_version[:15]}}
  %7B%7B=URL%28%27default%27,%27download%27%29%7D%7D
  {{=T('User groups')}}
  %7B%7B=URL%28%27default%27,%27usergroups%27%29%7D%7D
  {{=T('User Voice')}} http://web2py.uservoice.com/
  Twitter http://twitter.com/web2py
  {{=T('Live Chat (IRC)')}}
  http://webchat.freenode.net/?channels=web2py
  {{=T('F.A.Q.')}} http://www.web2py.com/AlterEgo
  {{=T('Quick Examples')}}
  %7B%7B=URL%28%27default%27,%27examples%27%29%7D%7D
  {{=T('Videos')}} %7B%7B=URL%28%27default%27,%27videos%27%29%7D%7D
  web2py Slices http://www.web2pyslices.com/main/default/index
  {{=T('Interactive demo')}} http://www.web2py.com/demo_admin
  {{=T('Free appliances')}} http://www.web2py.com/appliances
  {{=T('Plugins')}} http://www.web2py.com/plugins
  {{end}}
  © 2010 by Massimo Di Pierro
  # Download : hg clone https://web2py.googlecode.com/hg/ web2py

# Follow the instructions:


  Title : Using psycopg2 with virtualenv on Ubuntu

Link: 
http://www.saltycrane.com/blog/2009/07/using-psycopg2-virtualenv-ubuntu-jaunty/


Check your syntax :
# /db/ = /DAL/('/postgres/://myself:mypass@127.0.0.1:5432/mydatabase')

Enjoy it!
Follow the instructions:
Now, do we have to migrate web2py database and reimport it again? :


  Short tutorial to migrate web2py database - model and data
  
http://alexandremas.blogspot.com/2009/11/short-tutorial-to-migrate-web2py.html






{{
###
# response._vars contains the dictionary returned by the controller action
###
try:
   from gluon.serializers import json
   response.write(json(response._vars),escape=False)
   response.headers['Content-Type']='text/json'
except:
   raise HTTP(405,'no json')
}}
 text/html; name="appadmin.html": Unrecognized 
{{extend 'layout.html'}}
{{"""

You should not modify this file. 
It is used as default when a view is not provided for your controllers

"""}}

{{=BEAUTIFY(response._vars)}}

admin
request
request{{=BEAUTIFY(request)}}
session
session{{=BEAUTIFY(session)}}
response
response{{=BEAUTIFY(response)}}


{{block sidebar}}{{end}}
{{response.headers['web2py-response-flash']=response.flash}}{{if 
len(response._vars)==1:}}{{=response._vars.values()[0]}}{{else:}}{{=BEAUTIFY(response._vars)}}{{pass}}