예제 #1
0
    def _do_init_attrs(self):
        super(ViewBase, self)._do_init_attrs()
        if self.__base_widget_args__ is None:
            self.__base_widget_args__ = {}
        if self.__field_widgets__ is None:
            self.__field_widgets__ = {}
        if self.__field_widget_args__ is None:
            self.__field_widget_args__ = {}
        if self.__field_widget_types__ is None:
            self.__field_widget_types__ = {}
        if self.__widget_selector__ is None:
            self.__widget_selector__ = self.__widget_selector_type__()

        if self.__ignore_field_names__ is None:
            self.__ignore_field_names__ = ['sprox_id', '_method']

        for attr in dir(self):
            if not attr.startswith('__'):
                value = getattr(self, attr)
                if is_widget(value):
                    if not getattr(value, 'id', None):
                        raise ViewBaseError(
                            'Widgets must provide an id argument for use as a field within a ViewBase'
                        )
                    self.__add_fields__[attr] = value
                try:
                    if is_widget_class(value):
                        self.__field_widget_types__[attr] = value
                except TypeError:
                    pass
예제 #2
0
    def _do_init_attrs(self):
        super(ViewBase, self)._do_init_attrs()
        if self.__base_widget_args__ is None:
            self.__base_widget_args__ = {}
        if self.__field_widgets__ is None:
            self.__field_widgets__ = {}
        if self.__field_widget_args__ is None:
            self.__field_widget_args__ = {}
        if self.__field_widget_types__ is None:
            self.__field_widget_types__ = {}
        if self.__widget_selector__ is None:
            self.__widget_selector__ = self.__widget_selector_type__()

        if self.__ignore_field_names__ is None:
            self.__ignore_field_names__ = ['sprox_id', '_method']

        for attr in dir(self):
            if not attr.startswith('__'):
                value = getattr(self, attr)
                if is_widget(value):
                    if not getattr(value, 'id', None):
                        raise ViewBaseError('Widgets must provide an id argument for use as a field within a ViewBase')
                    self.__add_fields__[attr] = value
                try:
                    if is_widget_class(value):
                        self.__field_widget_types__[attr] = value
                except TypeError:
                    pass
예제 #3
0
    def _do_init_attrs(self):
        super(FormBase, self)._do_init_attrs()
        if self.__require_fields__ is None:
            self.__require_fields__ = []
        if self.__field_validators__ is None:
            self.__field_validators__ = {}
        if self.__validator_selector__ is None:
            self.__validator_selector__ = self.__validator_selector_type__(
                self.__provider__)
        if self.__field_validator_types__ is None:
            self.__field_validator_types__ = {}
        if self.__possible_field_names__ is None:
            if self.__dropdown_field_names__ is not None:
                warnings.warn(
                    'The __dropdown_field_names__ attribute is deprecated',
                    DeprecationWarning)
                self.__possible_field_names__ = self.__dropdown_field_names__
            else:
                self.__possible_field_names__ = self.__possible_field_name_defaults__

        # bring in custom declared validators
        for attr in dir(self):
            if not attr.startswith('__'):
                value = getattr(self, attr)
                if isinstance(value, Field):
                    widget = value.widget
                    if is_widget(widget):
                        if not getattr(widget, 'id', None):
                            raise ViewBaseError(
                                'Widgets must provide an id argument for use as a field within a ViewBase'
                            )
                        self.__add_fields__[attr] = widget
                    try:
                        if is_widget_class(widget):
                            self.__field_widget_types__[attr] = widget
                    except TypeError:
                        pass
                    validator = value.validator
                    if isinstance(validator, Validator):
                        self.__field_validators__[attr] = validator
                    try:
                        if issubclass(validator, Validator):
                            self.__field_validator_types__[attr] = validator
                    except TypeError:
                        pass
                if isinstance(value, Validator):
                    self.__field_validators__[attr] = value
                    continue
                try:
                    if issubclass(value, Validator):
                        self.__field_validator_types__[attr] = value
                except TypeError:
                    pass
예제 #4
0
    def _do_init_attrs(self):
        super(FormBase, self)._do_init_attrs()
        if self.__require_fields__ is None:
            self.__require_fields__ = []
        if self.__field_validators__ is None:
            self.__field_validators__ = {}
        if self.__validator_selector__ is None:
            self.__validator_selector__ = self.__validator_selector_type__(self.__provider__)
        if self.__field_validator_types__ is None:
            self.__field_validator_types__ = {}
        if self.__possible_field_names__ is None:
            if self.__dropdown_field_names__ is not None:
                warnings.warn('The __dropdown_field_names__ attribute is deprecated', DeprecationWarning)
                self.__possible_field_names__ = self.__dropdown_field_names__
            else:
                self.__possible_field_names__ = self.__possible_field_name_defaults__

        #bring in custom declared validators
        for attr in dir(self):
            if not attr.startswith('__'):
                value = getattr(self, attr)
                if isinstance(value, Field):
                    widget = value.widget
                    if is_widget(widget):
                        if not getattr(widget, 'id', None):
                            raise ViewBaseError('Widgets must provide an id argument for use as a field within a ViewBase')
                        self.__add_fields__[attr] = widget
                    try:
                        if is_widget_class(widget):
                            self.__field_widget_types__[attr] = widget
                    except TypeError:
                        pass
                    validator = value.validator
                    if isinstance(validator, Validator):
                        self.__field_validators__[attr] = validator
                    try:
                        if issubclass(validator, Validator):
                            self.__field_validator_types__[attr] = validator
                    except TypeError:
                        pass
                if isinstance(value, Validator):
                    self.__field_validators__[attr] = value
                    continue
                try:
                    if issubclass(value, Validator):
                        self.__field_validator_types__[attr] = value
                except TypeError:
                    pass