Exemplo n.º 1
0
 def validate(self, data):
     super(WidgetDataSourceSerializer, self).validate(data)
     if data["type"] == WidgetDataSourceTypes.DISCOVER_SAVED_SEARCH:
         serializer = DiscoverSavedQuerySerializer(data=data["data"], context=self.context)
         if not serializer.is_valid():
             raise ValidationError("Error validating DiscoverSavedQuery: %s" % serializer.errors)
     else:
         raise ValidationError("Widget data source type %s not recognized." % data["type"])
     return data
Exemplo n.º 2
0
 def validate_type(self, attrs, source):
     type = attrs[source]
     if type not in WidgetDataSourceTypes.TYPE_NAMES:
         raise ValidationError(
             'Widget data source type %s not recognized.' % type)
     attrs[source] = WidgetDataSourceTypes.get_id_for_type_name(type)
     return attrs
    def validate_widgets(self, widgets):
        if len(widgets) != len(set([w["order"] for w in widgets])):
            raise ValidationError("Widgets must not have duplicate order values.")

        widgets_count = Widget.objects.filter(
            id__in=[w["id"] for w in widgets],
            dashboard_id=self.context["dashboard_id"],
            status=ObjectStatus.VISIBLE,
        ).count()

        if len(widgets) != widgets_count:
            raise ValidationError(
                "All widgets must exist within this dashboard prior to reordering."
            )

        return widgets
Exemplo n.º 4
0
    def validate_displayType(self, attrs, source):
        display_type = attrs[source]
        if display_type not in WidgetDisplayTypes.TYPE_NAMES:
            raise ValidationError('Widget displayType %s not recognized.' %
                                  display_type)

        attrs[source] = WidgetDisplayTypes.get_id_for_type_name(display_type)
        return attrs
    def validate_widgets(self, widgets):
        widgets_count = DashboardWidget.objects.filter(
            id__in=[w["id"] for w in widgets],
            dashboard_id=self.context["dashboard_id"],
        ).count()

        if len(widgets) != widgets_count:
            raise ValidationError(
                "All widgets must exist within this dashboard prior to reordering."
            )

        return widgets
Exemplo n.º 6
0
    def validate_widgets(self, attrs, source):
        try:
            widgets = attrs[source]
        except KeyError:
            return attrs

        if len(widgets) != len(set([w['order'] for w in widgets])):
            raise ValidationError(
                'Widgets must not have duplicate order values.')

        widgets_count = Widget.objects.filter(
            id__in=[w['id'] for w in widgets],
            dashboard_id=self.context['dashboard_id'],
            status=ObjectStatus.VISIBLE,
        ).count()

        if len(widgets) != widgets_count:
            raise ValidationError(
                'All widgets must exist within this dashboard prior to reordering.'
            )

        return attrs
Exemplo n.º 7
0
    def validate_displayType(self, display_type):
        if display_type not in WidgetDisplayTypes.TYPE_NAMES:
            raise ValidationError("Widget displayType %s not recognized." %
                                  display_type)

        return WidgetDisplayTypes.get_id_for_type_name(display_type)
Exemplo n.º 8
0
 def validate_type(self, type):
     if type not in WidgetDataSourceTypes.TYPE_NAMES:
         raise ValidationError(
             "Widget data source type %s not recognized." % type)
     type = WidgetDataSourceTypes.get_id_for_type_name(type)
     return type
Exemplo n.º 9
0
 def validate_age(self, attrs, source):
     age = attrs[source]
     if age > 5:
         raise ValidationError('age %d is not allowed' % age)
     return attrs