当前位置: 首页>>代码示例>>Python>>正文


Python MONTHS.items方法代码示例

本文整理汇总了Python中django.utils.dates.MONTHS.items方法的典型用法代码示例。如果您正苦于以下问题:Python MONTHS.items方法的具体用法?Python MONTHS.items怎么用?Python MONTHS.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.dates.MONTHS的用法示例。


在下文中一共展示了MONTHS.items方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, basestring):
                if settings.USE_L10N:
                    try:
                        input_format = get_format('DATE_INPUT_FORMATS')[0]
                        v = datetime.datetime.strptime(value, input_format)
                        year_val, month_val, day_val = v.year, v.month, v.day
                    except ValueError:
                        pass
                else:
                    match = RE_DATE.match(value)
                    if match:
                        year_val, month_val, day_val = [int(v) for v in match.groups()]
        choices = [(i, i) for i in self.years]
        year_html = self.create_select(name, self.year_field, value, year_val, choices)
        choices = MONTHS.items()
        month_html = self.create_select(name, self.month_field, value, month_val, choices)
        choices = [(i, i) for i in range(1, 32)]
        day_html = self.create_select(name, self.day_field, value, day_val,  choices)

        output = []
        for field in _parse_date_fmt():
            if field == 'year':
                output.append(year_html)
            elif field == 'month':
                output.append(month_html)
            elif field == 'day':
                output.append(day_html)
        return mark_safe(u'\n'.join(output))
开发者ID:101studio,项目名称:django,代码行数:35,代码来源:widgets.py

示例2: render

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, basestring):
                match = RE_DATE.match(value)
                if match:
                    year_val, month_val, day_val = [int(v) for v in match.groups()]

        choices = [(i, i) for i in self.years]
        year_html = self.create_select(name, self.year_field, value, year_val, choices)
        choices = MONTHS.items()
        month_html = self.create_select(name, self.month_field, value, month_val, choices)
        choices = [(i, i) for i in range(1, 32)]
        day_html = self.create_select(name, self.day_field, value, day_val,  choices)

        format = get_format('DATE_FORMAT')
        escaped = False
        output = []
        for char in format:
            if escaped:
                escaped = False
            elif char == '\\':
                escaped = True
            elif char in 'Yy':
                output.append(year_html)
            elif char in 'bFMmNn':
                output.append(month_html)
            elif char in 'dj':
                output.append(day_html)
        return mark_safe(u'\n'.join(output))
开发者ID:BGCX261,项目名称:zkwiki-hg-to-git,代码行数:34,代码来源:widgets.py

示例3: render

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def render(self, name, value, attrs=None):
        try:
            y_val, m_val = value.year, value.month
        except AttributeError:
            y_val = m_val = None
            if isinstance(value, str):
                match = RE_DATE.match(value)
                if match:
                    y_val, m_val, d_val = [int(v) for v in match.groups()]

        output = []

        if 'id' in self.attrs:
            id_ = self.attrs['id']
        else:
            id_ = 'id_%s' % name

        month_choices = list(MONTHS.items())
        if not (self.required and value):
            month_choices.append(self.none_value_month)
        month_choices.sort()
        local_attrs = self.build_attrs(id=self.month_field % id_)
        s = Select(choices=month_choices)
        select_html = s.render(self.month_field % name, m_val, local_attrs)
        output.append('<div class="date-select">' + select_html + '</div>')

        year_choices = [(i, i) for i in self.years]
        if not (self.required and value):
            year_choices.insert(0, self.none_value_year)
        local_attrs['id'] = self.year_field % id_
        s = Select(choices=year_choices)
        select_html = s.render(self.year_field % name, y_val, local_attrs)
        output.append('<div class="date-select">' + select_html + '</div>')

        return mark_safe(u'\n'.join(output))
开发者ID:lm-tools,项目名称:situational,代码行数:37,代码来源:widgets.py

示例4: render

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, str):
                match = RE_DATE.match(value)
                if match:
                    year_val, month_val, day_val = [int(v) for v in match.groups()]

        output = []

        if 'id' in self.attrs:
            id_ = self.attrs['id']
        else:
            id_ = 'id_%s' % name

        month_choices = list(MONTHS.items())
        month_choices.sort()
        local_attrs = self.build_attrs(id=self.month_field % id_)
        select_html = Select(choices=month_choices).render(self.month_field % name, month_val, local_attrs)
        output.append(select_html)

        day_choices = [(i, i) for i in range(1, 32)]
        local_attrs['id'] = self.day_field % id_
        select_html = Select(choices=day_choices).render(self.day_field % name, day_val, local_attrs)
        output.append(select_html)

        year_choices = [(i, i) for i in self.years]
        local_attrs['id'] = self.year_field % id_
        select_html = Select(choices=year_choices).render(self.year_field % name, year_val, local_attrs)
        output.append(select_html)

        return mark_safe('\n'.join(output))
开发者ID:gitdlam,项目名称:geraldo,代码行数:36,代码来源:widgets.py

