@filter_hook
def get_widget(self, widget_or_id, data=None):
    try:
        if isinstance(widget_or_id, UserWidget):
            widget = widget_or_id
        else:
            widget = UserWidget.objects.get(user=self.user, page_id=self.get_page_id(), id=widget_or_id)
        wid = widget_manager.get(widget.widget_type)

        class widget_with_perm(wid):

            def context(self, context):
                super(widget_with_perm, self).context(context)
                context.update({'has_change_permission': self.request.user.has_perm('xadmin.change_userwidget')})
        wid_instance = widget_with_perm(self, (data or widget.get_value()))
        return wid_instance
    except UserWidget.DoesNotExist:
        return None
@filter_hook
def get_widget(self, widget_or_id, data=None):
    try:
        if isinstance(widget_or_id, UserWidget):
            widget = widget_or_id
        else:
            widget = UserWidget.objects.get(user=self.user, page_id=self.get_page_id(), id=widget_or_id)
        wid = widget_manager.get(widget.widget_type)

        class widget_with_perm(wid):

            def context(self, context):
                super(widget_with_perm, self).context(context)
                context.update({'has_change_permission': self.request.user.has_perm('xadmin.change_userwidget')})
        wid_instance = widget_with_perm(self, (data or widget.get_value()))
        return wid_instance
    except UserWidget.DoesNotExist:
        return None