Allow datagrid Column subclasses to set attributes on the class level.
Review Request #14824 — Created Feb. 17, 2026 and updated
Historically,
Columnsubclasses had to override__init__and set
attributes there. This was a bit messy and error-prone, as it was common
to mix up positional and keyword arguments when subclassing, and made
for harder customization for more complex class hierarchies.Now, subclasses can set these arguments directly on the class as
attributes. The baseColumnclass has defaults for all these fields,
which can be overridden by subclasses and further overridden when
calling__init__(). Built-in subclasses also provide their own fitting
this pattern.To make this work, the arguments in
__init__()are all set toUNSET
by default. IfUNSET, class attributes (or more complex default
calculations) are used, but if any value is explicitly provided, it will
be used instead.To help avoid the mess of positional and keyword arguments in these
classes, all arguments other thanlabelare now keyword-only, with
positional arguments deprecated and scheduled for removal in Djblets 7.This is now the recommended approach for column subclasses. It has the
benefit of storing less state per-instance, as well, as we only set the
values on the instance if they're explicitly provided during
construction.As an added bonus, we've deprecated
cell_clickablewhich is confusing
and has never been largely ignored by the Djblets code. It's used by
the template to inject anonclick="javascript:window.location = ...",
but there's no way to set it without overriding it on a column instance.
Unit tests pass.
Tested updating existing columns to use this, and verified the new
settings were correct.
| Summary | ID |
|---|---|
| c7feb1be9cedf8c56814fb0e9e0cd613fc328214 |
| Description | From | Last Updated |
|---|---|---|
|
Should we do format_html(self.detailed_label) here to be safe? |
|
|
|
Can you add a Raises section for this in the docstring. |
|
|
|
How come we're setting this to False instead of using the cell_clickable arg? |
|
|
|
This is a no-op. We should just have: if detailed_label is UNSET: detailed_label = self.detailed_label |
|
|
|
In DateTimeSinceColumn you included label in the kwarg-only section. Should we do that here too? |
|
|
|
This needs to come after the *args docstring. |
|
|
|
I think we still want to pass label positionally to the parent __init__(), and then pass sortable=sortable after *args. |
|
|
|
Can we emit a DeprecationWarning if this is passed in? |
|
|
|
This class doesn't have a test case to test the init method, like the others do. |
|
|
|
Copy-pasteo: DateTimeColumn -> DateTimeSinceColumn |
|
|
|
Can we assert on label in here as well? |
|
|
|
Can we add 'label': 'My Column' to this? (this would catch the label issue that Michelle flagged) |
|
|
|
We might want to make this if not (self.label or label):, because otherwise if label is passed in, we do … |
|
- Change Summary:
-
- Deprecated
cell_clickable. detailed_label_htmlnow escapesdetailed_labelwhen used as a fallback.- Added a
Raisedsection to theColumn.__init__docs. - Removed a no-op codepath.
- Restored a
labelargument as a positional arg.
- Deprecated
- Description:
-
Historically,
Columnsubclasses had to override__init__and setattributes there. This was a bit messy and error-prone, as it was common to mix up positional and keyword arguments when subclassing, and made for harder customization for more complex class hierarchies. Now, subclasses can set these arguments directly on the class as
attributes. The base Columnclass has defaults for all these fields,which can be overridden by subclasses and further overridden when calling __init__(). Built-in subclasses also provide their own fittingthis pattern. To make this work, the arguments in
__init__()are all set toUNSETby default. If UNSET, class attributes (or more complex defaultcalculations) are used, but if any value is explicitly provided, it will be used instead. To help avoid the mess of positional and keyword arguments in these
classes, all arguments other than labelare now keyword-only, withpositional arguments deprecated and scheduled for removal in Djblets 7. This is now the recommended approach for column subclasses. It has the
benefit of storing less state per-instance, as well, as we only set the values on the instance if they're explicitly provided during construction. + + As an added bonus, we've deprecated
cell_clickablewhich is confusing+ and has never been largely ignored by the Djblets code. It's used by + the template to inject an onclick="javascript:window.location = ...",+ but there's no way to set it without overriding it on a column instance. - Commits:
-
Summary ID 2fa0467921ab882e082fc04cad1e8c5d0d1495c0 388f3f84cb0d2cd08637d815d5b2f6ade2046f85 - Diff:
-
Revision 2 (+1058 -408)
Checks run (2 succeeded)
- Change Summary:
-
- Passing
cell_clickablenow emits a deprecation warning. - Fixed a regression passing in
labeltoDateTimeSinceColumn. - Added unit tests for
DateTimeSinceColumn.__init__. - Added a missing
labelcomparison to aDateTimeColumntest.
- Passing
- Commits:
-
Summary ID 388f3f84cb0d2cd08637d815d5b2f6ade2046f85 e2abeb2b206fbe0186d2dde3a65824b82c8b6076 - Diff:
-
Revision 3 (+1162 -414)
Checks run (2 succeeded)
- Change Summary:
-
- Fixed an error where a custom label for
CheckboxColumnwould get overridden, and added tests. - Added an assertion for a
DateTimeSinceColumn'slabel. - Fixed docstring issues.
- Fixed an error where a custom label for
- Commits:
-
Summary ID e2abeb2b206fbe0186d2dde3a65824b82c8b6076 c7feb1be9cedf8c56814fb0e9e0cd613fc328214 - Diff:
-
Revision 4 (+1260 -414)