Wiki

Wiki

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

Document Functions

Here’s a list of functions supported by the BaseDocument class and related utilities in the provided script:

Core Functions

  1. __init__(self, d) - Initialize a document instance.
  2. update(self, d) - Update multiple fields using a dictionary.
  3. update_if_missing(self, d) - Set default values for fields without existing values.
  4. get(self, key, filters=None, limit=None, default=None) - Retrieve a field's value or child table rows with optional filters.
  5. getone(self, key, filters=None) - Retrieve a single matching child document.
  6. set(self, key, value, as_value=False) - Set a field's value or initialize child tables.
  7. delete_key(self, key) - Delete a field from the document.
  8. append(self, key, value=None) - Add a new row to a child table.
  9. extend(self, key, value) - Add multiple rows to a child table.
  10. remove(self, doc) - Remove a child document from a child table.
  11. as_dict(self, ...) - Serialize the document as a dictionary.
  12. as_json(self) - Serialize the document as JSON.
  13. get_valid_dict(self, ...) - Retrieve a dictionary of valid fields for database insertion.
  14. get_table_field_doctype(self, fieldname) - Get the doctype of a child table.
  15. db_insert(self, ignore_if_duplicate=False) - Insert the document into the database.
  16. db_update(self) - Update the document in the database.
  17. db_update_all(self) - Update the document and all child documents in the database.
  18. get_db_value(self, key) - Retrieve a field's value from the database.
  19. get_parentfield_of_doctype(self, doctype) - Get the parent fieldname for a given child doctype.
  20. update_modified(self) - Update the modified timestamp in the database.

Validation

  1. _validate_length(self) - Validate length constraints for fields.
  2. _validate_selects(self) - Validate Select field values against options.
  3. _validate_data_fields(self) - Validate Data fields (e.g., email, URL).
  4. _validate_constants(self) - Validate fields marked as "set only once."
  5. _validate_update_after_submit(self) - Validate updates after document submission.
  6. _validate_non_negative(self) - Ensure numeric fields are not negative.
  7. _validate_code_fields(self) - Validate fields containing code (e.g., Python expressions).
  8. _validate_links(self) - Check for invalid or canceled links in linked fields.
  9. _validate_mandatory(self) - Validate mandatory fields.

Document Metadata and Utility

  1. is_new(self) - Check if the document is new.
  2. get_formatted(self, fieldname, ...) - Retrieve a formatted version of a field's value.
  3. precision(self, fieldname, parentfield=None) - Get precision for numeric fields.
  4. is_print_hide(self, fieldname, ...) - Check if a field is hidden for print.
  5. in_format_data(self, fieldname) - Check if a field is part of the print format data.
  6. init_child_tables(self) - Initialize child tables for the document.
  7. init_valid_columns(self) - Initialize valid columns with default values.
  8. get_valid_columns(self) - Retrieve a list of valid columns for the document.
  1. set_fetch_from_value(self, doctype, df, values) - Set value for fields with fetch_from property.
  2. get_invalid_links(self, is_submittable=False) - Retrieve invalid or canceled links.

Password Management

  1. _save_passwords(self) - Save password field values securely.
  2. get_password(self, fieldname="password", raise_exception=True) - Retrieve a password securely.
  3. is_dummy_password(self, pwd) - Check if a password is a dummy (e.g., *****).

Error Handling

  1. show_unique_validation_message(self, e) - Show validation errors for unique constraints.
  2. throw_length_exceeded_error(self, df, max_length, value) - Raise an error for exceeded length constraints.

Miscellaneous

  1. get_label_from_fieldname(self, fieldname) - Get the label for a fieldname.
  2. get_value(self, fieldname) - Get a value for a field, casting it appropriately.
  3. cast(self, value, df) - Cast a value based on field type.
  4. _sanitize_content(self) - Sanitize HTML and email fields to prevent XSS.
  5. _fix_numeric_types(self) - Ensure numeric fields have consistent types.
  6. _extract_images_from_text_editor(self) - Extract images embedded in Text Editor fields.
  7. reset_values_if_no_permlevel_access(self, ...) - Reset fields based on permission levels.

This comprehensive list covers all primary methods defined in the script for interacting with, validating, and managing documents in the Frappe framework.

Last updated 1 month ago
Was this helpful?
Thanks!