Print Format Jinja Issue

Hello,
In my project I need to convert from Gregorian to Arabic Hijri date, I need to print the current printing date in Hijri
This is my code, I use umalqurra library for that:

from umalqurra.hijri_date import HijriDate
import datetime

def hijry():
	datee = datetime.datetime.strptime(frappe.utils.today(), "%Y-%m-%d")
	um = HijriDate(datee.year,datee.month,datee.day,gr=True)
	print int(um.year), um.month_name , int(um.day)

I change this code to jinja like follow:

{% set datee = datetime.datetime.strptime(frappe.utils.today(), "%Y-%m-%d") %}
{% set um = HijriDate(datee.year,datee.month,datee.day,gr=True) %}        
{{ int(um.day) }}

When I check print format, it shows this error

UndefinedError: ‘datetime’ is undefined

I try to include it in jinja like this :

{% import datetime %}
{% from umalqurra.hijri_date import HijriDate %}

But it still the same!
Any solution
thanks

1 Like

We only allow limited methods in Jinja for security reasons.

See https://github.com/frappe/frappe/blob/develop/frappe/utils/jinja.py#L104

1 Like

I solve it by adding my function in the utils with importing code
and then call it in jinja using
{{ frappe.get_hijry() }}

1 Like

it will get overwritten next bench update …

1 Like

try to create ur method in ur custom app dont update in frappe codebase it will be overwritten when u do bench update

1 Like

@hereabdulla @JoEz
thanks , we chose stable frappe to be fixed in project