How can I generate a registration number in PloneFormGen, using a TALES Expression?

爱⌒轻易说出口 提交于 2019-12-12 14:21:39

问题


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:

  1. 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);

  2. Add a hidden field to the form. I used the id "regno";

  3. 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)
    
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!