Skip to content

Instantly share code, notes, and snippets.

@michaelhjulskov
Last active August 29, 2015 14:05
Show Gist options
  • Save michaelhjulskov/e500a7039b248b2495de to your computer and use it in GitHub Desktop.
Save michaelhjulskov/e500a7039b248b2495de to your computer and use it in GitHub Desktop.
friendly greetings
def friendly_signature_line():
i = datetime.now()
day_num_in_week = int(i.strftime("%w"))
month_num = int(i.strftime("%m"))
day_num_in_month = int(i.strftime("%d"))
hour_num = int(i.strftime("%H"))
if month_num == 12 and day_num_in_month > 12 and day_num_in_month < 26:
return _("We wish you Merry Christmas & Happy New Year")
if month_num == 12 and day_num_in_month > 25:
return _("We wish you a Happy New Year")
if day_num_in_week == 4:
return _("Have a good weekend")
if day_num_in_week == 5:
return _("Have a nice Saturday")
if day_num_in_week == 6:
return _("Have a nice Sunday")
if hour_num > 18:
return _("Have a nice evening")
return _("Have a nice day")
def friendly_greeting_hello(name=False):
if not name:
return _("Dear Customer")
i = datetime.now()
hour_num = int(i.strftime("%H"))
if hour_num > 18:
return _("Good evening %s") % name
if hour_num >= 13 and hour_num <= 16:
return _("Good afternoon %s") % name
if hour_num >= 10 and hour_num < 12:
return _("God formiddag %s") % name
if hour_num >= 5 and hour_num < 10:
return _("Good morning %s") % name
return _("Dear %s") % name
-----------------
a simple templatetag could be:
#templatetags/greeting_tags.py
register = template.Library()
@register.filter
def as_friendly_hello(name):
return friendly_greeting_hello(name)
--------------------------
example usage
{% load greeting_tags %}
{{ name|as_friendly_hello }}
.....
@codeinthehole
Copy link

If you name the gist greetings.py then it will be rendered with syntax highlighting (which makes it easier to read).

@michaelhjulskov
Copy link
Author

Ahh thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment