globals attached to frappe module + some utility functions that should probably be moved
Returns translated string in current lang, if exists.
Inherits from __builtin__.dict
dict like object that exposes keys as attributes
No docs
No docs
__setattr__ (self, key, value)
No docs
No docs
No docs
update and return self -- the missing dict feature in python
Insert a new Version of the given document. A Version is a JSON dump of the current document state.
No docs
frappe.as_json (obj, indent=1)
No docs
frappe.attach_print (doctype, name, file_name=None, print_format=None, style=None, html=None)
No docs
frappe.build_match_conditions (doctype, as_condition=True)
Return match (User permissions) for given doctype as list or SQL.
Returns memcache connection.
Call a function and match arguments.
frappe.clear_cache (user=None, doctype=None)
Clear User, DocType or global cache.
Parameters:
user
- If user is given, only user cache is cleared.doctype
- If doctype is given, only DocType cache is cleared.frappe.compare (val1, condition, val2)
Compare two values using frappe.utils.compare
condition
could be:
- "^"
- "in"
- "not in"
- "="
- "!="
- ">"
- "<"
- ">="
- "<="
- "not None"
- "None"
frappe.connect (site=None, db_name=None)
Connect to site database instance.
Parameters:
site
- If site is given, calls frappe.init
.db_name
- Optional. Will use from site_config.json
.frappe.copy_doc (doc, ignore_no_copy=True)
No_copy fields also get copied.
frappe.create_folder (path, with_init=False)
Create a folder in the given path and add an __init__.py
file (optional).
Parameters:
path
- Folder path.with_init
- Create __init__.py
in the new folder.frappe.delete_doc (doctype=None, name=None, force=0, ignore_doctypes=None, for_reload=False, ignore_permissions=False, flags=None)
Delete a document. Calls frappe.model.delete_doc.delete_doc
.
Parameters:
doctype
- DocType of document to be delete.name
- Name of document to be delete.force
- Allow even if document is linked. Warning: This may lead to data integrity errors.ignore_doctypes
- Ignore if child table is one of these.for_reload
- Call before_reload
trigger before deleting.ignore_permissions
- Ignore user permissions.frappe.delete_doc_if_exists (doctype, name, force=0)
Delete document if exists.
Closes connection and releases werkzeug local.
Log error. This is sent back as exc
in response.
Parameters:
msg
- Message.frappe.format_value (value, df, doc=None, currency=None)
Format value with given field properties.
Parameters:
value
- Value to be formatted.df
- DocField object with properties fieldtype
, options
etc.frappe.generate_hash (txt=None, length=None)
Generates random hash for given text + current timestamp + random string.
List database query via frappe.model.db_query
. Will not check for conditions.
Parameters are same as frappe.get_list
Parameters:
doctype
- DocType on which query is to be made.fields
- List of fields or *
. Default is: ["name"]
.filters
- List of filters (see example).order_by
- Order By e.g. modified desc
.limit_page_start
- Start results at record #. Default 0.limit_poge_length
- No of records in the page. Default 20.Example usage:
# simple dict filter
frappe.get_all("ToDo", fields=["name", "description"], filters = {"owner":"test@example.com"})
# filter as a list of lists
frappe.get_all("ToDo", fields=["*"], filters = [["modified", ">", "2014-01-01"]])
# filter as a list of dicts
frappe.get_all("ToDo", fields=["*"], filters = {"description": ("like", "test%")})
frappe.get_all_apps (with_frappe=False, with_internal_apps=True, sites_path=None)
Get list of all apps via sites/apps.txt
.
frappe.get_app_path (app_name)
Return path of given app.
Parameters:
app
- App name.*joins
- Join additional path elements using os.path.join
.frappe.get_attr (method_string)
Get python method object from its name.
frappe.get_doc (arg1, arg2=None)
Return a frappe.model.document.Document
object of the given type and name.
Parameters:
arg1
- DocType name as string or document JSON.arg2
- [optional] Document name as string.Examples:
# insert a new document
todo = frappe.get_doc({"doctype":"ToDo", "description": "test"})
tood.insert()
# open an existing document
todo = frappe.get_doc("ToDo", "TD0001")
frappe.get_doctype_app (doctype)
No docs
frappe.get_file_items (path, raise_not_found=False, ignore_empty_lines=True)
Returns items from text file as a list. Ignores empty lines.
Read a file and return parsed JSON object.
frappe.get_hooks (hook=None, default=None, app_name=None)
Get hooks via app/hooks.py
Parameters:
hook
- Name of the hook. Will gather all hooks for this name and return as a list.default
- Default if no hook found.app_name
- Filter by app.frappe.get_installed_apps (sort=False, frappe_last=False)
Get list of installed apps in current site.
frappe.get_lang_dict (fortype, name=None)
Returns the translated language dict for the given type and name.
Parameters:
fortype
- must be one of doctype
, page
, report
, include
, jsfile
, boot
name
- name of the document for which assets are to be returned.Get last created document of this type.
List database query via frappe.model.db_query
. Will also check for permissions.
Parameters:
doctype
- DocType on which query is to be made.fields
- List of fields or *
.filters
- List of filters (see example).order_by
- Order By e.g. modified desc
.limit_page_start
- Start results at record #. Default 0.limit_poge_length
- No of records in the page. Default 20.Example usage:
# simple dict filter
frappe.get_list("ToDo", fields=["name", "description"], filters = {"owner":"test@example.com"})
# filter as a list of lists
frappe.get_list("ToDo", fields="*", filters = [["modified", ">", "2014-01-01"]])
# filter as a list of dicts
frappe.get_list("ToDo", fields="*", filters = {"description": ("like", "test%")})
frappe.get_logger (module=None)
No docs
frappe.get_meta (doctype, cached=True)
Get frappe.model.meta.Meta
instance of given doctype name.
frappe.get_meta_module (doctype)
No docs
frappe.get_module (modulename)
Returns a module object for given Python module name using importlib.import_module
.
frappe.get_module_list (app_name)
Get list of modules for given all via app/modules.txt
.
frappe.get_module_path (module)
Get the path of the given module name.
Parameters:
module
- Module name.*joins
- Join additional path elements using os.path.join
.frappe.get_precision (doctype, fieldname, currency=None, doc=None)
Get precision for a given field
frappe.get_print (doctype, name, print_format=None, style=None, html=None, as_pdf=False)
Get Print Format for given document.
Parameters:
doctype
- DocType of document.name
- Name of document.print_format
- Print Format name. Default 'Standard',style
- Print Format style.as_pdf
- Return as PDF. Default False.frappe.get_pymodule_path (modulename)
Return path of given Python module name.
Parameters:
modulename
- Python module name.*joins
- Join additional path elements using os.path.join
.frappe.get_request_header (key, default=None)
Return HTTP request header.
Parameters:
key
- HTTP header key.default
- Default value.frappe.get_roles (username=None)
Returns roles of current user.
Return a frappe.model.document.Document
object of the given Single doctype.
frappe.get_site_config (sites_path=None, site_path=None)
Returns site_config.json
combined with sites/common_site_config.json
.
site_config
is a set of site wide settings like database name, password, email etc.
Return path of current site.
Parameters:
*joins
- Join additional path elements using os.path.join
.frappe.get_test_records (doctype)
Returns list of objects from test_records.json
in the given doctype's folder.
Returns error traceback.
No docs
Returns a document property or list of properties.
Alias for frappe.db.get_value
Parameters:
doctype
- DocType name.filters
- Filters like {"x":"y"}
or name of the document. None
if Single DocType.fieldname
- Column name.ignore
- Don't raise exception if table, column is missing.as_dict
- Return values as dict.debug
- Print query in error log.frappe.has_permission (doctype, ptype=read, doc=None, user=None, verbose=False, throw=False)
Raises frappe.PermissionError
if not permitted.
Parameters:
doctype
- DocType for which permission is to be check.ptype
- Permission type (read
, write
, create
, submit
, cancel
, amend
). Default: read
.doc
- [optional] Checks User permissions for given doc.user
- [optional] Check for given user. Default: current user.frappe.has_website_permission (doctype, ptype=read, doc=None, user=None, verbose=False)
Raises frappe.PermissionError
if not permitted.
Parameters:
doctype
- DocType for which permission is to be check.ptype
- Permission type (read
, write
, create
, submit
, cancel
, amend
). Default: read
.doc
- Checks User permissions for given doc.user
- [optional] Check for given user. Default: current user.frappe.import_doc (path, ignore_links=False, ignore_insert=False, insert=False)
Import a file using Data Import Tool.
frappe.init (site, sites_path=None)
Initialize frappe for the current site. Reset thread locals frappe.local
Returns True if istable
property (indicating child Table) is set for given DocType.
frappe.local_cache (namespace, key, generator, regenerate_if_none=False)
A key value store for caching within a request
Parameters:
namespace
- frappe.local.cache[namespace]key
- frappe.local.cache[namespace][key] used to retrieve valuegenerator
- method to generate a value if not found in storeAdd to debug_log
.
Parameters:
msg
- Message.frappe.make_property_setter (args, ignore_validate=False, validate_fields_for_doctype=True)
Create a new Property Setter (for overriding DocType and DocField properties).
frappe.msgprint (msg, small=0, raise_exception=0, as_table=False)
Print a message to the user (via HTTP response).
Messages are sent in the __server_messages
property in the
response JSON and shown in a pop-up / modal.
Parameters:
msg
- Message.small
- [optional] Show as a floating message in the footer.raise_exception
- [optional] Raise given exception and show message.as_table
- [optional] If msg
is a list of lists, render as HTML table.frappe.new_doc (doctype, parent_doc=None, parentfield=None, as_dict=False)
Returns a new document of the given DocType with defaults set.
Parameters:
doctype
- DocType of the new document.parent_doc
- [optional] add to parent document.parentfield
- [optional] add against this parentfield
.Raise frappe.PermissionError
if the user does not have any of the given Roles.
Parameters:
roles
- List of roles to check.Publish real-time updates
Parameters:
event
- Event name, like task_progress
etc.message
- JSON message object. For async must contain task_id
room
- Room in which to publish update (default entire site)user
- Transmit to userdoctype
- Transmit to doctype, docnamedocname
- Transmit to doctype, docnameafter_commit
- (default False) will emit after current transaction is committedfrappe.read_file (path, raise_not_found=False)
Open a file and return its content as Unicode.
frappe.reload_doc (module, dt=None, dn=None, force=False)
Reload Document from model ([module]/[doctype]/[name]/[name].json
) files.
Parameters:
module
- Module name.dt
- DocType name.dn
- Document name.force
- Reload even if modified
timestamp matches.frappe.reload_doctype (doctype, force=False)
Reload DocType from model ([module]/[doctype]/[name]/[name].json
) files.
frappe.rename_doc (doctype, old, new, debug=0, force=False, merge=False, ignore_permissions=False)
Rename a document. Calls frappe.model.rename_doc.rename_doc
frappe.reset_metadata_version ()
Reset metadata_version
(Client (Javascript) build ID) hash.
frappe.respond_as_web_page (title, html, success=None, http_status_code=None)
Send response as a web page with a message rather than JSON. Used to show permission errors etc.
Parameters:
title
- Page title and heading.message
- Message to be shown.success
- Alert message.http_status_code
- HTTP status code.Returns sluggified string. e.g. Sales Order
becomes sales_order
.
frappe.sendmail (recipients=(), sender=, subject=No Subject, message=No Message, as_markdown=False, bulk=False, reference_doctype=None, reference_name=None, unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, attachments=None, content=None, doctype=None, name=None, reply_to=None, cc=(), show_as_cc=(), message_id=None, as_bulk=False, send_after=None, expose_recipients=False, bulk_priority=1)
Send email using user's default Email Account or global default Email Account.
Parameters:
recipients
- List of recipients.sender
- Email sender. Default is current user.subject
- Email Subject.message
- (or content
) Email Content.as_markdown
- Convert content markdown to HTML.bulk
- Send via scheduled email sender Bulk Email. Don't send immediately.bulk_priority
- Priority for bulk email, default 1.reference_doctype
- (or doctype
) Append as communication to this DocType.reference_name
- (or name
) Append as communication to this document name.unsubscribe_method
- Unsubscribe url with options email, doctype, name. e.g. /api/method/unsubscribe
unsubscribe_params
- Unsubscribe paramaters to be loaded on the unsubscribe_method [optional] (dict).attachments
- List of attachments.reply_to
- Reply-To email id.message_id
- Used for threading. If a reply is received to this email, Message-Id is sent back as In-Reply-To in received email.send_after
- Send after the given datetime.expose_recipients
- Display all recipients in the footer message - "This email was sent to"Set current user.
Parameters:
username
- User name to set as current user.frappe.set_user_lang (user, user_language=None)
Guess and set user language for the session. frappe.local.lang
frappe.set_value (doctype, docname, fieldname, value)
Set document value. Calls frappe.client.set_value
Rebuild map of all modules (internal).
Throw execption and show message (msgprint
).
Parameters:
msg
- Message.exc
- Exception class. Default frappe.ValidationError
Returns titlified string. e.g. sales_order
becomes Sales Order
.
frappe.whitelist (allow_guest=False, xss_safe=False)
Decorator for whitelisting a function and making it accessible via HTTP.
Standard request will be /api/method/[path.to.method]
Parameters:
allow_guest
- Allow non logged-in user to access this method.Use as:
@frappe.whitelist()
def myfunc(param1, param2):
pass