Actually I was looking at the wrong controller function. I have a utility
function which returns part of the UI. Somehow when the form is submitted
and this is run the tempfile for the image is closed. So by doing this at
the end, after the form processing is complete, the problem is solved.
@auth.requires_login()
def add_custom():
#check if there is an offer selected
# if not session.quote or not session.quote.number:
# session.flash = T('Please select an offer first')
# redirect(URL('default', 'offer_landing'))
try:
offerId = request.args[0]
except IndexError:
offerId = 0
offerDetails = offer.authorise(offerId)
pagetitle = H3(T('Custom Product'))
buttongroup = [btn.back()]
try:
record = db.custom_product[request.args[1]] or None
except [IndexError, KeyError, TypeError]:
record = None
if session.custom_copy:
db.custom_product.productname.default = session.custom_copy.
productname
db.custom_product.description.default = session.custom_copy.
description
db.custom_product.purchasecost.default = session.custom_copy.
purchasecost
db.custom_product.monthlycost.default = session.custom_copy.
monthlycost
#db.custom_product.smallimage.default =
session.custom_copy.smallimage
session.custom_copy = None
db.custom_product.created_on.readable = False
db.custom_product.updated_on.readable = False
form = SQLFORM(db.custom_product, record, showid = False)
if form.process().accepted:
#do this for insert but not update
if not record:
# need to get the max priorites from the offer table
pp = mp = None
# offerDetails = db.offer[session.quote.number]
# increment whichever needs to be used and save it to the offer
table
if form.vars.purchasecost:
if offerDetails.offer.maxpurchasepriority:
offerDetails.offer.maxpurchasepriority += 1
else:
offerDetails.offer.maxpurchasepriority = 1
pp = offerDetails.offer.maxpurchasepriority
if form.vars.monthlycost or (not form.vars.purchasecost and not
form.vars.monthlycost):
if offerDetails.offer.maxmonthlypriority:
offerDetails.offer.maxmonthlypriority += 1
else:
offerDetails.offer.maxmonthlypriority = 1
mp = offerDetails.offer.maxmonthlypriority
offerDetails.offer.update_record()
# insert record into product_offer_item
db.product_offer_item.insert(
offer_id = offerDetails.offer.id,
custom_pid = form.vars.id,
quantity = 1,
purchasepriority = pp,
monthlypriority = mp,
)
else:
# only do this for updates
# check if a price change also needs a priority change
poiRecord = record.product_offer_item.select().first()
pp = copy.copy(poiRecord.purchasepriority)
mp = copy.copy(poiRecord.monthlypriority)
#poi_set = db(db.product_offer_item.custom_pid == poiRecord.id)
if pp and (not form.vars.purchasecost > 0):
poiRecord.update_record(purchasepriority = 0)
if not pp and (form.vars.purchasecost > 0):
poiRecord.update_record(purchasepriority = 99.5)
if mp and (form.vars.purchasecost > 0 and not form.vars.monthlycost
> 0):
poiRecord.update_record(monthlypriority = 0)
if not mp and\
((not form.vars.purchasecost > 0 and not
form.vars.monthlycost
> 0) or\
not form.vars.purchasecost > 0 and form.vars.monthlycost
> 0):
poiRecord.update_record(monthlypriority = 99.5)
offer.position_check(offerDetails.offer.id)
session.flash = T('Success')
redirect(btn.EditOffer(offerDetails.offer.id,
dict(custId = offerDetails.customer.id)).url)
elif form.errors:
response.flash = T('Errors in form')
else:
pass
status = roo.status(offerDetails) # <- Moved this line from the top to
down here
response.view = 'core.html'
return dict(
pagetitle = pagetitle,
pagecontent = form,
buttongroup = buttongroup,
status = status,
)
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/c051466f-ac1a-4ded-8e17-cd2b5f9649cc%40googlegroups.com.