dexterity field 设置默认值注意事项

dexterity field 设置默认值注意事项
  1. Model schema 要求直接继承 form.schema
  2. 字段不能隐藏
  3. 字段不能设置为只读

 

from plone.directives import form

class IOrgnization_annual_survey(form.Schema):

    title = schema.TextLine(title=_(u"company name"),

                             required=False,)

@form.default_value(field=IOrgnization_annual_survey['title'])

def titleDefaultValue(data):

    # To get hold of the folder, do: context =

    name = data.context.title

    year = (datetime.datetime.today() + datetime.timedelta(-365)).strftime("%Y")

    title = u"%s%s年度信用报告" % (name,year)

    return  title

设置