Skip to main content

Provide model integrity between requests

Project description

nango

Streamlining Django forms to provide all the wins of single-page-applications without the pain.

Key features

Available to all Django deployments:

  • Django forms no longer silently overwrite changes made in parallel by other users

Available if Django Channels is enabled:

  • Django forms can receive push notifications from the server (via Channels) when data used on the form changes, rather than only discovering data is out-of-date when the form is submitted
  • Django forms can send provisional form data to the server, allowing server-based field validation before the form is submitted
  • Django forms can save form data as it is edited, without needing a "submit" button.

What do all Django apps get?

Out of the box, Django provides reasonable support for database-level data consistency while a request is being processed, thanks to transactions. However, it is let down by not providing an easy way to avoid data corruptions between requests.

A simple example, where two users edit the same customer using the admin panel.

https://user-images.githubusercontent.com/236562/148663962-8f343216-cced-41fc-b2c0-c99ccda524e2.mp4

https://user-images.githubusercontent.com/236562/148663959-a0b69f19-c91d-405d-a4cc-1316a24c4bb8.mp4

As you can see, using the normal django tooling, the change made by the first user is lost. This occurs because Django does not track the original form value, making it impossible for it to know that the data was modified between when the form was rendered, and when the form was submitted.

Does this matter to me?

Here's a simple checklist to help you consider if this is a problem for you.

  • Can the same model be edited on multiple forms?
  • Can the same form be accessed simultaneously by multiple people?
  • Can one user access the same form in multiple tabs/windows, either on the same or different devices?

If the data you're storing is not important, maybe you can get away without caring about these "edge cases". However, if they do occur, you will have lost user data. There will be no errors, just users complaining that the changes they made were not saved. The original data will be irretrievable, and it will be difficult to even work out how often it is occurring.

learn more

What do Django Channels-enabled apps get?

Here is a quick example, where a model is being simultaneous edited in two admin panels, and two UpdateViews. Things to note:

  • the Customer model has a clean() rule ensuring the name and comment values are at least 5 characters long and there is a vowel in each word. Additionally it with capitalise the first letter in each word.
  • the only additional changes required are enabling the auto-clean and auto-submit features in the UpdateView's definition:
class UpdateView(edit.UpdateView):
    model = Customer
    fields = ["name", "notes", "company"]
    auto_clean_fields = ["name"]
    auto_submit_fields = ["notes"]
    ...

https://user-images.githubusercontent.com/236562/153730557-a22b473a-1680-465d-a898-1a7fa72e919f.mp4

Features demonstrated above:

  • the admin panel views automatically reflect changes as they occur. If a conflict occurs (due to also changing a field's value locally), it is highlighted and cannot be successfully saved.
  • the 'name' field, which is set to auto-clean, uses CSS to provide feedback on whether the current field value is valid, according to the server. In addition, if the field is not valid, the validation errors are shown. In both the admin panels and UpdateViews, any corrections to the field (ie: capitalisation) are reflected in realtime.
  • the 'notes' field is set to auto-submit, meaning that whenever its value is changed, the change is sent via a websocket to the server, and if clean() is successful, the value is saved. CSS classes are also used to indicate the status of the field, such as failing validation, save in progress, or saved.

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

nango-0.1.1.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nango-0.1.1-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file nango-0.1.1.tar.gz.

File metadata

  • Download URL: nango-0.1.1.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for nango-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ac0c0a8e692df5bd015c6871bda9089be31d2fb3a5fb84d1d7e50341fef26d2a
MD5 c22cd189e4ce02a005371972da423c73
BLAKE2b-256 d79eb4e217d4509b9efa26637be8f93331123e19400267c81f4296149bd1677b

See more details on using hashes here.

File details

Details for the file nango-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nango-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for nango-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c68b60c54981c2c165c1b036887bcf90a986446a22e9bd69f41c8c4368af54f5
MD5 516d5c9978e9987ebc28f3f426aa98ac
BLAKE2b-256 cf607ed4d7529a290a4a2b4aedb4411c342d24425703f416b6ef554c4d48665c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page