Exemplo n.º 1
0
    def get_widget(self, widget_or_id, data=None):
        '''
        实例话widget
        '''
        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
Exemplo n.º 2
0
 def get_widget_params_form(self, wizard):
     data = wizard.get_cleaned_data_for_step(wizard.steps.first)
     widget_type = data["widget_type"]
     widget = widget_manager.get(widget_type)
     fields = copy.deepcopy(widget.base_fields)
     if "id" in fields:
         del fields["id"]
     return DeclarativeFieldsMetaclass("WidgetParamsForm", (forms.Form,), fields)
Exemplo n.º 3
0
 def get_widget_params_form(self, wizard):
     data = wizard.get_cleaned_data_for_step(wizard.steps.first)
     widget_type = data['widget_type']
     widget = widget_manager.get(widget_type)
     fields = copy.deepcopy(widget.base_fields)
     if 'id' in fields:
         del fields['id']
     return DeclarativeFieldsMetaclass("WidgetParamsForm", (forms.Form,), fields)
Exemplo n.º 4
0
    def get_widget(self, widget_or_id, data=None):
        """
        实例话widget
        """
        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