问题
I am trying to set up a registration form for a conference using PloneFormGen, and I would like to use a TALES Expression to count the number of existing records, add "1", then display this on the "Thank You" page as the registrant's registration number. Is this possible?
I have used the following to generate a random 6 digit number in the past to create a case number ID for a support request, where the number didn't matter other than to track the request, then it would be deleted once the case is closed.
python:random.randint(100000, 999999)
Am I on the right track, or am I going about this completely the wrong way?
回答1:
I've done this in the past with the following trick:
In the ZMI, I create on the form an integer property named "reg_count" containing the starting number (navigate to the form folder and append /manage_propertiesForm to the URL);
Add a hidden field to the form. I used the id "regno";
Use a custom script adapter to fetch the reg_count property, increment it, and put it in the request's form dictionary:
reg_count = context.getProperty('reg_count', 0) + 1 context.manage_changeProperties(reg_count=reg_count) request.form['regno'] = str(reg_count)
Customize the thanks page to display it.
来源:https://stackoverflow.com/questions/15271588/how-can-i-generate-a-registration-number-in-ploneformgen-using-a-tales-expressi