本文整理汇总了Python中django.template.defaultfilters.date方法的典型用法代码示例。如果您正苦于以下问题:Python defaultfilters.date方法的具体用法?Python defaultfilters.date怎么用?Python defaultfilters.date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.defaultfilters
的用法示例。
在下文中一共展示了defaultfilters.date方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _validator
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def _validator(self, value):
"""
Validate the allowed_dates restrictions on the field.
"""
allowed = self.config.get('allowed_dates', 'AL')
today = datetime.date.today()
if allowed == 'AL':
pass
elif allowed == 'LT' and value >= today:
raise forms.ValidationError("The date must be before today.")
elif allowed == 'LE' and value > today:
raise forms.ValidationError("The date cannot be in the future.")
elif allowed == 'GT' and value <= today:
raise forms.ValidationError("The date must be after today.")
elif allowed == 'GE' and value < today:
raise forms.ValidationError("The date cannot be past.")
示例2: test_render
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def test_render(self):
expected_html = (
' <td>'
' <div class="media-left">'
' <img src="{thumbnail}"'
' class="thumb-60">'
' </div>'
' <div class="media-body resource-text">'
' <label for="file"><strong>Resource Name</strong></label>'
' <br>file.txt'
' </div>'
' </td>'
' <td class="hidden-xs hidden-sm">txt</td>'
' <td class="hidden-xs hidden-sm">'
' john<br>'
' John Lennon</td>'
' <td class="hidden-xs hidden-sm">{updated}</td>'
' <td class="hidden-xs hidden-sm">Attached to 1 other entity</td>'
)
widget = ResourceWidget(resource=self.resource)
rendered = widget.render('file', True)
assert expected_html.format(
updated=date(self.resource.last_updated, 'N j, Y, P'),
thumbnail=self.resource.thumbnail
) in rendered
示例3: month
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def month(value):
"""
Provides the month from a provided date as a string.
This is used to work around a bug in the Spanish django month translations.
See LEARNER-3859 for more details.
Arguments:
value (datetime): date to format
Returns:
string: A formatted version of the month
"""
formatted = date(value, 'E')
language = get_language()
if language and language.split('-')[0].lower() == 'es':
return formatted.lower()
return formatted
示例4: relative_date
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def relative_date(value):
if value in ('', None):
return ''
current = timezone.now()
if (current - value) > timedelta(days=1):
return date(value, "SHORT_DATETIME_FORMAT")
return naturaltime(value)
示例5: __unicode__
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def __unicode__(self):
return _date(self.day, "Y-m-d (D)")
示例6: make_entry_field
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def make_entry_field(self, fieldsubmission=None):
c = forms.DateField(required=self.config['required'],
label=self.config['label'],
validators=[self._validator],
help_text=self.config['help_text'])
c.widget.attrs['class'] = 'date-input' # a JS chunk uses the class to turn on the datepicker.
if fieldsubmission:
c.initial = fieldsubmission.data['info']
return c
示例7: _to_text
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def _to_text(self, fieldsubmission=None, format=settings.DATE_FORMAT):
if fieldsubmission.data['info']:
d = datetime.datetime.strptime(fieldsubmission.data['info'], '%Y-%m-%d').date()
return escape(defaultfilters.date(d, format))
else:
return 'not entered'
示例8: timestamp_to_string
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def timestamp_to_string(ts):
return django_date(
datetime.datetime.fromtimestamp(int(ts)),
'SHORT_DATETIME_FORMAT')
示例9: naturalday
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def naturalday(value, arg=None):
"""
For date values that are tomorrow, today or yesterday compared to
present day returns representing string. Otherwise, returns a string
formatted according to settings.DATE_FORMAT.
"""
try:
tzinfo = getattr(value, 'tzinfo', None)
value = date(value.year, value.month, value.day)
except AttributeError:
# Passed value wasn't a date object
return value
except ValueError:
# Date arguments out of range
return value
today = datetime.now(tzinfo).date()
delta = value - today
if delta.days == 0:
return _('today')
elif delta.days == 1:
return _('tomorrow')
elif delta.days == -1:
return _('yesterday')
return defaultfilters.date(value, arg)
# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
示例10: format_data_movimento
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_movimento(self):
return '%s' % date(self.data_movimento, "d/m/Y")
示例11: format_data_emissao
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_emissao(self):
return '%s' % date(self.data_emissao, "d/m/Y")
示例12: format_data_vencimento
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_vencimento(self):
return '%s' % date(self.data_vencimento, "d/m/Y")
示例13: format_data_entrega
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_entrega(self):
return '%s' % date(self.data_entrega, "d/m/Y")
示例14: format_data_emissao
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_emissao(self):
return '%s' % date(self.dhemi.date(), "d/m/Y")
示例15: naturalday
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def naturalday(value, arg=None):
"""
For date values that are tomorrow, today or yesterday compared to
present day return representing string. Otherwise, return a string
formatted according to settings.DATE_FORMAT.
"""
try:
tzinfo = getattr(value, 'tzinfo', None)
value = date(value.year, value.month, value.day)
except AttributeError:
# Passed value wasn't a date object
return value
except ValueError:
# Date arguments out of range
return value
today = datetime.now(tzinfo).date()
delta = value - today
if delta.days == 0:
return _('today')
elif delta.days == 1:
return _('tomorrow')
elif delta.days == -1:
return _('yesterday')
return defaultfilters.date(value, arg)
# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.