Skip to main content

An app for Django to implement the Unpoly v2 Server Protocol

Project description

django-unpoly

What it does

unpoly is a reusable app for Django implementing a Django-flavored Unpoly v2 Server Protocol.

It provides:

  1. A middleware which adds is_unpoly unpoly_target, and unpoly_validate methods to the request object.

  2. A view mixin classes support both Django Generic Views and Vanilla Views.

  3. A Form mixin class for Crispy Forms.

Installation

pip install unpoly_django

Configuration

You need to add unpoly.middleware.UnpolyMiddleware to your MIDDLEWARE.

To install all the middleware, you want something like:

MIDDLEWARE = (
    # ...
    'unpoly.middleware.UnpolyMiddleware',
    # ...
)

Settings

If using the View mixins following constants to settings.py:

MAIN_UP_TARGET = '#your_main_up_target'
MAIN_UP_FAIL_TARGET = '#your_main_upfail_target'

DEFAULT_UP_ERROR_TEMPLATE = 'your-unpoly-error-template.html'

# Default Templates for various Unpoly layers.
# Override on individual View attributes.
UNPOLY_MODAL_TEMPLATE = 'your-unpoly-modal-template.html'
UNPOLY_DRAWER_TEMPLATE = 'your-unpoly-drawer-template.html'
UNPOLY_POPUP_TEMPLATE = 'your-unpoly-popup-template.html'
UNPOLY_COVER_TEMPLATE = 'your-unpoly-cover-template.html'

# Routing URL kwarg set when an optimized response is to be sent
OPTIMIZED_SUCCESS_RESPONSE = 'optimized_success_response'

DEFAULT_ERROR_VIEW = 'appname:error_view_name'

CSRF Token

Ensure that the csrf_token meta tag is included in the head section of your templates

<meta name="csrf-token" content="{{ csrf_token }}" />

View Mixins

View mixin classes add hooks and properties for sending optimized server responses to the frontend.

Add view mixin classes to Django's Generic views, or Vanilla Views:

from django.views.generic import FormView, TemplateView
from unpoly.views import UnpolyViewMixin, UnpolyFormViewMixin, UnpolyCrispyFormViewMixin


class YourTemplateView(UnpolyViewMixin, TemplateView):
    pass

class YourFormView(UnpolyViewMixin, FormView):
    pass

class YourCrispyFormView(UnpolyCrispyFormViewMixin, FormView):
    pass

Crispy Form Mixin

The Crispy Form mixin can be used when form mixins are used, which enables passing up-target, up-layer, up-fail-layer and up-fail-target params from views to forms:

from django.forms import ModelForm
from unpoly.forms import UnpolyCrispyFormMixin

class UnpolyCrispyForm(UnpolyCrispyFormMixin, ModelForm):
    pass

Running the tests

If you have a cloned copy, run::

python3 runtests.py

Contributing

Contributions welcome! The project lives in the Github repo at thinkwelltwd/unpoly_django repository.

Bug reports and feature requests can be filed on the repository's issue tracker.

License

Released under the MIT License. There's should be a LICENSE file in the root of the repository.


The MIT License (MIT) Copyright (c) 2021, Dave Burkholder

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Change history for unpoly_django

0.1.0 ^^^^^^

  • Initial release.

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

unpoly_django-0.1.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

unpoly_django-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file unpoly_django-0.1.0.tar.gz.

File metadata

  • Download URL: unpoly_django-0.1.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

File hashes

Hashes for unpoly_django-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cd41e5f9474e70fd7b7b342955619b4a2e7c2bff2a49a6b369c83fb8cae66087
MD5 a4c7698f1986abd3af0cccd141990bfe
BLAKE2b-256 3d85772a3a845737eda4058f0fc940d7139d85b66269f93f1d56bc34919b04f3

See more details on using hashes here.

File details

Details for the file unpoly_django-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: unpoly_django-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

File hashes

Hashes for unpoly_django-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11fbbbce4c39e679001c88c99b4d2e0a16472fef6d83190ac847650f59b9c9db
MD5 f398b0f929fa06687957e8e9feff7cf2
BLAKE2b-256 0247a74f385cc89f745c8c4492e60961949a503fe1a92f6c581984b8a07e7321

See more details on using hashes here.

Supported by

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