Re: dynamic forms generation

2013-04-19 Thread andrea crotti
Well I think since we are using django anyway (and bottle on the API side)
I'm not sure why we would use flask forms for this..

Anyway the main question is probably, is it worth to try to define a DSL or
not?
The problem I see is that we have a lot and very complex requirements,
trying to define a DSL that is able to represent everything might be a
massive pain.

I prefer to do something smart with metaclasses and just use Python as the
configuration language itself, using metaclasses and similar nice things to
define the language used..
The only annoying part is the persistance, I don't like too much the idea
to store Python code in the db for example, but maybe it's fine, many
projects configure things with Python anyway..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dynamic forms generation

2013-04-18 Thread Wayne Werner

On Tue, 16 Apr 2013, andrea crotti wrote:


This is not really scalable, and we want to make the whole thing more
generic.

So ideally there could be a DSL (YAML or something else) that we could
define to then generate the forms, but the problem is that I'm quite
sure that this DSL would soon become too complex and inadeguate, so I'm
not sure if it's worth since noone should write forms by hands anyway.

Between the things that we should be able to do there are:
- dependent fields
- validation (both server and client side, better if client-side
  auto-generated)
- following DRY as much as possible

Any suggestions of possible designs or things I can look at?


I would highly recommend a look at Flask, and Flask-WTF in particular. 
It's fairly easy to write forms, and with only a bit of setup you can end 
out with some fairly generic systems.


I don't think that by default it does any client-side validation 
generation, but as the HTML for the forms are completely generated, 
extending the form and adding validation logic to the output wouldn't be 
too difficult.


Example:

# form.py

from flask.ext.wtf import Form, TextField, Required

class MyBasicForm(Form):
some_text = TextField(Put some text here:, validators=[Required()])


# View/HTML

{% extends 'base.html' %}
{{ form.some_text.label() }}{{ form.some_text(size=40) }}


# Server code

@app.route(/basic_form, methods=['GET', 'POST'])
def basic():
form = MyBasicForm()
if form.validate_on_submit():
do_the_needful(form.some_text.data)
return redirect(url_for('main'))

return render_template('basic_form.html', form=form)



Obviously a really basic example. Check out Flask here:
http://flask.pocoo.org/

And Flask WTF here:
http://pythonhosted.org/Flask-WTF/


HTH,
Wayne-- 
http://mail.python.org/mailman/listinfo/python-list


dynamic forms generation

2013-04-16 Thread andrea crotti
We are re-designing a part of our codebase, which should in short be
able to generate forms with custom fields.

We use django for the frontend and bottle for the backend (using CouchDB
as database), and at the moment we simply plug extra fields on normal
django forms.

This is not really scalable, and we want to make the whole thing more
generic.

So ideally there could be a DSL (YAML or something else) that we could
define to then generate the forms, but the problem is that I'm quite
sure that this DSL would soon become too complex and inadeguate, so I'm
not sure if it's worth since noone should write forms by hands anyway.

Between the things that we should be able to do there are:
- dependent fields
- validation (both server and client side, better if client-side
  auto-generated)
- following DRY as much as possible

Any suggestions of possible designs or things I can look at?
-- 
http://mail.python.org/mailman/listinfo/python-list