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


Python dates.MONTHS类代码示例

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


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

示例1: render

    def render(self, context, instance, placeholder):
        context = super(CalendarPlugin, self).render(context, instance,
                                                     placeholder)
        if context.get('plugin_configuration_error') is not None:
            return context
        namespace = self.get_namespace(instance)
        language = self.get_language(context['request'])
        site_id = getattr(get_current_site(context['request']), 'id', None)
        year = context.get('event_year')
        month = context.get('event_month')

        if not all([year, month]):
            year = str(timezone.now().date().year)
            month = str(timezone.now().date().month)

        current_date = datetime.date(int(year), int(month), 1)

        context['event_year'] = year
        context['event_month'] = month
        context['days'] = build_calendar(
            year, month, language, namespace, site_id)
        context['current_date'] = current_date
        context['last_month'] = current_date + datetime.timedelta(days=-1)
        context['next_month'] = current_date + datetime.timedelta(days=35)
        context['calendar_label'] = u'%s %s' % (MONTHS.get(int(month)), year)
        context['calendar_namespace'] = namespace
        return context
开发者ID:victorevector,项目名称:aldryn-events,代码行数:27,代码来源:cms_plugins.py

示例2: render

    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,代码行数:32,代码来源:widgets.py

示例3: render

    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,代码行数:33,代码来源:widgets.py

示例4: __init__

 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], unicode(m[1])))
                 for m in sorted(MONTHS.iteritems()) ]
     self.fields['card_expiry_month'].choices = months
开发者ID:jnm,项目名称:django-zebra,代码行数:7,代码来源:forms.py

示例5: render

    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,代码行数:35,代码来源:widgets.py

示例6: date_selector

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))
	}
开发者ID:ewheeler,项目名称:smspoll,代码行数:28,代码来源:utils.py

示例7: render

    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,代码行数:34,代码来源:widgets.py

示例8: render

    def render(self, context, instance, placeholder):
        # # check if we can reverse list view for configured namespace
        # # if no prepare a message to admin users.
        namespace = instance.app_config_id and instance.app_config.namespace
        if not is_valid_namespace(namespace):
            # add message, should be properly handled in template
            context['plugin_configuration_error'] = NO_APPHOOK_ERROR_MESSAGE
            return context

        year = context.get('event_year')
        month = context.get('event_month')

        if not all([year, month]):
            year = str(timezone.now().date().year)
            month = str(timezone.now().date().month)

        current_date = datetime.date(int(year), int(month), 1)
        language = instance.language

        context['event_year'] = year
        context['event_month'] = month
        context['days'] = build_calendar(year, month, language, namespace)
        context['current_date'] = current_date
        context['last_month'] = current_date + datetime.timedelta(days=-1)
        context['next_month'] = current_date + datetime.timedelta(days=35)
        context['calendar_label'] = u'%s %s' % (MONTHS.get(int(month)), year)
        context['calendar_namespace'] = namespace
        context['calendar_language'] = language
        return context
开发者ID:Marketionist,项目名称:aldryn-events,代码行数:29,代码来源:cms_plugins.py

示例9: create_projects_parts_and_imputations

    def create_projects_parts_and_imputations(self):
        max_projects = 3
        for p in range(0, max_projects):
            project = Project()
            project.internal_id = self.sd.word() + str(p)
            project.name = self.sd.word()
            project.description = self.sd.paragraph()
            project.active = self.sd.boolean()
            project.client = Client.objects.order_by("?")[0]
            project.save()
            project_users = User.objects.order_by("?")[0:3]
            for u in project_users:
                assignation = Assignation(employee=u, project=project)
                assignation.save()

        for u in User.objects.all():
            for year in [2011, 2012, 2013]:
                for month in MONTHS.keys():
                    part = Part()
                    part.month = month
                    part.year = year
                    part.employee = u
                    part.state = self.sd.choice(PART_STATE_CHOICES)[0]
                    part.save()

            for part in u.parts.all():
                part.data = {}
                for project in u.projects.all():
                    project_data = {day+1: self.sd.int(8) for day in range(monthrange(part.year, part.month)[1])}
                    part.data[project.id] = project_data

                part.save()
开发者ID:fatihzkaratana,项目名称:intranet,代码行数:32,代码来源:sample_data.py

示例10: render

	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,代码行数:33,代码来源:views.py

示例11: render

    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,代码行数:33,代码来源:widgets.py

示例12: __init__

 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,代码行数:9,代码来源:widgets.py

示例13: render

    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,代码行数:10,代码来源:cms_plugins.py

示例14: render

    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,代码行数:54,代码来源:widgets.py

示例15: __init__

    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,代码行数:11,代码来源:widgets.py


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