self.update_index(self.objects_deleted, arefs) for obj in self.objects_added: g.zarkov_event('create', extra=obj.index_id()) for obj in self.objects_modified: g.zarkov_event('modify', extra=obj.index_id()) for obj in self.objects_deleted: g.zarkov_event('delete', extra=obj.index_id()) self.objects_added = [] self.objects_modified = [] self.objects_deleted = [] def update_index(self, objects_deleted, arefs): # Post delete and add indexing operations from allura.tasks import index_tasks if objects_deleted: index_tasks.del_artifacts.post( [obj.index_id() for obj in objects_deleted]) if arefs: index_tasks.add_artifacts.post([aref._id for aref in arefs]) main_doc_session = Session.by_name('main') project_doc_session = Session.by_name('project') main_orm_session = ThreadLocalORMSession(main_doc_session) project_orm_session = ThreadLocalORMSession(project_doc_session) artifact_orm_session = ThreadLocalORMSession( doc_session=project_doc_session, extensions = [ ArtifactSessionExtension ]) repository_orm_session = ThreadLocalORMSession( doc_session=main_doc_session, extensions = [ ])
import datetime from ming.datastore import DataStore from ming import Session from ming.orm.ormsession import ThreadLocalORMSession bind = DataStore('mongodb://localhost:27017/orm_tutorial') doc_session = Session(bind) session = ThreadLocalORMSession(doc_session=doc_session) from ming import schema from ming.orm.mapped_class import MappedClass from ming.orm.property import FieldProperty, ForeignIdProperty, RelationProperty class WikiPage(MappedClass): class __mongometa__: session = session name = 'pages' _id = FieldProperty(schema.ObjectId) author = FieldProperty(str) title = FieldProperty(str) tags = FieldProperty([str]) date = FieldProperty(datetime.datetime) text = FieldProperty(str) comments = RelationProperty('WikiComment') class WikiComment(MappedClass): class __mongometa__: session = session
class __mongometa__: session = ThreadLocalORMSession(Session.by_name('sprox_tests'))
session._kwargs['extensions'] = extensions or [] yield session # if successful, flush the session to ensure everything # new is written using the modified extensions session.flush() session.close() finally: # restore proper session extension even if everything goes horribly awry session._kwargs['extensions'] = original_exts main_doc_session = Session.by_name('main') project_doc_session = Session.by_name('project') task_doc_session = Session.by_name('task') main_orm_session = ThreadLocalORMSession( doc_session=main_doc_session, extensions=[IndexerSessionExtension] ) main_explicitflush_orm_session = ThreadLocalORMSession( doc_session=main_doc_session, extensions=[IndexerSessionExtension, ExplicitFlushOnlySessionExtension] ) project_orm_session = ThreadLocalORMSession( doc_session=project_doc_session, extensions=[IndexerSessionExtension] ) task_orm_session = ThreadLocalORMSession(task_doc_session) artifact_orm_session = ThreadLocalORMSession( doc_session=project_doc_session, extensions=[ArtifactSessionExtension]) repository_orm_session = ThreadLocalORMSession( doc_session=main_doc_session,