File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1919 'DecimalField' ,
2020 'FloatField' ,
2121 'IntField' ,
22+ 'ListField' ,
2223 'TimeField' ,
2324 'VerbatimField' ,
2425]
@@ -78,10 +79,6 @@ def prepare(self, data):
7879 return Decimal (data )
7980
8081
81- class VerbatimField (BaseField ):
82- pass
83-
84-
8582class FloatField (BaseField ):
8683 def prepare (self , data ):
8784 return float (data )
@@ -92,6 +89,15 @@ def prepare(self, data):
9289 return int (data )
9390
9491
92+ class ListField (BaseField ):
93+ def __init__ (self , child , ** kwargs ):
94+ self .child = child
95+ super (ListField , self ).__init__ (** kwargs )
96+
97+ def prepare (self , data ):
98+ return [self .child ().adapt (item ) for item in data ]
99+
100+
95101class TimeField (BaseField ):
96102 def prepare (self , data ):
97103 if isinstance (data , datetime .time ):
@@ -100,3 +106,7 @@ def prepare(self, data):
100106 return dateutil .parser .parse (data ).timetz ()
101107 else :
102108 raise ValueError ("Invalid time argument" )
109+
110+
111+ class VerbatimField (BaseField ):
112+ pass
Original file line number Diff line number Diff line change @@ -162,3 +162,8 @@ def test_optional_field_with_default(self):
162162 for entry in data :
163163 actual = field .adapt (entry )
164164 self .assertEqual (actual , expected )
165+
166+ def test_list_field (self ):
167+ actual = adapters .ListField (adapters .CharField ).adapt ([1 , 2 , 3 ])
168+ expected = ['1' , '2' , '3' ]
169+ self .assertEqual (actual , expected )
You can’t perform that action at this time.
0 commit comments