mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Added natural times to profile view
This commit is contained in:
33
sso/templatetags/naturaltimediff.py
Normal file
33
sso/templatetags/naturaltimediff.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
MOMENT = 120 # duration in seconds within which the time difference
|
||||
# will be rendered as 'a moment ago'
|
||||
|
||||
@register.filter
|
||||
def naturaltimediff(value):
|
||||
"""
|
||||
Finds the difference between the datetime value given and now()
|
||||
and returns appropriate humanize form
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
if isinstance(value, datetime):
|
||||
delta = datetime.now() - value
|
||||
if delta.days > 6:
|
||||
return value.strftime("%b %d") # May 15
|
||||
if delta.days > 1:
|
||||
return value.strftime("%A") # Wednesday
|
||||
elif delta.days == 1:
|
||||
return 'yesterday' # yesterday
|
||||
elif delta.seconds > 3600:
|
||||
return str(delta.seconds / 3600 ) + ' hours ago' # 3 hours ago
|
||||
elif delta.seconds > MOMENT:
|
||||
return str(delta.seconds/60) + ' minutes ago' # 29 minutes ago
|
||||
else:
|
||||
return 'a moment ago' # a moment ago
|
||||
return defaultfilters.date(value)
|
||||
else:
|
||||
return str(value)
|
||||
@@ -1,5 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% load naturaltimediff %}
|
||||
|
||||
{% block title %}Your Profile{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@@ -64,7 +66,7 @@ setup.</p>
|
||||
<td>{{ acc.api_key }}</td>
|
||||
<td>{{ acc.description }}</td>
|
||||
<td>{{ acc.api_status_description }}</td>
|
||||
<td>{{ acc.api_last_updated }}</td>
|
||||
<td>{{ acc.api_last_updated|naturaltimediff }}</td>
|
||||
<td><a href="/profile/refresh/eveapi/{{ acc.api_user_id }}/">Refresh</a>,
|
||||
<a href="/profile/del/eveapi/{{ acc.api_user_id }}/">Delete</a></td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user