Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43822

Re: dynamic forms generation

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <wayne@waynewerner.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'example:': 0.03; 'ideally': 0.04; 'anyway.': 0.05; 'output': 0.05; 'extends': 0.09; 'forms,': 0.09; 'logic': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'systems.': 0.12; "wouldn't": 0.14; '(both': 0.16; 'generated,': 0.16; 'noone': 0.16; 'scalable,': 0.16; 'subject:generation': 0.16; 'url:pocoo': 0.16; 'wayne': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'bit': 0.19; 'dependent': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'example.': 0.24; 'fairly': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'code': 0.31; 'extending': 0.31; 'class': 0.32; 'quite': 0.32; 'text': 0.33; 'are:': 0.33; 'could': 0.34; 'problem': 0.35; 'basic': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'possible': 0.36; 'url:org': 0.36; 'should': 0.36; 'too': 0.37; 'server': 0.38; 'form,': 0.38; 'generic': 0.38; 'does': 0.39; 'sure': 0.39; 'easy': 0.60; 'here:': 0.62; 'soon': 0.63; 'become': 0.64; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'worth': 0.66; 'between': 0.67; 'default': 0.69; 'skip:r 30': 0.69; 'andrea': 0.84; 'client-side': 0.84; 'dry': 0.84; 'dsl': 0.84; 'generation,': 0.84; '2013,': 0.91; 'hands': 0.96
Date Thu, 18 Apr 2013 07:53:54 -0500 (CDT)
From Wayne Werner <wayne@waynewerner.com>
X-X-Sender wayne@gilgamesh
To andrea crotti <andrea.crotti.0@gmail.com>
Subject Re: dynamic forms generation
In-Reply-To <CAF_E5Ja93v_6-AcTc=T2EVOUPufYk12zmiv24QRTPKFetfAfcg@mail.gmail.com>
References <CAF_E5Ja93v_6-AcTc=T2EVOUPufYk12zmiv24QRTPKFetfAfcg@mail.gmail.com>
User-Agent Alpine 2.02 (DEB 1266 2009-07-14)
MIME-Version 1.0
Content-Type MULTIPART/MIXED; BOUNDARY="8323329-47601280-1366289634=:3322"
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.765.1366289645.3114.python-list@python.org> (permalink)
Lines 73
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366289645 news.xs4all.nl 2180 [2001:888:2000:d::a6]:48973
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43822

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: dynamic forms generation Wayne Werner <wayne@waynewerner.com> - 2013-04-18 07:53 -0500

csiph-web