How to use the dispatch.theme.ThemeManager.Widgets.get 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 / widgets.py View on Github external
def before_save(self, widget_id, data):
        try:
            widget = ThemeManager.Widgets.get(widget_id)
            return widget.before_save(data)
        except:
            return data
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 / 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: