本文整理汇总了Python中django.template.defaultfilters.timesince方法的典型用法代码示例。如果您正苦于以下问题:Python defaultfilters.timesince方法的具体用法?Python defaultfilters.timesince怎么用?Python defaultfilters.timesince使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.defaultfilters
的用法示例。
在下文中一共展示了defaultfilters.timesince方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import timesince [as 别名]
def check(request):
return {
'hostname': socket.gethostname(),
'ips': ips,
'cpus': psutil.cpu_count(),
'uptime': timesince(datetime.fromtimestamp(psutil.boot_time())),
'memory': {
'total': filesizeformat(psutil.virtual_memory().total),
'available': filesizeformat(psutil.virtual_memory().available),
'used': filesizeformat(psutil.virtual_memory().used),
'free': filesizeformat(psutil.virtual_memory().free),
'percent': psutil.virtual_memory().percent
},
'swap': {
'total': filesizeformat(psutil.swap_memory().total),
'used': filesizeformat(psutil.swap_memory().used),
'free': filesizeformat(psutil.swap_memory().free),
'percent': psutil.swap_memory().percent
}
}
示例2: test_timesince_or_never_returns_same_output_as_django_date
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import timesince [as 别名]
def test_timesince_or_never_returns_same_output_as_django_date(self):
d = datetime.date(year=2014, month=3, day=7)
c = django.template.Context({'date': d})
t = django.template.Template('{{date|timesince_or_never}}')
self.assertEqual(defaultfilters.timesince(d), t.render(c))
示例3: test_timesince_or_never_returns_same_output_as_django_datetime
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import timesince [as 别名]
def test_timesince_or_never_returns_same_output_as_django_datetime(self):
now = datetime.datetime.now()
c = django.template.Context({'date': now})
t = django.template.Template('{{date|timesince_or_never}}')
self.assertEqual(defaultfilters.timesince(now), t.render(c))
示例4: test_broken_filter
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import timesince [as 别名]
def test_broken_filter(self):
class MyTableBrokenFilter(MyTable):
value = tables.Column('value',
filters=(defaultfilters.timesince,))
value = "not_a_date"
data = TEST_DATA[0]
data.value = value
table = MyTableBrokenFilter(self.request, [data])
resp = http.HttpResponse(table.render())
self.assertContains(resp, value)
示例5: user_popover_ajax
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import timesince [as 别名]
def user_popover_ajax(request, username):
profile = get_object_or_404(UserProfile, user__username=username)
template = 'popover/user.html'
from django.template.defaultfilters import timesince
date_time = profile.user.date_joined.replace(tzinfo=None)
span = timesince(date_time)
span = span.split(",")[0] # just the most significant digit
if span == "0 " + _("minutes"):
member_since = _("seconds ago")
else:
member_since = _("%s ago") % span
html = render_to_string(template,
{
'user': profile.user,
'images': Image.objects.filter(user=profile.user).count(),
'member_since': member_since,
'is_authenticated': request.user.is_authenticated(),
'request': request,
})
response_dict = {
'success': True,
'html': html,
}
return HttpResponse(
simplejson.dumps(response_dict),
content_type='application/javascript')
示例6: ago
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import timesince [as 别名]
def ago(date_time):
date_time = date_time.replace(tzinfo=None)
diff = abs(date_time - datetime.today())
if diff.days <= 0:
span = timesince(date_time)
span = span.split(",")[0] # just the most significant digit
if span == "0 " + _("minutes"):
return _("seconds ago")
return _("%s ago") % span
return datetime.date(date_time)