当前位置: 首页>>代码示例>>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;未经允许,请勿转载。