These are the whitelisted methods that dontmanage provides to use them in Jinja Templates.

dontmanage.format

dontmanage.format(value, df, doc)

Formats a raw value (stored in database) to a user presentable format. For example, convert 2019-09-08 to 08-09-2019

Usage

<div>{{ dontmanage.format('2019-09-08', {'fieldtype': 'Date'}) }}</div>
<!-- output -->
<div>09-08-2019</div>

dontmanage.format_date

dontmanage.format_date(date_string)

Formats date into a human readable long format.

Usage

<div>{{ dontmanage.format_date('2019-09-08') }}</div>
<!-- output -->
<div>September 8, 2019</div>

dontmanage.get_url

dontmanage.get_url()

Returns the site url

Usage

<div>{{ dontmanage.get_url() }}</div>
<!-- output -->
<div>https://dontmanage.io</div>

dontmanage.get_doc

dontmanage.get_doc(doctype, name)

Returns a document by its name.

Usage

<div>
    {% set doc = dontmanage.get_doc('Task', 'TASK00002') %}
    {{ doc.title }} - {{ doc.status }}
</div>
<!-- output -->
<div>
    Buy Eggs - Open
</div>

dontmanage.get_all

dontmanage.get_all(doctype, filters, fields, order_by, start, page_length, pluck)

Returns a list of all records of a DocType. Only returns the document names if the fields argument is not given.

Signature

dontmanage.get_all(doctype, filters, fields, order_by, start, page_length)

Usage

<div>
    {% set tasks = dontmanage.get_all('Task', filters={'status': 'Open'}, fields=['title', 'due_date'], order_by='due_date asc') %}
    {% for task in tasks %}
    <div>
<h3>{{ task.title }}</h3>
<p>Due Date: {{ dontmanage.format_date(task.due_date) }}</p>
</div>
    {% endfor %}
</div>
<!-- output -->
<div>
<div>
<h3>Redesign Website</h3>
<p>Due Date: September 8, 2019</p>
</div>
<div>
<h3>Add meta tags on websites</h3>
<p>Due Date: September 22, 2019</p>
</div>
</div>

dontmanage.get_list

dontmanage.get_list(doctype, filters, fields, order_by, start, page_length)

Similar to dontmanage.get_all but will filter records for the current session user based on permissions.

dontmanage.db.get_value

dontmanage.db.get_value(doctype, name, fieldname)

Returns a single field value (or a list of values) from a document.

Usage

<div>
<span>
        {% set company_abbreviation = dontmanage.db.get_value('Company', 'TennisMart', 'abbr') %}
        {{ company_abbreviation }}
    </span>
<div>
        {% set title, description = dontmanage.db.get_value('Task', 'TASK00002', ['title', 'description']) %}
        <h3>{{ title }}</h3>
<p>{{ description }}</p>
</div>
</div>
<!-- output -->
<div>
<span>TM</span>
</div>

dontmanage.db.get_single_value

dontmanage.db.get_single_value(doctype, fieldname)

Returns a field value from a Single DocType.

Usage

<div>
<span>
        {% set timezone = dontmanage.db.get_single_value('System Settings', 'time_zone') %}
        {{ timezone }}
    </span>
</div>
<!-- output -->
<div>
<span>
        Asia/Kolkata
    </span>
</div>

dontmanage.get_system_settings

dontmanage.get_system_settings(fieldname)

Returns a field value from System Settings.

Usage

<div>
    {% if dontmanage.get_system_settings('country') == 'India' %}
    <button>Pay via Razorpay</button>
    {% else %}
    <button>Pay via PayPal</button>
    {% endif %}
</div>
<!-- output -->
<div>
<button>Pay via Razorpay</button>
</div>

dontmanage.get_meta

dontmanage.get_meta(doctype)

Returns a doctype meta. It contains information like fields, title_field, image_field, etc.

Usage

<div>
<span>
        {% set meta = dontmanage.get_meta('Task') %}
        Task has {{ meta.fields | len }} fields.
        {% if meta.get_field('status') %}
        It also has a Status field.
        {% endif %}
    </span>
</div>
<!-- output -->
<div>
<span>
        Task has 18 fields. It also has a Status field.
    </span>
</div>

dontmanage.get_fullname

dontmanage.get_fullname(user_email)

Returns the fullname of the user email passed. If user is not passed, assumes current logged in user.

Usage

<div>
<span>The fullname of faris@dontmanageerp.com is {{ dontmanage.get_fullname('faris@dontmanageerp.com') }}</span>
<span>The current logged in user is {{ dontmanage.get_fullname() }}</span>
</div>
<!-- output -->
<div>
<span>The fullname of faris@dontmanageerp.com is Faris Ansari</span>
<span>The current logged in user is John Doe</span>
</div>

dontmanage.render_template

dontmanage.render_template(template_name, context)

Render a jinja template string or file with context.

Usage

<div>
<!-- render a jinja template file -->
    {{ dontmanage.render_template('templates/includes/footer/footer.html', {}) }}

    <!-- render a jinja template string -->
<p>{{ dontmanage.render_template('{{ foo }}', {'foo': 'bar'}) }}</p>
</div>
<!-- output -->
<div>
<footer class="web-footer">
<!-- full footer html -->
</footer>
<p>bar</p>
</div>

dontmanage._

dontmanage._(string) or _(string)

Usage

<div>
<p>{{ _('This string should get translated') }}</p>
</div>
<!-- output -->
<div>
<p>इस तार का अनुवाद होना चाहिए</p>
</div>

dontmanage.session.user

Returns the current session user

dontmanage.session.csrf_token

Returns the current session's CSRF token

dontmanage.form_dict

If the template is being evaluated in a web request, dontmanage.form_dict is a dict of query parameters, else it is None.

dontmanage.lang

Current language used by the translation function. Two letter, lowercase code.