Belle II Software light-2406-ragdoll
DefaultValueFormatter Class Reference
Inheritance diagram for DefaultValueFormatter:
Collaboration diagram for DefaultValueFormatter:

Public Member Functions

def format_field (self, value, spec)
 
def get_field (self, field_name, args, kwargs)
 

Detailed Description

Custom formatter class which allows to substitute a missing value with a
default value

Definition at line 151 of file format.py.

Member Function Documentation

◆ format_field()

def format_field (   self,
  value,
  spec 
)
Format a single field:

* if the field is None and we have a ``:=`` specification we replace
  the field with the default value and change the spec to 's'
* if the value is None we replace it with an empty string

then we just run the normal formatter ...

Definition at line 155 of file format.py.

155 def format_field(self, value, spec):
156 """
157 Format a single field:
158
159 * if the field is None and we have a ``:=`` specification we replace
160 the field with the default value and change the spec to 's'
161 * if the value is None we replace it with an empty string
162
163 then we just run the normal formatter ...
164 """
165 if spec.startswith("="):
166 if value is None:
167 value = spec[1:]
168 spec = "s"
169 if value is None:
170 value = ""
171 spec = ""
172 return super().format_field(value, spec)
173

◆ get_field()

def get_field (   self,
  field_name,
  args,
  kwargs 
)
Try to get the field as usual but in case we cannot find it because it
either doesn't exist or it doesn't have the correct attribute/item we
just return None

Definition at line 174 of file format.py.

174 def get_field(self, field_name, args, kwargs):
175 """
176 Try to get the field as usual but in case we cannot find it because it
177 either doesn't exist or it doesn't have the correct attribute/item we
178 just return None
179 """
180 try:
181 return super().get_field(field_name, args, kwargs)
182 except (KeyError, TypeError):
183 return None, None
184
185

The documentation for this class was generated from the following file: