django-admin-edit-lock is a Django application used in admin to prevent simultaneous edit by more than one users.
Project description
django-admin-edit-lock
:warning: Correct operation relies on cache. Therefore, the current version will be unreliable in cases where the default local-memory cache backend is used, along with multiple application server worker (see https://github.com/demestav/django-admin-edit-lock/issues/1).
Setup
Install package using pip
:
python -m pip install django-admin-edit-lock
Add it to the installed apps:
INSTALLED_APPS = [
...
"admin_edit_lock",
...
]
Configuration
There are two one mandatory settings:
ADMIN_EDIT_LOCK_DURATION
Defines how long each edit lock should last. The value is in seconds. For example:
ADMIN_EDIT_LOCK_DURATION = 60
will keep the lock for sixty seconds.
The lock is being updated regularly (every 5 seconds) as long as the user is still editing the object. Therefore this value needs to be larger than 5 seconds. This configuration will probably be removed in the future, as it does not really offer any value by being user-configurable. The only case this affects the user is how long the lock will remain after the user finished editing. For example, the user updated the lock at 10:00:00 (i.e. the lock expires at 10:01:00) and the user exits the edit screen (closer tab or saves or navigates back etc.) at 10:00:10. For the remaining 50 seconds, the lock will be there without any real purpose.
ADMIN_EDIT_LOCK_MAX_DURATION
Defines for how long a user can keep the same lock. The value is in seconds.
This prevents a user to keep the maintain the edit rights of an object indefinitely. This is useful in cases where a user unintentionally keeps the edit screen open and therefore not allowing other users to edit the object.
ADMIN_EDIT_LOCK_DISPLAY_OWNER
Defines whether to display the username of the user with edit rights, to other users trying to edit the same object. The value is
True
or False
.
:warning: If this is set to True, it raises potential privacy issues.
Usage
Use the AdminEditLockMixin
to enable edit lock on a model.
For example:
# models.py
from django.db import models
class Book(models.Model):
name = models.CharField(max_length=100)
# admin.py
from django.contrib import admin
from admin_edit_lock.admin import AdminEditLockMixin
class BookAdmin(AdminEditLockMixin, admin.ModelAdmin):
class Meta:
model = Book
Roadmap
- Customize messages
Extending the lock expiry time through AJAX callOptionally set a limit to how much the lock can be extended
Acknowledgements
This project is inspired by https://github.com/jonasundderwolf/django-admin-locking . This project differentiates by utilizing the Django permissions to decide whether a user can edit or not. Further, this project uses the messages middleware to notify the users of the lock status.
Project details
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
Hashes for django-admin-edit-lock-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c85e8a8de1a7fce62f1b103279bbcb417b16f01982740c93a86d58f1e71a1e7 |
|
MD5 | 08f2116b4ef941cbec78be41e01f5b74 |
|
BLAKE2b-256 | b208f0e64c1fc02bf0026c4182c4aac71399c75e04916b132ee992acf5805781 |
Hashes for django_admin_edit_lock-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae65f01d4c2bbb47aa18f6673291387541f4ce7a16891d36175fa7514d282b45 |
|
MD5 | 5e2390fbc8342ffa1a73c992aed22d3a |
|
BLAKE2b-256 | 753b27ef9fb6e975a3ca8df57f6e085a229520bd96c672db389d4e77d874cb1a |