Dynamic Form

BJ Swope bigblueswope at gmail.com
Tue Sep 22 23:20:33 EDT 2009


If you are trying to avoid the browser caching the pages so that they fetch
a new copy of the page every time, add the following 2 meta tags to the
header of the html page:

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

Those don't guarantee that the browser won't cache the page but it should
help the situation.

If on the other hand, you only want to populate each company's table with
the data from the form that is currently being submitted, you would run a
delete query on that company's table before you do the insert of the current
form's data.

I have some questions for you.

1. Why create a distinct table for each company?  Why not have a single
table called lets say, "catalog".  Have company be just an additional field
in the catalog table.  This way you can avoid having to create distinct
tables every time somebody submits the form with a distinct company.

2.  Why do you use build your sql statements differently and call
cursor.execute() differently.  In the first sql declaration you are using a
static string then using the string substitution when you make the
cursor.execute() call.  In the second sql declaration you perform the string
substitiution and then make the cursor.execute() call with the resulting
variable.  Why not use the same technique in both places.

3.  And as a way to make the catalog item entry page easier on the eyes, why
not use tables to give a consistent spacing/alignment.

Replace the following:
      print '<hr />\n'
      print "Category: <input type='text' value='' size='20' maxlength='100'
name='cat%s' /><br />\n" % (str(i))
      print "Item: <input type='text' value='' size='20' maxlength='20'
name='item%s' /><br />\n" % (str(i))
      print "Description: <input type='text' value='' size='20'
maxlength='255' name='descr%s' /><br />\n" % (str(i))
      print "UOM: <input type='text' value='' size='20' maxlength='20'
name='uom%s' /><br />\n" % (str(i))
      print "Price: <input type='text' value='' size='10' maxlength='10'
name='price%s' /><br />\n" % (str(i))

With the following:
      print "<hr>"
      print "<table>"
      print "<tr><td>Category</td><td><input type='text' value='' size='20'
maxlength='100' name='cat%s' /></td></tr>" % (str(i))
      print "<tr><td>Item</td><td><input type='text' value='' size='20'
maxlength='20' name='item%s' /></td></tr>" % (str(i))
      print "<tr><td>Description</td><td><input type='text' value=''
size='20' maxlength='255' name='descr%s' /></td></tr>" % (str(i))
      print "<tr><td>UOM</td><td><input type='text' value='' size='20'
maxlength='20' name='uom%s' /></td></tr>" % (str(i))
      print "<tr><td>Price</td><td><input type='text' value='' size='10'
maxlength='10' name='price%s' /></td></tr>" % (str(i))
      print "</table>"

Makes the web page much easier to read.


-- 
To argue that honorable conduct is only required against an honorable enemy
degrades the Americans who must carry out the orders. -- Charles Krulak,
Former Commandant of the Marine Corps

We are all slave to our own paradigm. -- Joshua Williams

If the letters PhD appear after a person's name, that person will remain
outdoors even after it's started raining. -- Jeff Kay



On Tue, Sep 22, 2009 at 12:50 PM, Victor Subervi <victorsubervi at gmail.com>wrote:

> Well it's Web stuff, sure, but it's written in python :) The code follows.
> The problem is that I haven't figured out how to tell the program that the
> user has entered data and to clear the cache of that data so that it's not
> re-entered. How do I do that?
> TIA,
> Victor
>
> snip

>     sql = 'Category varchar(100), Item varchar(20), Description
> varchar(255), UOM varchar(20), Price float(7,2)'
>     cursor.execute('create table if not exists %s (%s);' % (company, sql))
>
> snip

>       sql = 'insert into %s (Category, Item, Description, UOM, Price)
> values ("%s", "%s", "%s", "%s", "%s");' % (company, cat, item, descr, uom,
> price)
>       cursor.execute(sql)
>
> snip

>     i = 0
>     while i < num:
>       print '<hr />\n'
>       print "Category: <input type='text' value='' size='20'
> maxlength='100' name='cat%s' /><br />\n" % (str(i))
>       print "Item: <input type='text' value='' size='20' maxlength='20'
> name='item%s' /><br />\n" % (str(i))
>       print "Description: <input type='text' value='' size='20'
> maxlength='255' name='descr%s' /><br />\n" % (str(i))
>       print "UOM: <input type='text' value='' size='20' maxlength='20'
> name='uom%s' /><br />\n" % (str(i))
>       print "Price: <input type='text' value='' size='10' maxlength='10'
> name='price%s' /><br />\n" % (str(i))
>
>
>
> On Tue, Sep 22, 2009 at 11:34 AM, Simon Forman <sajmikins at gmail.com>wrote:
>
>> On Tue, Sep 22, 2009 at 10:46 AM, Victor Subervi
>> <victorsubervi at gmail.com> wrote:
>> > Hi;
>> > I have a dynamic form in which I do the following:
>> > 1) Request two fields (company name, number of entries). That is sent
>> back
>> > to the form.
>> > 2) If the two fields are not None, the form requests other data. That,
>> too,
>> > is sent back to the form.
>> > 3) That new data is then entered into a MySQL table.
>> > The problem is, that when I go back to refresh the form, the data is
>> > re-entered into the table! How do I prevent that?
>> > TIA,
>> > Victor
>> >
>>
>> First, this seems like it's not a python question, rather it's seems
>> to be about some web stuff.
>>
>> Second, there's not enough information to tell you anything useful.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090922/1039fa2b/attachment-0001.html>


More information about the Python-list mailing list