Script API
List of restricted commands that be called in DontManage Framework Server Script, Print Formats and Script Reports
Note: This is only applicable for in-app scripting. If you want more features, you will have to create an "Application" and write the event handlers inside Python Modules
Python Modules
Following python modules are available
json
Python standard module json
Formatting
_ (Translate)
Translate a string
Example: _("This is translatable")
dontmanage.format
Format a value based on its datatype
Example: dontmanage.format_value(value, dict(fieldtype='Currency'))
dontmanage.date_format
Format as default date format
dontmanage.format_date
Returns date as "1st September 2019"
Session
dontmanage.form_dict
Form / request parameters
Example: Request parameter /page?name="test" can be accesssed as dontmanage.form_dict.name
dontmanage.request
Request object
dontmanage.response
Response object
dontmanage.session.user
Current user
dontmanage.session.csrf_token
CSRF token of the current session
dontmanage.user
Current user
dontmanage.get_fullname
Returns fullname of the current user
dontmanage.get_gravatar
Gets the user display image from dontmanage.utils.get_gravatar_url
dontmanage.full_name
Fullname of the current user
Documents (ORM)
Document access and editing
dontmanage.get_meta
Get metadata object
dontmanage.new_doc
Create a new Document record.
dontmanage.get_doc
Get Document. You can also save or execute any method exposed by the document.
Example: dontmanage.get_doc("User", dontmanage.session.user)
dontmanage.get_last_doc
Get the last Document of a particular DocType with a given set of filters. Defaults to last created.
Example: dontmanage.get_last_doc("User", filters={"name": ("like", "%@apple.com")})
dontmanage.get_cached_doc
Get Document (or cached)
dontmanage.get_mapped_doc
dontmanage.rename_doc
dontmanage.delete_doc
dontmanage.get_system_settings
Get system default settings
Database
Database access API
dontmanage.db.get_list
Get list of record filtered by current user's permissions
Example: dontmanage.db.get_list("Customer") will return list of customers
dontmanage.db.get_all
Get list of all records
dontmanage.db.sql
Run a SELECT query
Example: dontmanage.db.sql("select name from Customer where name like 'm%'")
dontmanage.db.get_value
Get a value from a record
Example: dontmanage.db.get_value("User", dontmanage.session.user, "first_name")
dontmanage.db.get_single_value
Get value from a single type document
Example: dontmanage.db.get_single_value("System Settings", "default_currency")
dontmanage.db.get_default
Get default value
dontmanage.db.escape
Sanitize value for database queries to prevent SQL injection
dontmanage.db.set_value
Set a value
dontmanage.db.exists
Checks for existence of a document. Returns name of the document if exists else None.
dontmanage.db.commit
Allow users to make explicit commits in server scripts like custom scheduler scripts.
Note: This won't work in any DocType Event server scripts
dontmanage.db.rollback
Allow users to rollback changes via server scripts.
Note: This won't work in any DocType Event server scripts
Cache Methods
Available cache methods
dontmanage.cache.set_value
Set a value in cache for a specific key
Example: dontmanage.cache().set_value("test_key", "test_value")
dontmanage.cache.get_value
Get a value from cache for a specific key
Example: dontmanage.cache().get_value("test_key")
dontmanage.cache.hset
Set a value in cache for a specific key for a specific named record
Example: dontmanage.cache().hset("sales_invoice", "test_key", "test_value")
dontmanage.cache.hget
Get a value from cache for a specific key for a specific named record
Example: dontmanage.cache().hget("sales_invoice", "test_key")
Query Builder
dontmanage.qb
Query builder API to run SELECT queries.
Example: dontmanage.qb.from_("Task").select("*").run()
Utilities
Utility methods and functions
run_script
Run a server script (return values in dontmanage.flags)
dontmanage.msgprint
Show a modal on the server side after as a part of the response.
Example: dontmanage.msgprint("Hello")
dontmanage.get_hooks
Get application hooks
dontmanage.utils
Methods in dontmanage.utils
dontmanage.render_template
Render a Jinja template
dontmanage.get_url
Get url of the current site via dontmanage.utils.get_url
socketio_port
Port for socketio
style.border_color
Returns '#d1d8dd'
guess_mimetype
Returns mimetypes.guess_type
html2text
Encode HTML as text (markdown)
dev_server
True if in developer mode
dontmanage.log_error
Generate Error Log with a traceback
DontManageClient
Connect to a DontManage site using a requests session
API
Make external API calls from DontManage.
dontmanage.make_get_request
Make a GET request.
Example: dontmanage.make_get_request('https://example.com')
dontmanage.make_post_request
Make a POST request.
Example: dontmanage.make_post_request('https://example.com', data={'username: 'test'})
dontmanage.make_put_request
Make a PUT request.
Example: dontmanage.make_put_request('https://example.com', headers={'Auth': 'Bearer xyz'})
dontmanage.sendmail
Send an email. See docs
Example: dontmanage.sendmail(recipients=['test@example.com'], sender='sender@example.com', subject='My Subject', message='<p>Hello</p>')