(self, form)
return json_row
Converts a child form to JSON for rendering
Converts a child form to JSON for rendering
Converts a child form to JSON for rendering
def form_to_json(self, form):
        """
        Converts a child form to JSON for rendering
        """
        cleaned_data = getattr(form, 'cleaned_data', {})

        def get_data(key):
            if key in cleaned_data:
                return cleaned_data[key]
            return form.data.get(key)

        json_row = {}
        for header in self.columns:
            if isinstance(header, dict):
                json_row[header['key']] = get_data(header['key'])
            elif isinstance(self.get_child_form_field(header), forms.Field):
                json_row[header] = get_data(header)
        if getattr(form, 'errors', None):
            json_row['form_errors'] = form.errors
        return json_row
def form_to_json ( self , form ) : cleaned_data = getattr ( form , 'cleaned_data' , { } ) def get_data ( key ) : if key in cleaned_data : return cleaned_data [ key ] return form . data . get ( key ) json_row = { } for header in self . columns : if isinstance ( header , dict ) : json_row [ header [ 'key' ] ] = get_data ( header [ 'key' ] ) elif isinstance ( self . get_child_form_field ( header ) , forms . Field ) : json_row [ header ] = get_data ( header ) if getattr ( form , 'errors' , None ) : json_row [ 'form_errors' ] = form . errors return json_row