Parameters API Reference
All parameter classes live in dj_design_system.parameters. Any new parameter
class added to that module will appear here automatically.
dj_design_system.parameters
BaseParam(description=None, *, required=True, default=None, choices=None)
Uses the descriptor protocol to define parameters for components, including type validation, default values, and documentation generation.
See https://docs.python.org/3/howto/descriptor.html for more on the descriptor protocol.
Source code in dj_design_system/parameters/base.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
get_css_classes(param_name, value)
Return CSS classes derived from the parameter value.
Override in subclasses to produce CSS classes from the parameter.
Source code in dj_design_system/parameters/base.py
83 84 85 86 87 88 | |
get_extra_context(param_name, value)
Return additional context variables to add to the component's template context.
Override in subclasses (e.g. ModelParam) to inject extra context derived from the parameter value.
Source code in dj_design_system/parameters/base.py
75 76 77 78 79 80 81 | |
has_been_set(obj)
Return True if the parameter has been explicitly set on the given component instance.
Source code in dj_design_system/parameters/base.py
90 91 92 | |
BoolCSSClassParam(description=None, *, required=True, default=None, choices=None)
Bases: BoolParam
Source code in dj_design_system/parameters/base.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
get_css_classes(param_name, value)
Return the parameter name as a CSS class when truthy.
Source code in dj_design_system/parameters/base.py
149 150 151 | |
ModelParam(description=None, *, required=True, default=None)
Bases: BaseParam
A parameter that accepts a Django model instance and exposes its attributes.
Subclass this and define a Meta inner class with at least model
and fields. model may be a model class or an "app_label.ModelName"
string (resolved lazily via Django's app registry). fields should be a
list of attribute names or "__all__" (all concrete model fields).
.. warning::
Prefer explicit field lists over ``"__all__"``. Using ``"__all__"``
exposes every concrete model field in the template context, which may
include sensitive data. It also defers CSS class field validation to
runtime instead of catching mismatches at class definition time.
Optional Meta attributes:
bool_css_classes– list of attribute names (or(attr, class_name)tuples) whose truthy values contribute a CSS class.str_css_classes– list of attribute names (or(attr, class_name)tuples) whose string values contribute a CSS class.
All attributes referenced in bool_css_classes and str_css_classes
must be present in Meta.fields.
CSS classes are namespaced with the parameter's name on the component to
avoid collisions, e.g. user-active, user-name-andrew.
Source code in dj_design_system/parameters/model.py
60 61 62 63 64 65 66 67 68 | |
__init_subclass__(**kwargs)
Validate that all subclasses define a Meta class.
Concrete subclasses must have Meta.model and Meta.fields.
Abstract intermediates must set Meta.abstract = True.
Source code in dj_design_system/parameters/model.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
docstring()
Generate a docstring using the resolved model name.
Source code in dj_design_system/parameters/model.py
146 147 148 149 150 151 152 153 154 155 156 157 158 | |
get_css_classes(param_name, value)
Generate namespaced CSS classes from model attributes configured in Meta.
Delegates to shared CSS class generation logic for both boolean and string attributes, adding a {param_name}- prefix for namespacing.
Source code in dj_design_system/parameters/model.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
get_extra_context(param_name, value)
Flatten model attributes into the template context.
Each attribute listed in Meta.fields is added as
{param_name}_{attribute}.
Source code in dj_design_system/parameters/model.py
168 169 170 171 172 173 174 175 176 177 178 179 | |
validate(value)
Check that value is an instance of the configured model.
Source code in dj_design_system/parameters/model.py
138 139 140 141 142 143 144 | |
StrCSSClassParam(description=None, *, required=True, default=None, choices)
Bases: StrParam
Source code in dj_design_system/parameters/base.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
get_css_classes(param_name, value)
Return the parameter's string value as a CSS class when truthy.
Source code in dj_design_system/parameters/base.py
141 142 143 | |
UserParam(description=None, *, required=True, default=None)
Bases: ModelParam
A ModelParam pre-configured for the project's User model.
Exposes common user attributes and marks is_active as a boolean
CSS class (rendered as {param_name}-active when truthy).
Source code in dj_design_system/parameters/model.py
60 61 62 63 64 65 66 67 68 | |
options: members: true show_root_heading: false show_source: true show_symbol_type_heading: true show_symbol_type_toc: true docstring_style: google merge_init_into_class: true group_by_category: true