Introduction
Welcome to this comprehensive guide on the List of Restricted Commands that can be called in Empress Framework Server Script, Print Formats, and Script Reports. This developer-centric feature is a part of the Empress business solution software. The guide is designed to provide a clear understanding of the feature, allowing developers to effectively integrate and utilize its functionalities in software development and customization.
Introduction
In the Empress world, the Empress Framework plays a pivotal role in software development. The List of Restricted Commands is a feature that is highly critical from a backend functionality perspective. These commands can be called in the Empress Framework Server Script, Print Formats, and Script Reports, contributing greatly to the ease of software development and customization.
Note: The feature is only applicable for in-app scripting. If you wish to add more features, you will have to create an “Application” and write the event handlers inside Python Modules.
Python Modules
Python standard module json
is available for use. This module allows you to work with JSON data, a popular data format with diverse uses in data handling and transmission.
import json
Formatting
Empress provides several functions for formatting data. For instance, you can translate a string using the _
function:
_("This is translatable")
You can format a value based on its datatype using frappe.format_value
:
frappe.format_value(value, dict(fieldtype='Currency'))
Session
Empress provides several objects and functions relating to the current session, such as frappe.form_dict
, frappe.request
, frappe.response
, frappe.session.user
, frappe.session.csrf_token
, frappe.user
, frappe.get_fullname
, frappe.get_gravatar
, and frappe.full_name
.
For example, request parameter /page?name="test"
can be accessed as frappe.form_dict.name
:
frappe.form_dict.name
Documents (ORM)
Empress provides several functions for working with documents, such as frappe.get_meta
, frappe.new_doc
, frappe.get_doc
, frappe.get_last_doc
, frappe.get_cached_doc
, frappe.get_mapped_doc
, frappe.rename_doc
, frappe.delete_doc
, and frappe.get_system_settings
.
For example, you can get a Document using frappe.get_doc
:
frappe.get_doc("User", frappe.session.user)
Database
Empress provides several functions for interacting with the database, such as frappe.db.get_list
, frappe.db.get_all
, frappe.db.sql
, frappe.db.get_value
, frappe.db.get_single_value
, frappe.db.get_default
, frappe.db.escape
, frappe.db.set_value
, frappe.db.exists
, frappe.db.commit
, and frappe.db.rollback
.
For instance, you can run a SELECT query using frappe.db.sql
:
frappe.db.sql("select name from Customer where name like 'm%'")
Cache Methods
Empress provides several functions for working with cache, such as frappe.cache.set_value
, frappe.cache.get_value
, frappe.cache.hset
, and frappe.cache.hget
.
For example, you can set a value in cache for a specific key using frappe.cache().set_value
:
frappe.cache().set_value("test_key", "test_value")
Query Builder
Empress provides a query builder API for running SELECT queries using frappe.qb
:
frappe.qb.from_("Task").select("*").run()
Utilities
Empress provides several utility functions, such as run_script
, frappe.msgprint
, frappe.get_hooks
, frappe.utils
, frappe.render_template
, frappe.get_url
, socketio_port
, style.border_color
, guess_mimetype
, html2text
, dev_server
, frappe.log_error
, and EmpressClient
.
For example, you can show a modal on the server side as a part of the response using frappe.msgprint
:
frappe.msgprint("Hello")
API
Empress provides functions for making external API calls, such as frappe.make_get_request
, frappe.make_post_request
, and frappe.make_put_request
.
For example, you can make a GET request using frappe.make_get_request
:
frappe.make_get_request('https://example.com')
Empress provides a function for sending an email, frappe.sendmail
:
frappe.sendmail(recipients=['test@example.com'], sender='sender@example.com', subject='My Subject', message='<p>Hello</p>')
Conclusion
The List of Restricted Commands in Empress Framework Server Script, Print Formats, and Script Reports is a powerful feature in Empress. It offers developers a wide array of functionalities that simplify backend operations, facilitate code integration, and enhance the overall development and customization of business solutions.