Astrological sign theme filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@register.filter
def astrological_sign(bday):
    if bday.month == 1 and bday.day >= 20 or bday.month == 2 and bday.day < 18:
        return 'aquarius'
    if bday.month == 2 and bday.day >= 18 or bday.month == 3 and bday.day < 20:
        return 'pisces'
    if bday.month == 3 and bday.day >= 20 or bday.month == 4 and bday.day < 20:
        return 'aries'
    if bday.month == 4 and bday.day >= 20 or bday.month == 5 and bday.day < 21:
        return 'taurus'
    if bday.month == 5 and bday.day >= 21 or bday.month == 6 and bday.day < 21:
        return 'gemini'
    if bday.month == 6 and bday.day >= 21 or bday.month == 7 and bday.day < 22:
        return 'cancer'
    if bday.month == 7 and bday.day >= 22 or bday.month == 8 and bday.day < 23:
        return 'leo'
    if bday.month == 8 and bday.day >= 23 or bday.month == 9 and bday.day < 23:
        return 'virgo'
    if bday.month == 9 and bday.day >= 23 or bday.month == 10 and bday.day < 23:
        return 'libra'
    if bday.month == 10 and bday.day >= 23 or bday.month == 11 and bday.day < 22:
        return 'scorpio'
    if bday.month == 11 and bday.day >= 22 or bday.month == 12 and bday.day < 22:
        return 'sagittarius'
    return 'capricorn'

More like this

  1. Amazon's CloudFront streaming signed urls by sayane 3 years, 7 months ago
  2. S/MIME Encrypted E-mail by bthomas 4 years, 8 months ago
  3. Securely Signed S3 Links With Expiration by pjs 5 years, 5 months ago
  4. Sign a string using SHA1, then shrink it using url-safe base65 by simon 5 years, 7 months ago
  5. (en-US) Humanized Decimal Field by ActionScripted 5 years, 9 months ago

Comments

willhardy (on November 18, 2010):

Here is a more pythonic version:

# Dictionary mapping month number to a function that takes a
# day and returns the sign. Use like this: SIGNS[month](day)
SIGNS = {
  1: lambda d: d >= 20 and 'aquarius' or 'capricorn',
  2: lambda d: d >= 18 and 'pisces' or 'aquarius',
  3: lambda d: d >= 20 and 'aries' or 'pisces',
  4: lambda d: d >= 20 and 'taurus' or 'aries',
  5: lambda d: d >= 21 and 'gemini' or 'taurus',
  6: lambda d: d >= 21 and 'cancer' or 'gemini',
  7: lambda d: d >= 22 and 'leo' or 'cancer',
  8: lambda d: d >= 23 and 'virgo' or 'leo',
  9: lambda d: d >= 23 and 'libra' or 'virgo',
  10: lambda d: d >= 23 and 'scorpio' or 'libra',
  11: lambda d: d >= 22 and 'sagittarius' or 'scorpio',
  12: lambda d: d >= 22 and 'capricorn' or 'sagittarius',
}

@register.filter
def astrological_sign(bday):
  return SIGNS[bday.month](bday.day)

#

sberlotto (on November 18, 2010):

Great filter macat. Great version willhardy!

#

(Forgotten your password?)