How to use the dispatch.theme.exceptions.WidgetNotFound function in dispatch

To help you get started, we’ve selected a few dispatch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ubyssey / dispatch / dispatch / theme / widgets.py View on Github external
def _load_zone(self):
        try:
            self._zone = ZoneModel.objects.get(zone_id=self.id)
            try:
                self._widget = ThemeManager.Widgets.get(self._zone.widget_id)
                self._widget.set_data(self._zone.data)
            except WidgetNotFound:
                self._widget = None
            self._is_loaded = True
        except ZoneModel.DoesNotExist:
            pass
github ubyssey / dispatch / dispatch / theme / __init__.py View on Github external
        @staticmethod
        def get(id):
            """Return a specific widget"""
            try:
                return register.widgets[id]()
            except KeyError:
                raise WidgetNotFound("Widget with id '%s' does not exist" % id)
github ubyssey / dispatch / dispatch / api / serializers.py View on Github external
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)
github ubyssey / dispatch / dispatch / theme / fields.py View on Github external
def get_widget(self, id):
        from dispatch.theme import ThemeManager

        if id is None:
            return None

        try:
            return ThemeManager.Widgets.get(id)
        except WidgetNotFound:
            raise WidgetNotFound('Widget with id %s does not exist' % id)
github ubyssey / dispatch / dispatch / templatetags / widgets.py View on Github external
def zone(zone_id, **kwargs):
    """Renders the contents of the zone with given zone_id."""
    
    try:
        zone = ThemeManager.Zones.get(zone_id)
    except ZoneNotFound:
        return ''

    try:
        return zone.widget.render(add_context=kwargs)
    except (WidgetNotFound, AttributeError):
        pass

    return ''
github ubyssey / dispatch / dispatch / theme / fields.py View on Github external
def get_widget(self, id):
        from dispatch.theme import ThemeManager

        if id is None:
            return None

        try:
            return ThemeManager.Widgets.get(id)
        except WidgetNotFound:
            raise WidgetNotFound('Widget with id %s does not exist' % id)