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. Widget for CommaSeparatedIntegerField with pre-defined choices by rudyryk 1 year, 8 months ago
  2. SplitTimeField by theju 4 years ago
  3. Show users' full names for foreign keys in admin by SmileyChris 2 years, 6 months ago
  4. Faster pagination / model object seeking (10x faster infact :o) for larger datasets (500k +) by sleepycal 1 year, 2 months ago
  5. Paginator template tag using ObjectPaginator by Batiste 4 years, 9 months ago

Comments

(Forgotten your password?)