ActivityLog
Activity log entry DocType.
Stores an immutable audit record of a user action on a document.
Once created, activity logs should never be modified or deleted.
Attributes:
user_id: ID of the user who performed the action
action: Type of action ("create", "read", "update", "delete")
doctype_name: Name of the affected DocType
document_id: ID of the affected document
job_id: ID of the background job (if applicable)
timestamp: When the action occurred (auto-set)
diff: Field changes for updates (old/new values)
metadata: Additional context (request_id, ip, user_agent)
Example:
log = ActivityLog(
user_id="user-001",
action="create",
doctype_name="Todo",
document_id="TODO-001",
)
Source: activity_log.py
Fields
| Field | Type | Required | Description | Validators |
|---|---|---|---|---|
| user_id | str | ✓ | ID of the user who performed the action | minLen: 1 |
| action | ActivityLogAction | ✓ | Type of action: create, read, update, delete | - |
| doctype_name | str | ✓ | Name of the affected DocType | minLen: 1 |
| document_id | str | ✓ | ID of the affected document | minLen: 1 |
| timestamp | datetime | When the action occurred (UTC) | - | |
| job_id | None | ID of the background job that triggered the action | - | |
| diff | None | Field changes for updates: {field: {old: x, new: y}} | - | |
| metadata | None | Additional context: request_id, ip, user_agent, etc. | - |
Permissions
| Role | Create | Delete | Read | Write |
|---|---|---|---|---|
| All | ✓ | |||
| System Manager | ✓ | ✓ |
Configuration
| Setting | Value |
|---|---|
| Submittable | False |
| Track Changes | True |
Controller
Controller hooks are implemented in *_controller.py files.
Available lifecycle hooks:
validate()- Called before save, raise exceptions for validation errorsbefore_insert()- Called before inserting a new documentafter_insert()- Called after successfully insertingbefore_save()- Called before saving (insert or update)after_save()- Called after savingbefore_delete()- Called before deletingafter_delete()- Called after deleting