django-tz-detect icon indicating copy to clipboard operation
django-tz-detect copied to clipboard

Add Django-Jinja2 template engine support.

Open denis-trofimov opened this issue 7 years ago • 1 comments

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.

denis-trofimov avatar Dec 11 '18 14:12 denis-trofimov

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

denis-trofimov avatar Dec 11 '18 17:12 denis-trofimov