def post(req): # if DELETE was clicked... delete # the object, then and redirect if req.POST.get("delete", ""): pk = rep.pk rep_profile.delete() rep.delete() transaction.commit() return message(req, "Tester %d deleted" % (pk), link="/testers") else: # check the form for errors (just # missing fields, for the time being) reporter_errors = check_reporter_form(req) profile_errors = check_profile_form(req) # if any fields were missing, abort. this is # the only server-side check we're doing, for # now, since we're not using django forms here missing = reporter_errors["missing"] + profile_errors["missing"] if missing: transaction.rollback() return message(req, "Missing Field(s): %s" % ", ".join(missing), link="/testers/%s" % (rep.pk)) try: # automagically update the fields of the # reporter object, from the form update_via_querydict(rep, req.POST).save() # add relevent connections update_reporter(req, rep) # update reporter profile update_reporterprofile(req, rep, req.POST.get("chw_id", ""), \ req.POST.get("chw_username", ""), \ req.POST.get("e_mail", ""), \ req.POST.get("facility","")) # no exceptions, so no problems # commit everything to the db transaction.commit() # full-page notification return message(req, "Tester %d updated" % (rep.pk), link="/testers") except Exception, err: transaction.rollback() raise
def post(req): # check the form for errors reporter_errors = check_reporter_form(req) profile_errors = check_profile_form(req) # if any fields were missing, abort. missing = reporter_errors["missing"] + profile_errors["missing"] exists = reporter_errors["exists"] + profile_errors["exists"] if missing: transaction.rollback() return message(req, "Missing Field(s): %s" % comma(missing), link="/testers/add") # if chw_id exists, abort. if exists: transaction.rollback() return message(req, "Field(s) already exist: %s" % comma(exists), link="/testers/add") try: # create the reporter object from the form rep = insert_via_querydict(Reporter, req.POST) rep.save() # add relevent connections update_reporter(req, rep) # create reporter profile update_reporterprofile(req, rep, req.POST.get("chw_id", ""), \ req.POST.get("alias", ""), \ req.POST.get("e_mail", ""),\ req.POST.get("facility","")) # save the changes to the db transaction.commit() # full-page notification return message(req, "Testers %d added" % (rep.pk), link="/testers") except Exception, err: transaction.rollback() raise