django-siteforms


Namedjango-siteforms JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/idlesign/django-siteforms
SummaryDjango reusable app to simplify form construction
upload_time2023-09-08 14:52:11
maintainer
docs_urlNone
authorIgor `idle sign` Starikov
requires_python
licenseBSD 3-Clause License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            django-siteforms
================
https://github.com/idlesign/django-siteforms

|release| |lic| |coverage|

.. |release| image:: https://img.shields.io/pypi/v/django-siteforms.svg
    :target: https://pypi.python.org/pypi/django-siteforms

.. |lic| image:: https://img.shields.io/pypi/l/django-siteforms.svg
    :target: https://pypi.python.org/pypi/django-siteforms

.. |coverage| image:: https://img.shields.io/coveralls/idlesign/django-siteforms/master.svg
    :target: https://coveralls.io/r/idlesign/django-siteforms


Description
-----------

*Django reusable app to simplify form construction*

For those who consider maintaining templates-based forms solutions for Django a burden.

Features:

* Full form rendering support, including prolog and submit button
* Subforms support (represent entire other form as a form field): JSON, Foreign Key, Many-to-Many
* Field groups
* Declarative attributes for elements
* Simplified declarative forms layout, allowing fields ordering
* Simple ways to make fields hidden, disabled, readonly
* Support for fields from model's properties
* Aria-friendly (Accessible Rich Internet Applications)
* Complex widgets (e.g. using values from multiple fields) support
* Filter-forms (use form for queryset filtering)

Supported styling:

* No CSS
* Bootstrap 4
* Bootstrap 5


Usage
-----

To render a form in templates just address a variable, e.g. ``<div>{{ form }}</div>``.

.. note:: By default there's no need to add a submit button and wrap it all into ``<form>``.

Basic
~~~~~

Let's show how to build a simple form.

.. code-block:: python

    from django.shortcuts import render
    from siteforms.composers.bootstrap5 import Bootstrap5
    from siteforms.toolbox import ModelForm


    class MyForm(ModelForm):
        """This form will show us how siteforms works."""
        
        disabled_fields = {'somefield'}  # Declarative way of disabling fields.
        hidden_fields = {'otherfield'}  # Declarative way of hiding fields.
        readonly_fields = {'anotherfield'}  # Declarative way of making fields readonly.

        class Composer(Bootstrap5):
            """This will instruct siteforms to compose this
            form using Bootstrap 5 styling.

            """
        class Meta:
            model = MyModel  # Suppose you have a model class already.
            fields = '__all__'

    def my_view(request):
        # Initialize form using data from POST.
        my_form = MyForm(request=request, src='POST')
        is_valid = form.is_valid()
        return render(request, 'mytemplate.html', {'form': my_form})


Composer options
~~~~~~~~~~~~~~~~

Now let's see how to tune our form.

.. code-block:: python

    from siteforms.composers.bootstrap5 import Bootstrap5, FORM, ALL_FIELDS

    class Composer(Bootstrap5):

        opt_size='sm'  # Bootstrap 5 has sizes, so let's make our form small.

        # Element (fields, groups, form, etc.) attributes are ruled by `attrs`.
        # Let's add rows=2 to our `contents` model field.
        attrs={'contents': {'rows': 2}}

        # To group fields into named groups describe them in `groups`.
        groups={
            'basic': 'Basic attributes',
            'other': 'Other fields',
        }

        # We apply custom layout to our form.
        layout = {
            FORM: {
                'basic': [  # First we place `basic` group.
                    # The following three fields are in the same row -
                    # two fields in the right column are stacked.
                    ['title', ['date_created',
                               'date_updated']],
                    'contents',  # This one field goes into a separate row.
                ],
                # We place all the rest fields into `other` group.
                'other': ALL_FIELDS,
            }
        }


Documentation
-------------

