Skip to content

Commit

Permalink
Added some error handling to a volital insert of data into the database
Browse files Browse the repository at this point in the history
  • Loading branch information
kusinwolf committed Jul 27, 2010
1 parent 6a2215e commit 4294985
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 12 additions & 7 deletions kusinwolf/PylonsApps/iman/iman/controllers/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,18 @@ def weight_delete(self):
def weight_add(self):
'''functional method'''

meta.Session.begin_nested()
meta.Session.save(
Weight(weight = float(request.POST.get("weight")),
user_id = int(session['identity'].uid),
units = int(request.POST.get("unit")))
)
meta.Session.commit()
c.failed = ""

try:
meta.Session.begin_nested()
meta.Session.save(
Weight(weight = float(request.POST.get("weight")),
user_id = int(session['identity'].uid),
units = int(request.POST.get("unit")))
)
meta.Session.commit()
except:
c.failed = "Oops sorry, something happened and we could not save your information, please try again"

return redirect_to(action="index")

5 changes: 5 additions & 0 deletions kusinwolf/PylonsApps/iman/iman/templates/health/index.mako
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ ${h.form(h.url_for(action="weight_add"), method="post")}
${h.submit("Submit", "Add Weight")}<br />
${h.end_form()}

% if c.failed:
<h4>${c.failed}</h4>
<br />
% endif

<br />
% if c.last_weight:
<h2>Your Last Weight was ${c.last_weight.weight} ${c.last_weight.unit.digest}</h2>
Expand Down

0 comments on commit 4294985

Please sign in to comment.