forms.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:NZ-ORCID-Hub 作者: Royal-Society-of-New-Zealand 项目源码 文件源码
def render_select(cls, part, field):
        """Render select for a specific part of date."""
        yield "<select %s>" % html_params(name=field.name + ":" + part)
        # If user didn't specifiy the date then the year range will start from current year + 5 years
        range_value = cls.__current_year + 5
        try:
            current_value = int(getattr(field.data, part))
            range_value = current_value + 5
        except Exception:
            current_value = None
        # TODO: localization
        yield "<option %s>%s</option>" % (html_params(value="", selected=(current_value is None)),
                                          part.capitalize())
        option_format = "<option %s>%04d</option>" if part == "year" else "<option %s>%02d</option>"
        for v in range(range_value, 1912, -1) if part == "year" else range(
                1, 13 if part == "month" else 32):
            yield option_format % (html_params(value=v, selected=(v == current_value)), v)
        yield "</select>"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号