def __init__(self, **attrs):
        icon = attrs.get('name')
        attrs['name'] = attrs.get('name', 'Image').replace("-", "_")

        super(Image, self).__init__(**attrs)
        self.filename = attrs.get('filename', '')
        self.state = attrs.get('state')
        self.field = self.name.split('/')[-1]
        if attrs.get('widget'):
            extra_url_params = {}
            if not (self.id and self.id != 'None'):
                # during record creation provide current value (from default_get())
                # so we do not need to call default_get() twice
                extra_url_params['default_value'] = self.value
            self.src = tools.url('/openerp/form/binary_image_get_image',
                                 model=self.model,
                                 id=self.id,
                                 field=self.field,
                                 nocache=random.randint(0, 2**32),
                                 **extra_url_params)
            self.height = attrs.get('img_height', attrs.get('height', None))
            self.width = attrs.get('img_width', attrs.get('width', None))
            self.validator = validators.Binary()
        else:
            self.src = icons.get_icon(icon)
        if self.readonly:
            self.editable = False
Beispiel #2
0
    def __init__(self, **attrs):
        icon = attrs.get('name')
        attrs['name'] = attrs.get('name', 'Image').replace("-", "_")

        super(Image, self).__init__(**attrs)

        self.filename = attrs.get('filename', '')
        if getattr(self, 'size', ''):
            self.img_size = True
        else:
            self.img_size = False
        if 'widget' in attrs:
            self.stock = False
            self.field = self.name.split('/')[-1]
            if self.id:
                self.src = tools.url('/image/get_image',
                                     model=self.model,
                                     id=self.id,
                                     field=self.field)
            else:
                self.src = attrs.get('value')
            self.height = attrs.get('img_height', attrs.get('height', 160))
            self.width = attrs.get('img_width', attrs.get('width', 200))
            self.validator = validators.Binary()
        else:
            self.src = icons.get_icon(icon)

        if self.readonly:
            self.editable = False
Beispiel #3
0
    def __init__(self, **attrs):
        super(Picture, self).__init__(**attrs)

        height = attrs.get('img_height', attrs.get('height', None))
        self.height = height and 'height="%s"' % height or ''
        width = attrs.get('img_width', attrs.get('width', None))
        self.width = width and 'width="%s"' % width or ''
        self.validator = validators.Binary()

        ctx = rpc.session.context.copy()
        ctx.update(self.context or {})
        ctx['bin_size'] = False

        proxy = rpc.RPCProxy(self.model)

        if '/' in self.name:
            name = self.name.rsplit('/', 1)[-1]
        else:
            name = self.name

        if not self.id:
            value = proxy.default_get([name], ctx)
        else:
            value = proxy.read([self.id], [name], ctx)[0]

        value = value.get(name) or (None, None)
        self.url = generate_url_for_picture(self.model, name, self.id, value)
 def __init__(self, **attrs):
     super(Binary, self).__init__(**attrs)
     self.validator = validators.Binary()
     self.onchange = "set_binary_filename(this, '%s');" % (self.filename
                                                           or '')
     self.bin_data = attrs.get('value')
     # if bin_size was in context when reading the binary field, then the field's value is actually the binary
     # field's content size
     self.value_bin_size = getattr(self, 'context',
                                   {}).get('bin_size', False)
Beispiel #5
0
    def __init__(self, **attrs):
        icon = attrs.get('name')
        attrs['name'] = attrs.get('name', 'Image').replace("-", "_")

        super(Image, self).__init__(**attrs)
        self.filename = attrs.get('filename', '')
        self.state = attrs.get('state')
        self.field = self.name.split('/')[-1]
        if attrs.get('widget'):
            self.src = tools.url('/openerp/form/binary_image_get_image',
                                 model=self.model,
                                 id=self.id,
                                 field=self.field,
                                 nocache=random.randint(0, 2**32))
            self.height = attrs.get('img_height', attrs.get('height', None))
            self.width = attrs.get('img_width', attrs.get('width', None))
            self.validator = validators.Binary()
        else:
            self.src = icons.get_icon(icon)
        if self.readonly:
            self.editable = False
Beispiel #6
0
    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):
        formencode.api.Invalid.__init__(self, msg, value, state=None, error_list=None, error_dict=None)
        self.field = field
Beispiel #7
0
 def __init__(self, **attrs):
     super(Binary, self).__init__(**attrs)
     self.validator = validators.Binary()
     self.onchange = "onChange(this); set_binary_filename(this, '%s');" % (
         self.filename or '')
     self.is_wizard = attrs.get('is_wizard')