1+ from typing import TYPE_CHECKING , Any
2+
13from django .core .exceptions import FieldDoesNotExist
24from django .db import models
35
6+ from .columns .base import BoundColumn , CellArguments
47from .columns .linkcolumn import BaseLinkColumn
58from .columns .manytomanycolumn import ManyToManyColumn
69from .utils import A , AttributeDict , call_with_appropriate , computed_values
710
11+ if TYPE_CHECKING :
12+ from .tables import Table
13+
814
915class CellAccessor :
10- """
11- Allows accessing cell contents on a row object (see `BoundRow`)
12- """
16+ """Allows accessing cell contents on a row object (see `BoundRow`)."""
1317
1418 def __init__ (self , row ):
1519 self .row = row
@@ -80,31 +84,26 @@ class BoundRow:
8084
8185 """
8286
83- def __init__ (self , record , table ):
87+ def __init__ (self , record : Any , table : "Table" ):
8488 self ._record = record
8589 self ._table = table
8690
8791 self .row_counter = next (table ._counter )
8892
89- # support accessing cells from a template: {{ row.cells.column_name }}
93+ # Support accessing cells from a template: {{ row.cells.column_name }}
9094 self .cells = CellAccessor (self )
9195
9296 @property
93- def table (self ):
97+ def table (self ) -> "Table" :
9498 """The `.Table` this row is part of."""
9599 return self ._table
96100
97- def get_even_odd_css_class (self ):
98- """
99- Return css class, alternating for odd and even records.
100-
101- Return:
102- string: `even` for even records, `odd` otherwise.
103- """
101+ def get_even_odd_css_class (self ) -> str :
102+ """Return "odd" and "even" depending on the row counter."""
104103 return "odd" if self .row_counter % 2 else "even"
105104
106105 @property
107- def attrs (self ):
106+ def attrs (self ) -> AttributeDict :
108107 """Return the attributes for a certain row."""
109108 cssClass = self .get_even_odd_css_class ()
110109
@@ -120,7 +119,7 @@ def attrs(self):
120119 return AttributeDict (row_attrs )
121120
122121 @property
123- def record (self ):
122+ def record (self ) -> Any :
124123 """The data record from the data source which is used to populate this row with data."""
125124 return self ._record
126125
@@ -136,7 +135,7 @@ def __iter__(self):
136135 # is correct – it's what __getitem__ expects.
137136 yield value
138137
139- def _get_and_render_with (self , bound_column , render_func , default ):
138+ def _get_and_render_with (self , bound_column : BoundColumn , render_func , default ):
140139 value = None
141140 accessor = A (bound_column .accessor )
142141 column = bound_column .column
@@ -172,20 +171,20 @@ def _get_and_render_with(self, bound_column, render_func, default):
172171
173172 return render_func (bound_column , value )
174173
175- def _optional_cell_arguments (self , bound_column , value ) :
174+ def _optional_cell_arguments (self , bound_column : "BoundRow" , value : Any ) -> CellArguments :
176175 """
177176 Defines the arguments that will optionally be passed while calling the
178177 cell's rendering or value getter if that function has one of these as a
179178 keyword argument.
180179 """
181- return {
182- " value" : value ,
183- " record" : self .record ,
184- " column" : bound_column .column ,
185- " bound_column" : bound_column ,
186- " bound_row" : self ,
187- " table" : self ._table ,
188- }
180+ return CellArguments (
181+ value = value ,
182+ record = self .record ,
183+ column = bound_column .column ,
184+ bound_column = bound_column ,
185+ bound_row = self ,
186+ table = self ._table ,
187+ )
189188
190189 def get_cell (self , name ):
191190 """
0 commit comments