dispatch/api/serializers.py
def validate(self, data):
        """Perform validation of the widget data"""

        from dispatch.theme import ThemeManager

        errors = {}

        if data.get('widget') is not None:

            try:
                widget = ThemeManager.Widgets.get(data['widget'])
            except WidgetNotFound as e:
                errors['widget'] = str(e)
            else:
                for field in widget.fields:

                    field_data = data['data'].get(field.name)

                    if field_data is not None:
                        try:
                            field.validate(field_data)
                        except InvalidField as e:
                            errors[field.name] = str(e)
                    elif field.required:
                        errors[field.name] = '%s is required' % field.label

        if errors:
            raise ValidationError(errors)

        return data
def validate(self, data):
        from dispatch.theme import ThemeManager

        errors = {}

        if data.get('widget') is not None:

            try:
                widget = ThemeManager.Widgets.get(data['widget'])
            except WidgetNotFound as e:
                errors['widget'] = str(e)
            else:
                for field in widget.fields:

                    field_data = data['data'].get(field.name)

                    if field_data is not None:
                        try:
                            field.validate(field_data)
                        except InvalidField as e:
                            errors[field.name] = str(e)
                    elif field.required:
                        errors[field.name] = '%s is required' % field.label

        if errors:
            raise ValidationError(errors)

        return data
def validate ( self , data ) : from dispatch . theme import ThemeManager errors = { } if data . get ( 'widget' ) is not None : try : widget = ThemeManager . Widgets . get ( data [ 'widget' ] ) except WidgetNotFound as e : errors [ 'widget' ] = str ( e ) else : for field in widget . fields : field_data = data [ 'data' ] . get ( field . name ) if field_data is not None : try : field . validate ( field_data ) except InvalidField as e : errors [ field . name ] = str ( e ) elif field . required : errors [ field . name ] = '%s is required' % field . label if errors : raise ValidationError ( errors ) return data
Perform validation of the widget data
Perform validation of the widget data