django-tz-detect
django-tz-detect copied to clipboard
Add Django-Jinja2 template engine support.
A feature proposal.
I have a need to implement Django-Jinja2 template engine support. I plan to use it in commercial product and I am at a deadline. I have read Writing Extensions Create Jinja extensions and I don't know how solve it myself.
I solved with this small JS jsTimezoneDetect from Jon Nylander. I pass jstz timezone name to a hidden form field value. In Django backend call I have this so called "MVP" unpolished code.
try:
current_tz = pytz.timezone(post.get('timezone_name'))
except:
current_tz = timezone.get_current_timezone()
try:
naive_datetime = timezone.datetime.strptime(
post.get('date'), '%d.%m.%Y'
) + timezone.timedelta(
hours=int(post.get('time')[0:2]),
minutes=int(post.get('time')[3:])
)
call_date = current_tz.localize(naive_datetime)
except:
pass