0
明GridFS的支持从0.3版本开始,我已经在几个TurboGears中使用它的应用,因此到目前为止,但无法找到如何使用GridFS的与明的任何文件,在TurboGears中使用与明ODM GridFS的
这是我到目前为止已经做了,在我的模型store.py
模块:
#import statements
BookFile = fs.filesystem('books',DBSession.impl,)
class Book(MappedClass):
"""
Book definition.
"""
class __mongometa__:
session = DBSession
name = 'books'
unique_indexes = [('title',),('author',),]
_id = FieldProperty(s.ObjectId)
title = FieldProperty(s.String)
author = FieldProperty(s.String)
isbn = FieldProperty(s.String)
vendor = FieldProperty(s.String)
_file = FieldProperty(s.ObjectId)
def _get_file(self):
return BookFile.m.find(dict(_id=self._file)).one()
def _set_file(self, name, data):
f = BookFile.m.put(name,data)
self._file = f
bookf = SynonymProperty(_get_file, _set_file)
正如你所看到的,fs.filesystem
不能采取ODMSession
(ThreadLocalODMSession
在这种情况下),所以我有砸下来到基本ming.Session
做的课DBSession.impl
。
我很担心的是,Turbogears一直使用ThreadLocalODMSession来适应多线程环境,但是我上面做的是给GridFS连接一个非线程安全的会话。
是吗?
我应该如何正确/安全地做到这一点?
Anyhelp,将不胜感激, 谢谢:)