from ming import schema as s, Field
from ming.odm import FieldProperty, ForeignIdProperty, RelationProperty
from ming.odm import Mapper
from ming.odm.declarative import MappedClass
from ming import fs
from tgming import SynonymProperty, ProgrammaticRelationProperty
import os
from session import DBSession
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)
As you can see, the fs.filesystem can't take an ODMSession (ThreadLocalODMSession in this case),
so i have to drop down to basic ming Session class by doing DBSession.impl,
what i'm worried is, Turbogears has been using ThreadLocalODMSession to adapt to multi-threaded environment,
but what i'm doing above is giving the GridFS Connection the non thread-safe Session,
is that okay?
how should i do this correctly/safely ?
Anyhelp would be appreciated,
Thanks :)