199 # XXX later __detach is for the new widget system, the former is to |
199 # XXX later __detach is for the new widget system, the former is to |
200 # be removed once web/widgets.py has been dropped |
200 # be removed once web/widgets.py has been dropped |
201 if formparams.has_key('__%s_detach' % attr) or formparams.has_key('%s__detach' % attr): |
201 if formparams.has_key('__%s_detach' % attr) or formparams.has_key('%s__detach' % attr): |
202 # drop current file value |
202 # drop current file value |
203 value = None |
203 value = None |
204 # no need to check value when nor explicit detach nor new file submitted, |
204 # no need to check value when nor explicit detach nor new file |
205 # since it will think the attribut is not modified |
205 # submitted, since it will think the attribute is not modified |
206 elif isinstance(value, unicode): |
206 elif isinstance(value, unicode): |
207 # file modified using a text widget |
207 # file modified using a text widget |
208 value = Binary(value.encode(entity.text_encoding(attr))) |
208 value = Binary(value.encode(entity.attribute_metadata(attr, 'encoding'))) |
209 else: |
209 else: |
210 # (filename, mimetype, stream) |
210 # (filename, mimetype, stream) |
211 val = Binary(value[2].read()) |
211 val = Binary(value[2].read()) |
212 if not val.getvalue(): # usually an unexistant file |
212 if not val.getvalue(): # usually an unexistant file |
213 value = None |
213 value = None |
214 else: |
214 else: |
215 # XXX suppose a File compatible schema |
|
216 val.filename = value[0] |
215 val.filename = value[0] |
217 if entity.has_format(attr): |
216 if entity.has_metadata(attr, 'format'): |
218 key = '%s_format' % attr |
217 key = '%s_format' % attr |
219 formparams[key] = value[1] |
218 formparams[key] = value[1] |
220 self.relations.append('X %s_format %%(%s)s' |
219 self.relations.append('X %s_format %%(%s)s' |
221 % (attr, key)) |
220 % (attr, key)) |
|
221 # XXX suppose a File compatible schema |
222 if entity.e_schema.has_subject_relation('name') \ |
222 if entity.e_schema.has_subject_relation('name') \ |
223 and not formparams.get('name'): |
223 and not formparams.get('name'): |
224 formparams['name'] = value[0] |
224 formparams['name'] = value[0] |
225 self.relations.append('X name %(name)s') |
225 self.relations.append('X name %(name)s') |
226 value = val |
226 value = val |