class CreditCardPayment(Payment): """ Credit card """ MONTH_CHOICES = [(i, n) for i, n in sorted(MONTHS_3.items())] card_type = models.CharField(max_length=10) expiry_month = models.PositiveSmallIntegerField(choices=MONTH_CHOICES) expiry_year = models.PositiveIntegerField() class Meta: verbose_name = _("Credit Card Payment") verbose_name_plural = _("Credit Card Payments")
def _choices(pattern): if pattern == '%b': choices = MONTHS_3.items() choices.sort() elif pattern == '%B': choices = MONTHS.items() choices.sort() elif pattern == '%d': choices = [(i, i) for i in range(1, 32)] elif pattern == '%m': choices = [(i, i) for i in range(1, 13)] elif pattern == '%y': choices = [(i, str(i)[-2:]) for i in self.years] elif pattern == '%Y': choices = [(i, i) for i in self.years] if self.null and not self.null_label: self.null_label = mark_safe('—') if self.null_label: choices.insert(0, (None, self.null_label)) return tuple(choices)
def render(self, name, value, attrs=None): super().render(name, value, attrs) flat_attrs = flatatt(attrs) context = { 'name': name, 'attrs': flat_attrs, 'id': attrs['id'], 'closeText': _("Close"), 'currentText': _("Today"), 'dayNames': mark_safe(list2str((str(item[1]) for item in WEEKDAYS.items()))), 'dayNamesMin': mark_safe( list2str((str(item[1]) for item in WEEKDAYS_ABBR.items()))), 'dayNamesShort': mark_safe( list2str((str(item[1]) for item in WEEKDAYS_ABBR.items()))), 'firstDay': mark_safe('"' + str(WEEKDAYS[settings.FIRST_DAY_OF_WEEK]) + '"'), 'isRTL': str(get_language_bidi()).lower(), 'monthNames': mark_safe(list2str((str(item[1]) for item in MONTHS.items()))), 'monthNamesShort': mark_safe(list2str((str(item[1]) for item in MONTHS_3.items()))), 'nextText': mark_safe('"' + str(_('Next')) + '"'), 'prevText': mark_safe('"' + str(_('Previous')) + '"'), 'weekHeader': mark_safe('"' + str(_('Wk')) + '"'), } template = get_template('users/datetimepicker.html') return template.render(context)
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 month_choices = [(num, month.capitalize()) for num, month in MONTHS.items()] month_choices.sort() local_attrs = self.build_attrs(id=self.month_field % id_) s = Select(choices=month_choices) # Hacky: Jan 02 is a guard date that signifies that the resume # had listed only the year. Burning Glass interprets year only # durations as Jan 01 of that year. # See https://github.ksjc.sh.colo/apps-team/web-resumes/issues/71 if hasattr(value, 'day') and value.month == 1 and value.day == 2: select_html = s.render(self.month_field % name, '', local_attrs) else: 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] 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))
class AllSplittedDateTimeWidget(forms.widgets.MultiWidget): """ A Widget that splits datetime input into two <input type="text"> boxes. """ curr_year = datetime.today().year date_choices = [ MONTHS_3.items(), #months [(v, v) for v in range(1, 32)], #days [(curr_year + x, curr_year + x) for x in range(2)], #years, this and the next one [(x, '%02i' % x) for x in [12] + range(1, 12)], #hours [(x, '%02i' % x) for x in range(60)], [('AM', 'AM'), ('PM', 'PM')], ] #cardinality def __init__(self, attrs=None): widgets = tuple( forms.widgets.Select(attrs=attrs, choices=c) for c in self.date_choices) super(AllSplittedDateTimeWidget, self).__init__(widgets, attrs) def render(self, *args, **kargs): return super(AllSplittedDateTimeWidget, self).render(*args, **kargs) def format_output(self, widgets): return '%s %s %s <label class="inline">At</label> %s %s %s' % tuple( widgets) def decompress(self, value): if not value: value = datetime.today( ) #When no value, show today instead of all '1'. mer, hour = divmod(value.hour, 12) return [ value.month, value.day, value.year, hour, value.minute, ['AM', 'PM'][mer] ]