Workflow models
- class megworkflows.models.WorkflowQuerySet(model=None, query=None, using=None, hints=None)
- class megworkflows.models.Workflow(*args, **kwargs)
The entry point of the workflow, which defines the stages and trigger mechanism.
- property scheduled_time: time
Get the scheduled execution time from workflow config.
- exception DoesNotExist
- exception MultipleObjectsReturned
- class megworkflows.models.Stage(*args, **kwargs)
A stage in the workflow which links an operation to the workflow.
- clean()
Validate the conditions JSON structure with detailed error messages.
- exception DoesNotExist
- exception MultipleObjectsReturned
- class megworkflows.models.Operation(*args, **kwargs)
Defines an operation to be performed within the workflow.
- validate_required_config_fields(required_fields: list) None
Helper method to validate required fields in the config.
- validate_ringfencing_audit_form(auditor: Auditor, form_id: int) None
Validates that an auditor has access to the specified audit form according to ringfencing rules. Checks if the given form is published and if the auditor has been granted access to it.
- Parameters:
auditor – The Auditor instance whose permissions are being checked
form_id – The ID of the audit form to validate access for
- Raises:
ValidationError – If the form is not published or the auditor lacks access rights
- validate_rinfencing_create_observation_for_each_choice(auditor: Auditor) None
Validates the configuration for creating multiple observations based on multiselect field choices.
For the create-observation-for-each-choice operation type, validates that either: 1. A single audit_form_id is specified and the auditor has access to it, or 2. A properly formatted form_map is provided with valid form IDs and choice mappings
Validates that the form map (‘audit_forms’): 1. Is a list with more than one sub config 2. Has audit_form_id and choice in each sub config 3. Has sub configs with audit forms the user has access to 4. Has no duplicate sub configs
The form_map allows different forms to be used based on specific choices from a multiselect field in the triggering observation.
- Parameters:
auditor – The Auditor instance whose permissions are being checked
- Raises:
ValidationError – If configuration is invalid, improperly formatted, or references forms the auditor cannot access
- validate_ringfencing() None
Enforces comprehensive ringfencing rules for observation creation operations.
Validates that: 1. Either both ward and auditor are using placeholders, or they are hardcoded (ensuring that the hardcoded values can be ringfenced together) 2. Auditor exists and is allowed access to the ward and audit form(s) 3. For multi-choice operations, validates the form_map configuration
This ensures that the audit form, ward, and auditor comply with ringfencing rules using the existing queryset methods.
- Raises:
ValidationError – If any ringfencing rules are violated or if referenced entities don’t exist
- validate_no_self_triggering()
Validate that the operation does not create an observation in the same form that triggers the workflow.
- validate_create_observation_for_each_choice_for_audit_form(audit_form: AuditForm)
Validates that the choice_field_name in operation config refers to a valid multiple-choice field in the related audit form (Worflows audit form).
- Parameters:
audit_form – The form containing the multi-choice field to validate.
- Raises:
ValidationError – If the field doesn’t exist or isn’t a multiple-choice field.
- property audit_forms: QuerySet
Returns all audit forms from workflows that use this operation’s stage as their initial stage.
- validate_create_observation_for_each_choice()
Then, Validates the create_observation_for_each_choice configuration against all workflows connected to this operation’s stage. Ensures the referenced choice field exists in each workflow’s form and is properly configured to support this operation type.
- validate_linked_choice_fields()
Validates the linked_choice_fields configuration for web request operations.
Checks that when linked_choice_fields is provided, it contains both ‘single_choice_field_name’ and ‘multi_choice_field_name’ keys and their values.
- validate_http_transaction_field_mapping() None
Validates the http_transaction_field_mapping configuration for web request operations.
Checks that when http_transaction_field_mapping is provided: - All keys are valid HttpTransaction attribute names (url, status_code, body, request_data) - Each value exists as a published CustomField in the workflow audit forms
- clean()
Custom validation to ensure necessary fields are present in the config.
- trigger_object_custom_fields() Iterator[str]
returns a set of fields required from the trigger object.
- exception DoesNotExist
- exception MultipleObjectsReturned