Login

Time toggle on mouseover template filter

Author:
soniiic
Posted:
April 22, 2009
Language:
Python
Version:
1.0
Tags:
date time usability time-toggle
Score:
2 (after 2 ratings)

Shows the timesince to the user and then on mouseover it will display the exact time for allowing the user to see the exact time. Example: shows "about 1 day, 3 hours ago" and then changes on mouseover to read "at 3:05pm on Wednesday 22nd April 2009"

 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 4 years, 10 months ago
  2. LocaleMiddleware without browser language discovery by ivellios 1 month, 2 weeks ago
  3. model save memos by depaolim 1 year, 10 months ago
  4. Full Model History by willhardy 6 years, 4 months ago
  5. Show users' full names for foreign keys in admin by SmileyChris 5 years, 9 months ago

Comments

Please login first before commenting.