Skip to content

Instantly share code, notes, and snippets.

@amiroff
Created January 6, 2011 09:56
Show Gist options
  • Save amiroff/767722 to your computer and use it in GitHub Desktop.
Save amiroff/767722 to your computer and use it in GitHub Desktop.
Django template filter that returns appropriate zodiac for a given date (in Turkish)
register = template.Library()
@register.filter(name='zodiac')
def zodiac(value):
""" Return appropriate zodiac for a given date
Usage in templates: {{ your_object.date_of_birth|zodiac }} """
signs = (
(u"Oğlak", range(356, 365)),
(u"Oğlak", range(1, 20)),
(u"Kova", range(21, 52)),
(u"Balık", range(52, 79)),
(u"Koç", range(79, 111)),
(u"Boğa", range(111, 141)),
(u"İkizler", range(141, 173)),
(u"Yengeç", range(173, 204)),
(u"Aslan", range(204, 236)),
(u"Başak", range(236, 267)),
(u"Terazi", range(267, 297)),
(u"Akrep", range(297, 327)),
(u"Yay", range(327, 355))
)
birthday_day_of_year = value.timetuple()[7]
for sign, days in signs:
if birthday_day_of_year in days:
return sign
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment