本文整理汇总了Python中django.utils.dates.MONTHS.iterkeys方法的典型用法代码示例。如果您正苦于以下问题:Python MONTHS.iterkeys方法的具体用法?Python MONTHS.iterkeys怎么用?Python MONTHS.iterkeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.dates.MONTHS
的用法示例。
在下文中一共展示了MONTHS.iterkeys方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: date_selector
# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import iterkeys [as 别名]
def date_selector(prefix, date=None, disabled=False):
# if no date was provided, select TODAY
if date == None:
t = time.localtime()
# if a date was provided (such as a Question.start
# or .end), extract the values to prepopulate <select>s
elif isinstance(date, datetime.date):
t = date.timetuple()
# we have no idea what was passed
else: raise Exception("wat")
return {
"prefix": prefix,
"disabled": disabled,
# for hidden fields
"year": t.tm_year,
"month": t.tm_mon,
"day": t.tm_mday,
# for drop-down selects
"days": list((d, d==t.tm_mday) for d in range(1, 32)),
"months": list((unicode(MONTHS[m]), m==t.tm_mon) for m in MONTHS.iterkeys()),
"years": list((y, y==t.tm_year) for y in range(t.tm_year, t.tm_year+5))
}