Plon 4:CalendarWidget 仅显示年份,不显示日期和月份
在 Plone 4 中,我使用的是 CalendarWidget。是否可以在日期时间字段的自定义视图中仅显示年份?我需要输入的一些记录没有月份和日期,但已提供年份。
有没有办法限制小部件仅允许年份但忽略日期和月份字段,除非提供了它们?
目前我的代码如下:
atapi.DateTimeField('item_publication_date',
required=True,
searchable = True,
validators = ('isValidDate'),
widget = atapi.CalendarWidget(
show_hm=False,
label=_(u'Publication Date'),
starting_year=1970,
format='%Y',
description=_(u"Item Publication Date"),
),
),
In Plone 4, I am using the CalendarWidget. Is it possible to display only the year in a custom view for a datetime field? Some records that I need to input do not have the month and date but the year has been provided.
Is there a way to limit the widget to allow only the year but ignore the date and month fields unless they are provided?
Currently my code is as follows:
atapi.DateTimeField('item_publication_date',
required=True,
searchable = True,
validators = ('isValidDate'),
widget = atapi.CalendarWidget(
show_hm=False,
label=_(u'Publication Date'),
starting_year=1970,
format='%Y',
description=_(u"Item Publication Date"),
),
),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能。在 Zope 中,DateTime 对象必须有月份和日期才能工作,如果您只提供年份,它们将被设置为什么?
但是,您可以使用带有动态词汇表的简单 StringField,让用户从下拉列表中选择年份,然后使用内容类上的自定义方法为 getItem_publication_date() 返回 DateTime 对象,您可以在其中获取年份该字段的返回值。
You can't. In Zope, DateTime objects must have a month and day to work at all, and what would they be set to if you only supply a year?
You can, however, use a simple StringField with a dynamic vocabulary to let users pick a year from a drop-down list, then use a custom method on your content class to return a DateTime object for getItem_publication_date() where you take the year for the return value from that field.