def _process_form_value(self, form): posted = form._cw.form if self.input_name(form, u'__detach') in posted: # drop current file value on explictily asked to detach return None try: value = posted[self.input_name(form)] except KeyError: # raise UnmodifiedField instead of returning None, since the later # will try to remove already attached file if any raise UnmodifiedField() # value is a 2-uple (filename, stream) or a list of such # tuples (multiple files) try: if isinstance(value, list): value = value[0] form.warning('mutiple files provided, however ' 'only the first will be picked') filename, stream = value except ValueError: raise UnmodifiedField() # XXX avoid in memory loading of posted files. Requires Binary handling changes... value = Binary(stream.read()) if not value.getvalue(): # usually an unexistant file value = None else: # set filename on the Binary instance, may be used later in hooks value.filename = normalize_filename(filename) return value
def _process_form_value_with_suffix(self, form, suffix=u''): """ add suffix parameter & use it """ posted = form._cw.form if self.input_name(form, u'__detach') in posted: # drop current file value on explictily asked to detach return None try: value = posted[self.input_name(form, suffix)] except KeyError: # raise UnmodifiedField instead of returning None, since the later # will try to remove already attached file if any raise ff.UnmodifiedField() # value is a 2-uple (filename, stream) try: filename, stream = value except ValueError: raise ff.UnmodifiedField() # XXX avoid in memory loading of posted files. Requires Binary handling changes... value = Binary(stream.read()) if not value.getvalue(): # usually an unexistant file value = None else: # set filename on the Binary instance, may be used later in hooks value.filename = ff.normalize_filename(filename) return value