[web2py] Re: how to cleanse field value

2014-04-18 Thread aleonserra
This is a very important question that i would like to complement. You can use a single custom validator for any kind of parse you want to perform on any particular field, like this. class process_field(): def __init__(self, func): self.func = func def __call__(self, value):

[web2py] preprocess SQLFORM fields before submission

2014-04-18 Thread aleonserra
Hello. Im trying to preprocess SQLFORM fields before they are saved into the database, for example given a table like the model: db.define_table("people", Field('first_name', 'string'), Field('last_name', 'string') ) I want to capitalize first and last name before they are saved into the

[web2py] Re: preprocess SQLFORM fields before submission

2014-04-18 Thread aleonserra
Thank you anthony. Ive been able to find the answer at this other post "How to cleanse a field value". I didnt know about that filter_in argument, ill give it a try. -- Resources

[web2py] how to render a widget using a class?

2014-04-25 Thread aleonserra
Hi, Im having troubles defining widgets as classes. When widgets are defined as functions it all works well, the function returns a html object(DIV, UL, ...) and the view renders the markup correctly, but im trying to define the widget as a class to handle static files requirements for that wi

[web2py] Re: how to render a widget using a class?

2014-04-26 Thread aleonserra
Thank you very much, it works wonders. Here is the code i was trying, when the widget is created it also adds static file requirements (css, js) dynamically at the html head by using response.include_files() there. > db = DAL('mysql://root:1234@localhost/mydb') > > class Widget(): > def a

[web2py] How to redirect an error ticket response to the current url

2014-04-28 Thread aleonserra
Hi. Im trying to display the error ticket caused by a controller "without changing the current url" on my browser, also in the same browser tab of course. Im using Live Reload to display the changes to my pages and its quite annoying to manually refreshing the browser each time i have an error

[web2py] Re: Tidy html output?

2014-04-29 Thread aleonserra
I just wrote that function check it out. def pretty_html(obj): import xml.dom.minidom as xml declaration = len(xml.Document().toxml())+1 doc = xml.parseString(obj.xml()) return XML(doc.toprettyxml()[declaration:]) Where obj is a web2py helper. You can easily change it to accept p

[web2py] Re: How to redirect an error ticket response to the current url

2014-04-30 Thread aleonserra
Im gonna try to explain it better. I have an application with a controller that has a function that produces an error. ex: myapp/default/index on routes.py im redirecting the errors to otherapp/default/display_errors to watch the ticket i have to go to "http://localhost:8000/admin/default/ticket

Re: [web2py] can custom.form be used from the controller and pass to the view??

2014-05-03 Thread aleonserra
I have the same problem and i came with a workaround that looks ugly but it works. I needed a SQLFORM HTML template without exposing a route like 'http://localhost/home/my_custom_form' I have created a view like "views/mycontroller/form_mytable.html" without any controller dependency, since t

Re: [web2py] can custom.form be used from the controller and pass to the view??

2014-05-03 Thread aleonserra
Ok, i just found that you can add a custom formstyle argument as a function to a SQLFORM which is perfect to customize forms. def my_form_html(fields, extra_fields): return "Some kind of html markup" form = SQLFORM(db.mytable, formstyle = my_form_html) -- Resources: - http://web2py.com - h

[web2py] Re: How to redirect an error ticket response to the current url

2014-05-06 Thread aleonserra
Ok i finally got it. If you want to bypass the ticket system and display the errors directly on the page you are working on, follow these steps: 1.-Install mechanize which it is a library that automates webforms. 2- Redirect the errors to a custom c

[web2py] Re: cannot operate on a closed database

2014-05-09 Thread aleonserra
The error suggest that dal couldnt connect to the database. It doesnt look like a web2py problem but a db one. at line 4 add .select() to execute the statement. row = db(db.auth_user.username == username).select() Also start a web2py shell session (web2py -a -M)and test the database by executi