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,將不勝感激, 謝謝:)