Hi,
I'm new to Web2Py, and am struggling with debugging a problem which is
most likely caused by my lack of understanding of the back-end of
Web2Py.
I'm writing an app that creates a form using SQLForm, which I display
using a form.custom.widget.etc. I've then added to this form an input
(NumberofAssets) that was not created by SQLForm, and that doesn't
match anything in the table. The additional input is to be used by the
controller to determine how many duplicate entries of the form to
create in the database. However, the form fails on form.accepts.
I've tried removing the additional data from request.vars by "del
request.vars['NumberofAssets']", but this doesn't make it work.
"form has errors" and "else achieved" exist purely for debugging, so I
can see where the program has gone logically. Upon entering data in
the form, "else achieved" keeps popping up, so its failing on "if
form.accepts(request.vars, dbio-False):", but no errors are being
reported because its not trapping in "elif form.errors".
I've been fighting with this for a week now, and getting nowhere. Any
assistance, or suggestions would be greatly appreciated. Controller
and View are appended below.
Thanks.
--James
Controller:
def ManageAssets():
form = SQLFORM(db.AssetTable)
if (request.vars.NumberofAssets):
NumberofAssets = int(request.vars.NumberofAssets)
Del request.vars['NumberofAssets']
while NumberofAssets > 0:
if form.accepts(request.vars, dbio=False):
form.vars.id = db.AssetTable.insert(**dict(form.vars))
response.flash = 'new record inserted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'else achieved'
NumberofAssets -= 1
return dict(form=form)
View:
{{extend 'layout.html'}}
{{=form.custom.begin}}
Asset Type: <div>{{=form.custom.widget.TypeID}}</div>
Location: <div>{{=form.custom.widget.Location}}</div>
Cost: <div>{{=form.custom.widget.Cost}}</div>
Date Purchased: <div>{{=form.custom.widget.PurchaseDate}}</div>
Purchase Order Number: <div>{{=form.custom.widget.PurchaseOrder}}</
div>
Manufacturer: <div>{{=form.custom.widget.Manufacturer}}</div>
Supplier: <div>{{=form.custom.widget.Supplier}}</div>
Department: <div>{{=form.custom.widget.Department}}</div>
Status: <div>{{=form.custom.widget.Status}}</div>
Curric: <div>{{=form.custom.widget.Curric}}</div>
Number of Assets: <div><input id="NumberofAssets"
name="NumberofAssets" type="int" value="1" /></div>
Create Assets: {{=form.custom.submit}}
{{=form.custom.end}}
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.