Django integration for Zooy UI framework with Carbon Design System widgets
Project description
django-zooy
Django form widgets for Carbon Design System and Zooy UI framework.
Installation
pip install django-zooy
# settings.py
INSTALLED_APPS = [
'django_zooy',
]
Quick Start
from django import forms
from django_zooy import CarbonFormMixin
from django_zooy.carbon import CarbonTextInput, CarbonEmailInput
class ContactForm(CarbonFormMixin, forms.Form):
name = forms.CharField(widget=CarbonTextInput())
email = forms.EmailField(widget=CarbonEmailInput())
The CarbonFormMixin automatically injects field labels, help text, validation states, and required attributes into Carbon widgets.
Widgets
Carbon Design System
from django_zooy.carbon import (
CarbonTextInput, # <cds-text-input>
CarbonEmailInput, # <cds-text-input type="email">
CarbonPasswordInput, # <cds-password-input>
CarbonURLInput, # <cds-text-input type="url">
CarbonTelInput, # <cds-text-input type="tel">
CarbonNumberInput, # <cds-text-input type="number">
CarbonSearchInput, # <cds-text-input type="search">
CarbonTextarea, # <cds-textarea>
)
Widget Configuration
Python snake_case attributes are automatically converted to Carbon's kebab-case:
CarbonTextInput(attrs={
'label': 'Username',
'helper_text': 'Enter your username',
'placeholder': 'johndoe',
'invalid': False,
'invalid_text': 'Username is required',
'size': 'md', # sm, md, lg
'enable_counter': True,
'max_count': 50,
})
Boolean attributes render without values:
required=True→requireddisabled=True→disabledinvalid=True→invalid
Form Mixins
CarbonFormMixin
Automatically configures Carbon widgets with form field metadata:
class MyForm(CarbonFormMixin, forms.ModelForm):
class Meta:
model = User
fields = ['username', 'email']
widgets = {
'username': CarbonTextInput(),
'email': CarbonEmailInput(),
}
Auto-injected attributes:
labelfromfield.labelrequiredfromfield.requiredhelper-textfromfield.help_textdisabledfromfield.disabledinvalidandinvalid-textfrom validation errors
Works with Form, ModelForm, and custom form classes. Only affects Carbon widgets.
ZooyFormMixin
Base mixin for Zooy UI integration. Use CarbonFormMixin for Carbon widgets.
Carbon Icons and Pictograms
Server-side SVG rendering of Carbon Design System icons and pictograms. No JavaScript required.
Setup
# settings.py
CARBON_ICONS_PATH = BASE_DIR / 'carbon' / 'icons'
CARBON_PICTOGRAMS_PATH = BASE_DIR / 'carbon' / 'pictograms' # Optional
# Download icons only
python manage.py fetch_carbon_assets icons
# Download pictograms only
python manage.py fetch_carbon_assets pictograms
# Download both
python manage.py fetch_carbon_assets all
Downloads 2,000+ icons and pictograms from npm to the specified paths.
Usage
{% load carbon %}
{# Icons #}
{% carbon_icon "save" %}
{% carbon_icon "edit" 20 %}
{% carbon_icon "delete" 16 slot="icon" class="text-red-500" %}
{# Pictograms #}
{% carbon_pictogram "accessibility" %}
{% carbon_pictogram "accelerating-transformation" size=64 %}
{% carbon_pictogram "cloud" slot="icon" class="my-pictogram" %}
Icon arguments:
name(required) - Icon name from Carbon icons librarysize(optional) - 16, 20, 24, or 32. Default: 16**attrs(optional) - HTML attributes (slot, class, data-*, etc.)
Pictogram arguments:
name(required) - Pictogram name from Carbon pictograms librarysize(optional) - Display size in pixels. Default: 48**attrs(optional) - HTML attributes (slot, class, data-*, etc.)
Missing icons/pictograms render nothing and log a warning.
Management Command Options
# Force re-download (overwrites existing files)
python manage.py fetch_carbon_assets icons --force
python manage.py fetch_carbon_assets all --force
Add to deployment pipeline:
# Download icons only
RUN python manage.py fetch_carbon_assets icons
# Or download both icons and pictograms
RUN python manage.py fetch_carbon_assets all
API Reference
CarbonWidgetMixin
Base class for all Carbon widgets. Provides:
- Automatic snake_case → kebab-case attribute conversion
- Boolean attribute handling
- Default size (
md) - Size constants:
SIZE_SMALL,SIZE_MEDIUM,SIZE_LARGE
CarbonTextInput
Tooltip constants:
- Alignment:
TOOLTIP_ALIGN_START,TOOLTIP_ALIGN_CENTER,TOOLTIP_ALIGN_END - Direction:
TOOLTIP_DIR_TOP,TOOLTIP_DIR_RIGHT,TOOLTIP_DIR_BOTTOM,TOOLTIP_DIR_LEFT
Supported attributes:
- Standard:
label,placeholder,required,disabled,readonly - Validation:
invalid,invalid_text,warn,warn_text - Display:
size,hide_label,inline - Counter:
enable_counter,max_count - Tooltip:
tooltip_alignment,tooltip_direction
CarbonPasswordInput
Same as CarbonTextInput with show_password_visibility_toggle=True by default.
Additional attributes:
hide_password_label- Tooltip text for hide passwordshow_password_label- Tooltip text for show password
CarbonTextarea
Same attributes as CarbonTextInput plus:
rows- Number of visible text linescols- Visible width of the text control
Development
git clone https://github.com/trinity-telecomms/django-zooy
cd django-zooy
uv sync --all-extras --all-groups
uv run pre-commit install # Install git hooks
pytest
ruff check .
Pre-commit Hooks
The project uses pre-commit hooks to ensure code quality:
# Install hooks (one-time setup)
uv run pre-commit install
# Run hooks manually on all files
uv run pre-commit run --all-files
# Hooks run automatically on git commit
Included hooks:
- Trailing whitespace and file ending fixes
- Ruff linting and formatting
- Django-upgrade for Django best practices
- Bandit security checks
Build and Publish
# Update version in pyproject.toml
uv sync --upgrade --all-extras --all-groups
pytest
rm -rf dist/ build/ *.egg-info/
uv build
uv publish
License
MIT License. See LICENCE for details.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_zooy-0.3.0.tar.gz.
File metadata
- Download URL: django_zooy-0.3.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85225c6a878d3eb3eed32ed512a4ab426e7d485840c80dfaffa74594a84f680b
|
|
| MD5 |
db812a05df380d7347e949ff7c8f377b
|
|
| BLAKE2b-256 |
566a33e42cae24e6600821bfe828f2676ac1b55e0f996491d2d14c208fc9401d
|
File details
Details for the file django_zooy-0.3.0-py3-none-any.whl.
File metadata
- Download URL: django_zooy-0.3.0-py3-none-any.whl
- Upload date:
- Size: 31.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1618f9738fcde0ca0f52c99304adfd1d5bd234c0a9ddeff3f327c542a02bf4a
|
|
| MD5 |
1ad8c00015a8a6a5eabc771e993ef291
|
|
| BLAKE2b-256 |
956ae7e65c3db69f4cfa53335ab3547f55c140f19cf8299fcb85d629a4108140
|