本文整理匯總了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)