A Django module to manage approval workflows for CRUD operations.
Project description
djangoapprove
djangoapprove is a Django module that introduces an approval workflow for CRUD operations. It provides a flexible and extensible way to intercept model operations, pause them for approval, and execute them once approved.
Features
- Approval Workflow: Create, update, or delete operations are paused until explicitly approved or rejected.
- Customizable States and Transitions: Define your own approval statuses and state transitions.
- Model Integration: Easily integrate with existing Django models using the
ApprovalMixin. - Flexible Settings: Configure transitions, statuses, and actions through Django settings.
- Lightweight: Simple to integrate, with minimal dependencies.
Installation
- Install using
pip:pip install djangoapprove
- Add
djangoapproveto yourINSTALLED_APPSinsettings.py:
INSTALLED_APPS = [
...,
'djangoapprove',
]
- Run migrations to create the Approval model table:
python manage.py migrate
Usage
Basic Integration
To integrate djangoapprove with a model, use the ApprovalMixin:
from django.db import models
from djangoapprove.mixins import ApprovalMixin
class MyModel(models.Model, ApprovalMixin):
name = models.CharField(max_length=100)
description = models.TextField()
def get_unique_key(self):
return f"mymodel-{self.pk or some_unique_property}"
Approving Requests
Once an operation is intercepted, it creates an Approval record. Approvals can be reviewed and transitioned to the next state (e.g., APPROVED).
from djangoapprove.models import Approval
# Approve a pending request
approval = Approval.objects.get(pk=1)
approval.transition("APPROVE")
Settings
You can customize states, transitions, and initial/completed statuses in your settings.py:
APPROVAL_ACTIONS = {
"APPROVE": "Approve",
"REJECT": "Reject",
}
APPROVAL_STATUSES = {
"PENDING": "Pending",
"APPROVED": "Approved",
"REJECTED": "Rejected",
"FAILED": "Failed",
}
APPROVAL_TRANSITIONS = {
"APPROVE": {"PENDING": "APPROVED"},
"REJECT": {"PENDING": "REJECTED"},
}
APPROVAL_INITIAL_STATUS = "PENDING"
APPROVAL_COMPLETED_STATUS = "APPROVED"
Example: Approval Workflow
- Intercept Save Operation:
instance = MyModel(name="Example", description="This is a test.")
approval = instance.save() # Does not save immediately
- Review The Approval:
# Fetch the pending approval
approval = Approval.objects.filter(status="PENDING").first()
print(approval.data) # View the data payload
- Approve The Request:
approval.transition("APPROVE")
- Verify Execution:
# The instance should now be created
instance = MyModel.objects.get(name="Example")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file djangoapprove-0.1.0.tar.gz.
File metadata
- Download URL: djangoapprove-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
947f04cbd628a691271a207ce8928055b0f2acb568bedb799980d0449e04892c
|
|
| MD5 |
8ea07cfd90671347d4614fc54950c3e9
|
|
| BLAKE2b-256 |
ebdf9047d449836eba571e49aa6967be1ad240ce6194bb13bd2f53a7d7f80e1b
|
File details
Details for the file djangoapprove-0.1.0-py3-none-any.whl.
File metadata
- Download URL: djangoapprove-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1df69697d907871ecc4300b27a317b28154de1c5265d504c2b6ed64cc4aabd2
|
|
| MD5 |
ad284128feea091604c3075f4d98aa36
|
|
| BLAKE2b-256 |
92be217e41a78f58e34cf0bbc38241ea374127daf7df6edc284bfefe5587c4c6
|