equal
deleted
inserted
replaced
111 |
111 |
112 |
112 |
113 class BytesFileSystemStorage(Storage): |
113 class BytesFileSystemStorage(Storage): |
114 """store Bytes attribute value on the file system""" |
114 """store Bytes attribute value on the file system""" |
115 def __init__(self, defaultdir, fsencoding='utf-8'): |
115 def __init__(self, defaultdir, fsencoding='utf-8'): |
|
116 if type(defaultdir) is unicode: |
|
117 defaultdir = defaultdir.encode(fsencoding) |
116 self.default_directory = defaultdir |
118 self.default_directory = defaultdir |
117 self.fsencoding = fsencoding |
119 self.fsencoding = fsencoding |
118 |
120 |
119 def callback(self, source, session, value): |
121 def callback(self, source, session, value): |
120 """sql generator callback when some attribute with a custom storage is |
122 """sql generator callback when some attribute with a custom storage is |
199 # well as providing more understandable file names on the fs. |
201 # well as providing more understandable file names on the fs. |
200 basename = [str(entity.eid), attr] |
202 basename = [str(entity.eid), attr] |
201 name = entity.cw_attr_metadata(attr, 'name') |
203 name = entity.cw_attr_metadata(attr, 'name') |
202 if name is not None: |
204 if name is not None: |
203 basename.append(name.encode(self.fsencoding)) |
205 basename.append(name.encode(self.fsencoding)) |
204 fspath = uniquify_path(self.default_directory, '_'.join(basename)) |
206 fspath = uniquify_path(self.default_directory, |
|
207 '_'.join(basename)) |
205 if fspath is None: |
208 if fspath is None: |
206 msg = entity._cw._('failed to uniquify path (%s, %s)') % ( |
209 msg = entity._cw._('failed to uniquify path (%s, %s)') % ( |
207 self.default_directory, '_'.join(basename)) |
210 self.default_directory, '_'.join(basename)) |
208 raise ValidationError(entity.eid, {role_name(attr, 'subject'): msg}) |
211 raise ValidationError(entity.eid, {role_name(attr, 'subject'): msg}) |
209 return fspath |
212 return fspath |