Giter Site home page Giter Site logo

k8n / django-admin-locking Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joshmaker/django-admin-locking

0.0 2.0 0.0 142 KB

Prevents users from overwriting each others work in Django. Works with the built in Django admin interface, or you can integrate it with your own apps using a REST API.

License: Other

Makefile 0.24% Python 71.79% CSS 1.43% JavaScript 26.55%

django-admin-locking's Introduction

Django Admin Locking

build-status-image coveralls-status-image

Prevents users from overwriting each others changes in Django.

Requirement

Django Admin Locking is tested in the following environments

  • Python (2.7, 3.4)
  • Django (1.6, 1.7, 1.8, 1.9, 1.10)

Installation

Add 'locking' to your INSTALLED_APPS setting.

INSTALLED_APPS = (
    ...
    'locking',
)

Add the required URL pattern:

url(r'^locking/', include('locking.urls')),

Usage

To enable locking for a ModelAdmin:

from django.contrib import admin
from locking.admin import LockingAdminMixin
from my_project.mt_models import MyModel

class MyModelAdmin(LockingAdminMixin, admin.ModelAdmin):
     pass

admin.site.register(MyModel, MyModelAdmin)

The LockingAdminMixin will automatically add a new column that displays which rows are currently locked. To manually place this column add is_locked to the admin's list_display property.

Locking Admin offers the following variables for customization in your settings.py:

  • LOCKING_EXPIRATION_SECONDS - Time in seconds that an object will stay locked for without a 'ping' from the server. Defaults to 180.
  • LOCKING_PING_SECONDS - Time in seconds between 'pings' to the server with a request to maintain or gain a lock on the current form. Defaults to 15.
  • LOCKING_SHARE_ADMIN_JQUERY - Should locking use instance of jQuery used by the admin or should it use it's own bundled version of jQuery? Useful because older versions of Django do not come with a new enough version of jQuery for admin locking. Defaults to True.
  • LOCKING_DB_TABLE - Used to override the default locking table name (locking_lock)
  • LOCKING_DELETE_TIMEOUT_SECONDS - If not zero, locks will not be deleted immediately when a user leaves an admin form, but will instead be set to expire in the specified number of seconds. Specifying this setting can help avoid the following situation: a user hits 'save and continue' on a form, causing the page to reload. If locks are deleted instantly, someone else might grab the lock before the form loads again. If this value is specified, it should be set to the approximate time it takes a form to save (generally a few seconds). Defaults to 0.

Cleaning up expired locks

Overtime, you may find it necessary to remove expired locks from the database. This can be done with the following management command

$ python manage.py delete_expired_locks

If you have a non-zero specified for LOCKING_DELETE_TIMEOUT_SECONDS in your settings, you should setup a reoccurring Cron or Celery task to automatically run this management command on a regular interval.

Testing

Running the included test suite requires the following additional requirements:

  • Selenium
  • PhantomJS

JavaScript plugins for advanced widgets

By default, form field widgets are disabled by adding the attribute disabled = disabled to all inputs. If you are using a custom widget, such as a WYSIWYG editor, you may need to register a locking plugin to ensure it is correctly locked and unlocked.

Plugin registration takes the following form:

window.locking.LockingFormPlugins.register({
    'enable': function(form) {  /* Enabled my custom widget */ },
    'disable': function(form) {  /* Disable my custom widget */ }
})

For an example, look at the included plugin for the CKEditor WYSIYG editor.

Compatibility Notes

This app is compatible the popular admin theme django-grappelli

License

This code is licensed under the Simplified BSD License. View the LICENSE file under the root directory for complete license and copyright information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.