Time toggle on mouseover template filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from django.utils import timesince, dateformat

@register.filter
def timetoggle(time, id):
	link = "<span id=\""+str(id) + "timesince\"> about <a href=\"#\" onmouseover=\"document.getElementById('"+str(id)+"timeactual').style.display=''; document.getElementById('"+str(id)+"timesince').style.display='none';return false;\">"
	link += timesince.timesince(time)
	link += " ago</a> </span><span id=\""+str(id)+"timeactual\" style='display:none'> at <a href=\"#\" onmouseout=\"document.getElementById('"+str(id)+"timeactual').style.display='none'; document.getElementById('"+str(id)+"timesince').style.display='';return false;\">"
	link += dateformat.DateFormat(time).format("g:ia o\\n l jS N Y")
	link += "</a></span>"
	return mark_safe(link)

More like this

  1. Timedelta template tag by dballanc 6 years ago
  2. SplitSelectDateTimeWidget by bradmontgomery 4 years, 6 months ago
  3. Date/time util template filters by marinho 5 years, 6 months ago
  4. Days Since Filter by joe4444 6 years, 2 months ago
  5. humanize time difference (how long ago) by supsupmo 5 years, 8 months ago

Comments

(Forgotten your password?)