Skip to content

Instantly share code, notes, and snippets.

@khamidou
Created June 5, 2012 19:12
Show Gist options
  • Save khamidou/2877088 to your computer and use it in GitHub Desktop.
Save khamidou/2877088 to your computer and use it in GitHub Desktop.
An example filter
from django import template
from django.contrib.sites.models import Site
from urlparse import urlparse
import datetime
register = template.Library()
@register.filter(name='dayinweek', is_safe=True, expects_localtime=True)
def dayincurrentweek(day):
if day == datetime.date.today():
return "Today"
min_date = datetime.date.today() - datetime.timedelta(7)
if day > min_date and day < datetime.date.today():
return day.strftime("Last %A")
else:
return day.strftime("%B, %d")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment