예제 #1
0
    def __init__(self, **attrs):
        super(Selection, self).__init__(**attrs)

        # m2o as selection
        if attrs.get('relation') and attrs.get('widget') == 'selection':
            proxy = rpc.RPCProxy(attrs['relation'])
            try:
                domain = attrs.get('domain', [])
                if isinstance(domain, (str, unicode)):
                    try:
                        domain = eval(domain)
                    except:
                        domain = []
                ids = proxy.search(domain)
                ctx = rpc.session.context.copy()
                ctx.update(attrs.get('context', {}))
                self.options = proxy.name_get(ids, ctx)
            except:
                self.options = []
        else:
            self.options = attrs.get('selection', [])

        # determine the actual type
        if self.options and isinstance(self.options[0][0], basestring):
            self.kind = 'char'
            self.validator = validators.String()
        else:
            self.validator = validators.Selection()
예제 #2
0
class FormCreate(DBForm):
    name = "create"
    string = _('Create new database')
    action = '/database/do_create'
    submit_text = _('OK')
    strip_name = True
    form_attrs = {'onsubmit': 'return on_create()'}
    fields = [
        widgets.PasswordField(name='password',
                              label=_('Super admin password:'******'dbname',
                          label=_('New database name:'),
                          validator=validators.NotEmpty()),
        widgets.CheckBox(name='demo_data',
                         label=_('Load Demonstration data:'),
                         default=True,
                         validator=validators.Bool(if_empty=False)),
        widgets.SelectField(name='language',
                            options=get_lang_list,
                            validator=validators.String(),
                            label=_('Default Language:')),
        widgets.PasswordField(name='admin_password',
                              label=_('Administrator password:'******'confirm_password',
                              label=_('Confirm password:'),
                              validator=validators.NotEmpty())
    ]
    validator = validators.Schema(chained_validators=[
        validators.FieldsMatch("admin_password", "confirm_password")
    ])
예제 #3
0
 def __init__(self, **attrs):
     
     if attrs.get('password'):
         attrs.pop('invisible', None)
     
     super(Char, self).__init__(**attrs)
     self.validator = validators.String()
예제 #4
0
    def __init__(self, **attrs):
        super(Selection, self).__init__(**attrs)

        self.options = attrs.get('selection', [])
        self.type2 = attrs.get('type2')
        self.operator = attrs.get('operator', '=')
        self.search_context = attrs.get('context', {})
        #Below mentioned process should be followed for m2o as selection and for boolean field on search panel
        if not self.options and attrs.get('relation') and attrs.get('widget') == 'selection':
            proxy = rpc.RPCProxy(attrs['relation'])
            try:
                domain = attrs.get('domain', [])
                if isinstance(domain, (str, unicode)):
                    try:
                        domain = eval(domain)
                    except:
                        domain = []
                ids = proxy.search(domain)
                ctx = rpc.session.context.copy()
#                ctx.update(attrs.get('context', {})) # In search view this will create problem for m2o field having widget='selection' and context as attr.
                self.options = proxy.name_get(ids, ctx)
            except:
                self.options = []

        if self.options and self.options[0][0] == '' and isinstance(self.options[0][0], unicode):
            self.validator = validators.Selection()
        # determine the actual type
        elif self.options and isinstance(self.options[0][0], basestring):
            self.kind = 'char'
            self.validator = validators.String()
        else:
            self.validator = validators.Selection()
class FormCreate(DBForm):
    name = "create"
    string = _('Create database')
    action = '/openerp/database/do_create'
    submit_text = _('Create')
    strip_name = True
    form_attrs = {'onsubmit': 'return on_create()'}
    fields = [
        openobject.widgets.PasswordField(
            name='password',
            label=_('Super admin password:'******'admin' after installation."
              )),
        openobject.widgets.TextField(
            name='dbname',
            label=_('New database name:'),
            validator=formencode.validators.NotEmpty(),
            help=
            _("Choose the name of the database that will be created. The name must not contain any special character. Exemple: 'terp'."
              )),
        openobject.widgets.CheckBox(
            name='demo_data',
            label=_('Load Demonstration data:'),
            default=True,
            validator=validators.Bool(if_empty=False),
            help=
            _("Check this box if you want demonstration data to be installed on your new database. These data will help you to understand OpenERP, with predefined products, partners, etc."
              )),
        openobject.widgets.SelectField(
            name='language',
            options=get_lang_list,
            validator=validators.String(),
            label=_('Default Language:'),
            help=
            _("Choose the default language that will be installed for this database. You will be able to install new languages after installation through the administration menu."
              )),
        openobject.widgets.PasswordField(
            name='admin_password',
            label=_('Administrator password:'******'admin' user that will be created in your new database."
              )),
        openobject.widgets.PasswordField(
            name='confirm_password',
            label=_('Confirm password:'******'admin' user that will be created in your new database. It has to be the same than the above field."
              ))
    ]
    validator = openobject.validators.Schema(chained_validators=[
        formencode.validators.FieldsMatch("admin_password", "confirm_password")
    ])
예제 #6
0
class FormBackup(DBForm):
    name = "backup"
    string = _('Backup database')
    action = '/database/do_backup'
    submit_text = _('OK')
    fields = [
        widgets.SelectField(name='dbname',
                            options=get_db_list,
                            label=_('Database:'),
                            validator=validators.String(not_empty=True)),
        widgets.PasswordField(name='password',
                              label=_('Password:'),
                              validator=validators.NotEmpty())
    ]
class FormBackup(DBForm):
    name = "backup"
    string = _('Backup database')
    action = '/openerp/database/do_backup'
    submit_text = _('Backup')
    fields = [
        openobject.widgets.SelectField(
            name='dbname',
            options=get_db_list,
            label=_('Database:'),
            validator=validators.String(not_empty=True)),
        openobject.widgets.PasswordField(
            name='password',
            label=_('Super admin password:'),
            validator=formencode.validators.NotEmpty())
    ]
예제 #8
0
class FormDrop(DBForm):
    name = "drop"
    string = _('Drop database')
    action = '/database/do_drop'
    submit_text = _('OK')
    form_attrs = {
        'onsubmit':
        'return window.confirm("%s")' %
        _("Do you really want to drop the selected database?")
    }
    fields = [
        widgets.SelectField(name='dbname',
                            options=get_db_list,
                            label=_('Database:'),
                            validator=validators.String(not_empty=True)),
        widgets.PasswordField(name='password',
                              label=_('Password:'),
                              validator=validators.NotEmpty())
    ]
class FormDrop(DBForm):
    name = "drop"
    string = _('Drop database')
    action = '/openerp/database/do_drop'
    submit_text = _('Drop')
    form_attrs = {
        'onsubmit':
        'return window.confirm(_("Do you really want to drop the selected database?"))'
    }
    fields = [
        openobject.widgets.SelectField(
            name='dbname',
            options=get_db_list,
            label=_('Database:'),
            validator=validators.String(not_empty=True)),
        openobject.widgets.PasswordField(
            name='password',
            label=_('Super admin password:'),
            validator=formencode.validators.NotEmpty())
    ]
예제 #10
0
    def __getstate__(self):
        return self.__dict__

    def __setstate__(self, d):
        self.__dict__.update(d)

_VALIDATORS = {
    'date': lambda *a: validators.DateTime(kind="date"),
    'time': lambda *a: validators.DateTime(kind="time"),
    'datetime': lambda *a: validators.DateTime(kind="datetime"),
    'float_time': lambda *a: validators.FloatTime(),
    'float': lambda *a: validators.Float(),
    'integer': lambda *a: validators.Int(),
    'selection': lambda *a: validators.Selection(),
    'char': lambda *a: validators.String(),
    'boolean': lambda *a: validators.Bool(),
    'reference': lambda *a: validators.Reference(),
    'binary': lambda *a: validators.Binary(),
    'text': lambda *a: validators.String(),
    'text_tag': lambda *a: validators.String(),
    'many2many': lambda *a: validators.many2many(),
    'one2many': lambda *a: validators.one2many(),
    'many2one': lambda *a: validators.many2one(),
    'email' : lambda *a: validators.Email(),
    'url' : lambda *a: validators.URL(),
    'picture': lambda *a: validators.Binary(),
}

class TinyFormError(formencode.api.Invalid):
    def __init__(self, field, msg, value):
예제 #11
0
 def __init__(self, **attrs):
     super(Text, self).__init__(**attrs)
     self.validator = validators.String()
예제 #12
0
 def __init__(self, **attrs):
     super(CKEditor, self).__init__(**attrs)
     self.validator = validators.String()
     self.readonly = not self.editable or self.readonly