示例5: render

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
	def render(self, name, value, attrs=None):
		try:
			year_val, month_val = value.year, value.month
		except AttributeError:
			year_val = month_val = None
			if isinstance(value, basestring):
				match = RE_DATE.match(value)
				if match:
					year_val, month_val, day_val = [int(v) for v in match.groups()]

		output = []

		if 'id' in self.attrs:
			id_ = self.attrs['id']
		else:
			id_ = 'id_%s' % name

		local_attrs = self.build_attrs(id=self.month_field % id_)
		month_choices = MONTHS.items()
		month_choices.insert(0, self.none_value)
		#month_choices.sort()
		s = Select(choices=month_choices)
		select_html = s.render(self.month_field % name, month_val, local_attrs)
		output.append(select_html)

		year_choices = [(i, i) for i in self.years]
		year_choices.insert(0, self.none_value)
		local_attrs['id'] = self.year_field % id_
		s = Select(choices=year_choices)
		select_html = s.render(self.year_field % name, year_val, local_attrs)
		output.append(select_html)

		return mark_safe(u'\n'.join(output))
开发者ID:Trannosaur,项目名称:myrobogals,代码行数:35,代码来源:views.py

示例6: __init__

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
 def __init__(self, *args, **kwargs):
     super(StripePaymentForm, self).__init__(*args, **kwargs)
     self.fields['card_cvv'].label = "Card CVC"
     self.fields['card_cvv'].help_text = "Card Verification Code; see rear of card."
     months = [(m[0], u'%02d - %s' % (m[0], str(m[1])))
               for m in sorted(MONTHS.items())]
     self.fields['card_expiry_month'].choices = months
开发者ID:bennylope,项目名称:django-quagga,代码行数:9,代码来源:forms.py

示例7: render

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def render(self, name, value, attrs=None, extra_context={}):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, basestring):
                if settings.USE_L10N:
                    try:
                        input_format = formats.get_format(
                            'DATE_INPUT_FORMATS'
                        )[0]
                        v = datetime.datetime.strptime(value, input_format)
                        year_val, month_val, day_val = v.year, v.month, v.day
                    except ValueError:
                        pass
                else:
                    match = RE_DATE.match(value)
                    if match:
                        year_val, month_val, day_val = map(int, match.groups())

        context = self.get_context(name, value, attrs=attrs,
                                   extra_context=extra_context)

        context['year_choices'] = [(i, i) for i in self.years]
        context['year_val'] = year_val

        context['month_choices'] = MONTHS.items()
        context['month_val'] = month_val

        context['day_choices'] = [(i, i) for i in range(1, 32)]
        context['day_val'] = day_val

        return loader.render_to_string(self.template_name, context)
开发者ID:LaMustax,项目名称:django-floppyforms,代码行数:35,代码来源:widgets.py

示例8: __init__

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
 def __init__(self, attrs=None):
     # create choices for days, months, years
     # example below, the rest snipped for brevity.
     _widgets = (
         widgets.Select(attrs=attrs, choices=MONTHS.items()),
         # widgets.Select(attrs=attrs, choices=years),
         widgets.TextInput(attrs=attrs),
     )
     super(MonthSelectorWidget, self).__init__(_widgets, attrs)
开发者ID:paramono,项目名称:django-monthfield,代码行数:11,代码来源:widgets.py

示例9: render

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def render(self, context, instance, placeholder):
        context = super(BirthdayCalendarPlugin, self).render(context, instance, placeholder)

        User = get_user_model()
        # Extracts/Truncates are only avaible in Django 1.10+
        users = list(User.objects.filter(birthdate__isnull=False))
        users.sort(key=lambda u: (u.birthdate.month, u.birthdate.day))
        context['profiles'] = users
        context['months'] = [m[1] for m in sorted(MONTHS.items())]
        return context
开发者ID:sergei-maertens,项目名称:langerak-gkv,代码行数:12,代码来源:cms_plugins.py

示例10: __init__

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def __init__(self, attrs=None):
        current_year = date.today().year
        years = reversed([(current_year + i, current_year + i) for i in range(-2, 2)])
        months = MONTHS.items()

        _widgets = (
            widgets.HiddenInput(attrs=attrs),
            widgets.Select(attrs=attrs, choices=months),
            widgets.Select(attrs=attrs, choices=years),
        )
        super(self.__class__, self).__init__(_widgets, attrs)
开发者ID:perenecabuto,项目名称:contas,代码行数:13,代码来源:widgets.py