https://django-siteforms.readthedocs.org/



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/idlesign/django-siteforms",
    "name": "django-siteforms",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Igor `idle sign` Starikov",
    "author_email": "idlesign@yandex.ru",
    "download_url": "https://files.pythonhosted.org/packages/07/04/682ff2849480f73af511a10733cde21be3112f2ab06c48330baf67ca5f9a/django-siteforms-1.2.0.tar.gz",
    "platform": null,
    "description": "django-siteforms\n================\nhttps://github.com/idlesign/django-siteforms\n\n|release| |lic| |coverage|\n\n.. |release| image:: https://img.shields.io/pypi/v/django-siteforms.svg\n    :target: https://pypi.python.org/pypi/django-siteforms\n\n.. |lic| image:: https://img.shields.io/pypi/l/django-siteforms.svg\n    :target: https://pypi.python.org/pypi/django-siteforms\n\n.. |coverage| image:: https://img.shields.io/coveralls/idlesign/django-siteforms/master.svg\n    :target: https://coveralls.io/r/idlesign/django-siteforms\n\n\nDescription\n-----------\n\n*Django reusable app to simplify form construction*\n\nFor those who consider maintaining templates-based forms solutions for Django a burden.\n\nFeatures:\n\n* Full form rendering support, including prolog and submit button\n* Subforms support (represent entire other form as a form field): JSON, Foreign Key, Many-to-Many\n* Field groups\n* Declarative attributes for elements\n* Simplified declarative forms layout, allowing fields ordering\n* Simple ways to make fields hidden, disabled, readonly\n* Support for fields from model's properties\n* Aria-friendly (Accessible Rich Internet Applications)\n* Complex widgets (e.g. using values from multiple fields) support\n* Filter-forms (use form for queryset filtering)\n\nSupported styling:\n\n* No CSS\n* Bootstrap 4\n* Bootstrap 5\n\n\nUsage\n-----\n\nTo render a form in templates just address a variable, e.g. ``<div>{{ form }}</div>``.\n\n.. note:: By default there's no need to add a submit button and wrap it all into ``<form>``.\n\nBasic\n~~~~~\n\nLet's show how to build a simple form.\n\n.. code-block:: python\n\n    from django.shortcuts import render\n    from siteforms.composers.bootstrap5 import Bootstrap5\n    from siteforms.toolbox import ModelForm\n\n\n    class MyForm(ModelForm):\n        \"\"\"This form will show us how siteforms works.\"\"\"\n        \n        disabled_fields = {'somefield'}  # Declarative way of disabling fields.\n        hidden_fields = {'otherfield'}  # Declarative way of hiding fields.\n        readonly_fields = {'anotherfield'}  # Declarative way of making fields readonly.\n\n        class Composer(Bootstrap5):\n            \"\"\"This will instruct siteforms to compose this\n            form using Bootstrap 5 styling.\n\n            \"\"\"\n        class Meta:\n            model = MyModel  # Suppose you have a model class already.\n            fields = '__all__'\n\n    def my_view(request):\n        # Initialize form using data from POST.\n        my_form = MyForm(request=request, src='POST')\n        is_valid = form.is_valid()\n        return render(request, 'mytemplate.html', {'form': my_form})\n\n\nComposer options\n~~~~~~~~~~~~~~~~\n\nNow let's see how to tune our form.\n\n.. code-block:: python\n\n    from siteforms.composers.bootstrap5 import Bootstrap5, FORM, ALL_FIELDS\n\n    class Composer(Bootstrap5):\n\n        opt_size='sm'  # Bootstrap 5 has sizes, so let's make our form small.\n\n        # Element (fields, groups, form, etc.) attributes are ruled by `attrs`.\n        # Let's add rows=2 to our `contents` model field.\n        attrs={'contents': {'rows': 2}}\n\n        # To group fields into named groups describe them in `groups`.\n        groups={\n            'basic': 'Basic attributes',\n            'other': 'Other fields',\n        }\n\n        # We apply custom layout to our form.\n        layout = {\n            FORM: {\n                'basic': [  # First we place `basic` group.\n                    # The following three fields are in the same row -\n                    # two fields in the right column are stacked.\n                    ['title', ['date_created',\n                               'date_updated']],\n                    'contents',  # This one field goes into a separate row.\n                ],\n                # We place all the rest fields into `other` group.\n                'other': ALL_FIELDS,\n            }\n        }\n\n\nDocumentation\n-------------\n\nhttps://django-siteforms.readthedocs.org/\n\n\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "Django reusable app to simplify form construction",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/idlesign/django-siteforms"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "638a3341bfa144b63e01da904fd0b42b01eeecf1051894be1fc227f2031ac808",
                "md5": "06f93b77b521128448a70847a5cf43cf",
                "sha256": "ea228b10d33573c42ae374f0632a5838bd8b84d66e2b643fd5f77c2f326eaa76"
            },
            "downloads": -1,
            "filename": "django_siteforms-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "06f93b77b521128448a70847a5cf43cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 42275,
            "upload_time": "2023-09-08T14:52:10",
            "upload_time_iso_8601": "2023-09-08T14:52:10.195250Z",
            "url": "https://files.pythonhosted.org/packages/63/8a/3341bfa144b63e01da904fd0b42b01eeecf1051894be1fc227f2031ac808/django_siteforms-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0704682ff2849480f73af511a10733cde21be3112f2ab06c48330baf67ca5f9a",
                "md5": "c0159f14d98f278deb6319838d70bba7",
                "sha256": "763e7e3f21bd5ebb5430e4d08c4024ad5928f8cf81605c7138aaf17508b40936"
            },
            "downloads": -1,
            "filename": "django-siteforms-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c0159f14d98f278deb6319838d70bba7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 40092,
            "upload_time": "2023-09-08T14:52:11",
            "upload_time_iso_8601": "2023-09-08T14:52:11.945446Z",
            "url": "https://files.pythonhosted.org/packages/07/04/682ff2849480f73af511a10733cde21be3112f2ab06c48330baf67ca5f9a/django-siteforms-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-08 14:52:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "idlesign",
    "github_project": "django-siteforms",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "django-siteforms"
}
        
Elapsed time: 0.25475s