conditional-field


Nameconditional-field JSON
Version 1.0.9 PyPI version JSON
download
home_pagehttps://github.com/Nigel2392/conditional_field
SummaryAn application made for the Django Web Framework.
upload_time2024-03-19 05:54:38
maintainer
docs_urlNone
authorNigel
requires_python>=3.8
licenseGPL-3.0-only
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # conditional_field

Allows for arbitrary showing and hiding of fields in the admin based on certain user input.
Idea based on [Wagtail UI+](https://pypi.org/project/wagtailuiplus/#description)'s conditional visibility fields.

## Installations

1. Add conditional field to your `INSTALLED_APPS`

   ```
   INSTALLED_APPS = [
       ...
       'conditional_field'
       ...
   ]
   ```
2. Run `python3 ./manage.py collectstatic`

## Example usage of the gcf conditional fields.

```python
from wagtail import blocks


class Link(blocks.StructBlock):
    text = CharBlockWithAttrs(
        required=False,
        label=_("Text"),
    )

    page = blocks.PageChooserBlock(
        required=False,
        label=_("Page"),
        classname=(
            "gcf "
            "gcf-handler--choice "
            "gcf-action--show--page "
        ),
    )

    document = DocumentChooserBlock(
        required=False,
        label=_("Document"),
        classname=(
            "gcf "
            "gcf-handler--choice "
            "gcf-action--show--document"
        ),
    )

    external_link = blocks.URLBlock(
        required=False,
        label=_("External Link"),
        classname=(
            "gcf "
            "gcf-handler--choice "
            "gcf-action--show--external_link"
        ),
    )

    email = blocks.EmailBlock(
        required=False,
        label=_("Email"),
        classname=(
            "gcf "
            "gcf-handler--choice "
            "gcf-action--show--email"
        ),
    )

    phone = blocks.CharBlock(
        required=False,
        label=_("Tel"),
        placeholder=_("123-456-7890"),
        validators=[
            RegexValidator(
                regex=r"^\+?[0-9\-\s\(\)]+$",
                message=_("Enter a valid phone number."),
            )
        ],
        min_length=7,
        max_length=14,
        classname=(
            # Example of multiple allowed
            # choices for a single block
            # We introduce fshow and fhide,
            # these do not automatically do the opposite for false values.
            # You would not want to use this in this context; it is just an example.
            "gcf "
            "gcf-handler--choice "
            "gcf-action-any--fhide "
            "gcf-action--fshow--email "
            "gcf-action--fshow--tel"
        ),
    )

    choice = blocks.ChoiceBlock(
        required=True,
        choices=[
             ("page", "Page")
             ("document", "Document")
             ("external_link", "External")
             ("email", "Email Link")
             ("tel", "Telephone Link")
        ],
        default="page",
        label=_("Link Type"),
        classname=(
            "gcf "
            "gcf-handler--choice"
        ),
        widget=forms.RadioSelect,
    )



hide_animation_fields_classname = (
    'gcf '
    'gcf-handler--animation '
    'gcf-action-empty--hide '
    'gcf-action-any--show'
)

class AnimatorBlock(blocks.StructBlock):
    animation = blocks.ChoiceBlock(
        choices=animations_choices,
        required=False,
        label=_("Animation"),
        translatable=False,
        classname=(
            'gcf '
            'gcf-handler--animation'
        ),
    )

    duration = blocks.IntegerBlock(
        default=1000,
        required=True,
        translatable=False,
        label=_("Duration"),
        classname=hide_animation_fields_classname,
    )

    delay = blocks.IntegerBlock(
        default=0,
        required=True,
        translatable=False,
        label=_("Delay"),
        classname=hide_animation_fields_classname,
    )
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Nigel2392/conditional_field",
    "name": "conditional-field",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Nigel",
    "author_email": "nigel@goodadvice.it",
    "download_url": "https://files.pythonhosted.org/packages/2b/37/333b612966741bba46c79e39262ae8c78a8cf37ab55b5fa20ecafa248c5f/conditional_field-1.0.9.tar.gz",
    "platform": null,
    "description": "# conditional_field\r\n\r\nAllows for arbitrary showing and hiding of fields in the admin based on certain user input.\r\nIdea based on [Wagtail UI+](https://pypi.org/project/wagtailuiplus/#description)'s conditional visibility fields.\r\n\r\n## Installations\r\n\r\n1. Add conditional field to your `INSTALLED_APPS`\r\n\r\n   ```\r\n   INSTALLED_APPS = [\r\n       ...\r\n       'conditional_field'\r\n       ...\r\n   ]\r\n   ```\r\n2. Run `python3 ./manage.py collectstatic`\r\n\r\n## Example usage of the gcf conditional fields.\r\n\r\n```python\r\nfrom wagtail import blocks\r\n\r\n\r\nclass Link(blocks.StructBlock):\r\n    text = CharBlockWithAttrs(\r\n        required=False,\r\n        label=_(\"Text\"),\r\n    )\r\n\r\n    page = blocks.PageChooserBlock(\r\n        required=False,\r\n        label=_(\"Page\"),\r\n        classname=(\r\n            \"gcf \"\r\n            \"gcf-handler--choice \"\r\n            \"gcf-action--show--page \"\r\n        ),\r\n    )\r\n\r\n    document = DocumentChooserBlock(\r\n        required=False,\r\n        label=_(\"Document\"),\r\n        classname=(\r\n            \"gcf \"\r\n            \"gcf-handler--choice \"\r\n            \"gcf-action--show--document\"\r\n        ),\r\n    )\r\n\r\n    external_link = blocks.URLBlock(\r\n        required=False,\r\n        label=_(\"External Link\"),\r\n        classname=(\r\n            \"gcf \"\r\n            \"gcf-handler--choice \"\r\n            \"gcf-action--show--external_link\"\r\n        ),\r\n    )\r\n\r\n    email = blocks.EmailBlock(\r\n        required=False,\r\n        label=_(\"Email\"),\r\n        classname=(\r\n            \"gcf \"\r\n            \"gcf-handler--choice \"\r\n            \"gcf-action--show--email\"\r\n        ),\r\n    )\r\n\r\n    phone = blocks.CharBlock(\r\n        required=False,\r\n        label=_(\"Tel\"),\r\n        placeholder=_(\"123-456-7890\"),\r\n        validators=[\r\n            RegexValidator(\r\n                regex=r\"^\\+?[0-9\\-\\s\\(\\)]+$\",\r\n                message=_(\"Enter a valid phone number.\"),\r\n            )\r\n        ],\r\n        min_length=7,\r\n        max_length=14,\r\n        classname=(\r\n            # Example of multiple allowed\r\n            # choices for a single block\r\n            # We introduce fshow and fhide,\r\n            # these do not automatically do the opposite for false values.\r\n            # You would not want to use this in this context; it is just an example.\r\n            \"gcf \"\r\n            \"gcf-handler--choice \"\r\n            \"gcf-action-any--fhide \"\r\n            \"gcf-action--fshow--email \"\r\n            \"gcf-action--fshow--tel\"\r\n        ),\r\n    )\r\n\r\n    choice = blocks.ChoiceBlock(\r\n        required=True,\r\n        choices=[\r\n             (\"page\", \"Page\")\r\n             (\"document\", \"Document\")\r\n             (\"external_link\", \"External\")\r\n             (\"email\", \"Email Link\")\r\n             (\"tel\", \"Telephone Link\")\r\n        ],\r\n        default=\"page\",\r\n        label=_(\"Link Type\"),\r\n        classname=(\r\n            \"gcf \"\r\n            \"gcf-handler--choice\"\r\n        ),\r\n        widget=forms.RadioSelect,\r\n    )\r\n\r\n\r\n\r\nhide_animation_fields_classname = (\r\n    'gcf '\r\n    'gcf-handler--animation '\r\n    'gcf-action-empty--hide '\r\n    'gcf-action-any--show'\r\n)\r\n\r\nclass AnimatorBlock(blocks.StructBlock):\r\n    animation = blocks.ChoiceBlock(\r\n        choices=animations_choices,\r\n        required=False,\r\n        label=_(\"Animation\"),\r\n        translatable=False,\r\n        classname=(\r\n            'gcf '\r\n            'gcf-handler--animation'\r\n        ),\r\n    )\r\n\r\n    duration = blocks.IntegerBlock(\r\n        default=1000,\r\n        required=True,\r\n        translatable=False,\r\n        label=_(\"Duration\"),\r\n        classname=hide_animation_fields_classname,\r\n    )\r\n\r\n    delay = blocks.IntegerBlock(\r\n        default=0,\r\n        required=True,\r\n        translatable=False,\r\n        label=_(\"Delay\"),\r\n        classname=hide_animation_fields_classname,\r\n    )\r\n```\r\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-only",
    "summary": "An application made for the Django Web Framework.",
    "version": "1.0.9",
    "project_urls": {
        "Homepage": "https://github.com/Nigel2392/conditional_field"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b37333b612966741bba46c79e39262ae8c78a8cf37ab55b5fa20ecafa248c5f",
                "md5": "92a3f49e472cd558c9d96fcead9c0083",
                "sha256": "3f52de5b7048f6b285ae9a51944fdd28adca66b7a02ae7fb721874e2f4663f33"
            },
            "downloads": -1,
            "filename": "conditional_field-1.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "92a3f49e472cd558c9d96fcead9c0083",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 12190,
            "upload_time": "2024-03-19T05:54:38",
            "upload_time_iso_8601": "2024-03-19T05:54:38.449074Z",
            "url": "https://files.pythonhosted.org/packages/2b/37/333b612966741bba46c79e39262ae8c78a8cf37ab55b5fa20ecafa248c5f/conditional_field-1.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-19 05:54:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Nigel2392",
    "github_project": "conditional_field",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "conditional-field"
}
        
Elapsed time: 0.19409s