當前位置: 首頁>>代碼示例>>Python>>正文


Python defaultfilters.timesince方法代碼示例

本文整理匯總了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
            }
        } 
開發者ID:pbs,項目名稱:django-heartbeat,代碼行數:22,代碼來源:host.py

示例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)) 
開發者ID:CiscoSystems,項目名稱:avos,代碼行數:7,代碼來源:utils.py

示例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)) 
開發者ID:CiscoSystems,項目名稱:avos,代碼行數:7,代碼來源:utils.py

示例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) 
開發者ID:CiscoSystems,項目名稱:avos,代碼行數:14,代碼來源:tables.py

示例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') 
開發者ID:astrobin,項目名稱:astrobin,代碼行數:33,代碼來源:__init__.py

示例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) 
開發者ID:astrobin,項目名稱:astrobin,代碼行數:12,代碼來源:tags.py


注:本文中的django.template.defaultfilters.timesince方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。