示例11: render

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, basestring):
                match = RE_DATE.match(value)
                if match:
                    year_val, month_val, day_val = [int(v) for v in match.groups()]

        output = []

        if "id" in self.attrs:
            id_ = self.attrs["id"]
        else:
            id_ = "id_%s" % name

        month_choices = MONTHS.items()
        if not (self.required and value):
            month_choices.append(self.none_value_month)
        month_choices.sort()
        local_attrs = self.build_attrs(id=self.month_field % id_)
        s = Select(choices=month_choices)

        if self.attrs_month is not None:
            local_attrs.update({"class": self.attrs_month})

        select_html = s.render(self.month_field % name, month_val, local_attrs)
        output.append(select_html)

        day_choices = [(i, i) for i in range(1, 32)]
        if not (self.required and value):
            day_choices.insert(0, self.none_value_day)
        local_attrs["id"] = self.day_field % id_
        if self.attrs_day is not None:
            local_attrs.update({"class": self.attrs_day})

        s = Select(choices=day_choices)
        select_html = s.render(self.day_field % name, day_val, local_attrs)
        output.append(select_html)

        year_choices = [(i, i) for i in self.years]
        if not (self.required and value):
            year_choices.insert(0, self.none_value_year)
        local_attrs["id"] = self.year_field % id_

        if self.attrs_year is not None:
            local_attrs.update({"class": self.attrs_year})

        s = Select(choices=year_choices)
        select_html = s.render(self.year_field % name, year_val, local_attrs)
        output.append(select_html)

        return mark_safe(u"\n".join(output))
开发者ID:braskin,项目名称:pd,代码行数:56,代码来源:widgets.py

示例12: as_dict

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def as_dict(self):
        widget_dict = super(RemoteSelectDateWidget, self).as_dict()
        widget_dict['input_type'] = 'selectdatewidget'

        current_year = datetime.datetime.now().year
        widget_dict['choices'] = [{
            '%s_day' % self.field_name: [{'key': x, 'value': x} for x in range(1, 32)],
            '%s_month' % self.field_name: [{'key': x, 'value': y} for (x, y) in MONTHS.items()],
            '%s_year' % self.field_name: [{'key': x, 'value': x} for x in range(current_year - 100, current_year + 1)]
        }]

        return widget_dict
开发者ID:gngotho,项目名称:django-remote-forms,代码行数:14,代码来源:widgets.py

示例13: __init__

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def __init__(self, *args, **kwargs):
        DAYS_CHOICES = [('','-------')] + [(y,y) for y in range(1,32)]
        MONTHS_CHOICES = [('','-------')] + MONTHS.items()
        year = date.today().year
        YEARS_CHOICES = [('','-------')] + [(y,y) for y in range(year-1, year+50)]
        widgets = [
                forms.Select(choices=DAYS_CHOICES),
                forms.Select(choices=MONTHS_CHOICES),
                forms.Select(choices=YEARS_CHOICES),
                ]

        super(YearMonthWidget, self).__init__(widgets=widgets, *args, **kwargs)
开发者ID:AnaBiel,项目名称:opentrials,代码行数:14,代码来源:widgets.py

示例14: as_dict

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def as_dict(self):
        widget_dict = super(RemoteDateInput, self).as_dict()

        widget_dict["input_type"] = "date"

        current_year = datetime.datetime.now().year
        widget_dict["choices"] = [
            {"title": "day", "data": [{"key": x, "value": x} for x in range(1, 32)]},
            {"title": "month", "data": [{"key": x, "value": y} for (x, y) in MONTHS.items()]},
            {"title": "year", "data": [{"key": x, "value": x} for x in range(current_year - 100, current_year + 1)]},
        ]

        return widget_dict
开发者ID:rhblind,项目名称:stickfighter,代码行数:15,代码来源:widgets.py

示例15: render

# 需要导入模块: from django.utils.dates import MONTHS [as 别名]
# 或者: from django.utils.dates.MONTHS import items [as 别名]
    def render(self, name, value, attrs=None, extra_context={}):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, six.text_type):
                if settings.USE_L10N:
                    try:
                        input_format = formats.get_format(
                            'DATE_INPUT_FORMATS'
                        )[0]
                        v = datetime.datetime.strptime(value, input_format)
                        year_val, month_val, day_val = v.year, v.month, v.day
                    except ValueError:
                        pass
                else:
                    match = RE_DATE.match(value)
                    if match:
                        year_val, month_val, day_val = map(int, match.groups())

        context = self.get_context(name, value, attrs=attrs,
                                   extra_context=extra_context)

        context['year_choices'] = [(i, i) for i in self.years]
        context['year_val'] = year_val

        context['month_choices'] = list(MONTHS.items())
        context['month_val'] = month_val

        context['day_choices'] = [(i, i) for i in range(1, 32)]
        context['day_val'] = day_val

        # Theoretically the widget should use self.is_required to determine
        # whether the field is required. For some reason this widget gets a
        # required parameter. The Django behaviour is preferred in this
        # implementation.

        # Django also adds none_value only if there is no value. The choice
        # here is to treat the Django behaviour as a bug: if the value isn't
        # required, then it can be unset.
        if self.required is False:
            context['year_choices'].insert(0, self.none_value)
            context['month_choices'].insert(0, self.none_value)
            context['day_choices'].insert(0, self.none_value)

        if callable(self.template_name):
            template_name = self.template_name(context, self)
        else:
            template_name = self.template_name
        return loader.render_to_string(template_name, context)
开发者ID:walnutist,项目名称:django-floppyforms,代码行数:52,代码来源:widgets.py


注:本文中的django.utils.dates.MONTHS.items方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。