Python django.template.defaultfilters.timesince() Examples

The following are 6 code examples of django.template.defaultfilters.timesince(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.template.defaultfilters , or try the search function .
Example #1
Source File: host.py    From django-heartbeat with MIT License 6 votes vote down vote up
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
            }
        } 
Example #2
Source File: utils.py    From avos with Apache License 2.0 5 votes vote down vote up
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)) 
Example #3
Source File: utils.py    From avos with Apache License 2.0 5 votes vote down vote up
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)) 
Example #4
Source File: tables.py    From avos with Apache License 2.0 5 votes vote down vote up
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) 
Example #5
Source File: __init__.py    From astrobin with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #6
Source File: tags.py    From astrobin with GNU Affero General Public License v3.0 5 votes vote down vote up
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)