- Timestamp:
- 08/05/10 18:37:06 (22 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
plone4bio.biosql/trunk/src/plone4bio/biosql/content/root.py
r112 r153 1 # -*- coding: utf-8 -*- 1 2 __author__ = '''Mauro Amico <mauro@biodec.com>''' 2 3 __docformat__ = 'plaintext' 3 4 5 from threading import local 4 6 from zope.interface import implements 5 7 from zope.component.factory import Factory 6 8 from zope.schema.fieldproperty import FieldProperty 9 10 from Acquisition import aq_base 7 11 8 12 from plone.app.content.container import Container … … 14 18 from Products.CMFPlone.utils import base_hasattr 15 19 from Products.CMFPlone.utils import safe_callable 20 from Products.CMFPlone.interfaces.constrains import IConstrainTypes 21 22 from Products.ATContentTypes.content.base import ATCTContent 23 from Products.ATContentTypes.content.schemata import ATContentTypeSchema 24 25 from Products.Archetypes import atapi 26 27 from Products.Archetypes.atapi import Schema 28 from Products.Archetypes.atapi import BooleanWidget 29 from Products.Archetypes.atapi import StringField 30 from Products.Archetypes.atapi import StringWidget 31 from Products.Archetypes.atapi import registerType 32 16 33 from zope.app.container.interfaces import IContainer 17 34 from plone.app.content.interfaces import INameFromTitle … … 43 60 return self.dsn 44 61 45 # WebDAV ... Collection 46 # class BioSQLRoot(BaseContent, BrowserDefaultMixin): 62 """ 63 47 64 class BioSQLRoot(Container): 48 __implements__ = (BrowserDefaultMixin.__implements__)49 65 portal_type='BioSQLRoot' 66 50 67 implements(IBioSQLRoot, IContainer, IFolderish, INameFromTitle) 68 51 69 security = ClassSecurityInfo() 52 70 # isPrincipiaFolderish = True # already on Container 53 dsn = FieldProperty(IBioSQLRoot['dsn']) 71 # dsn = FieldProperty(IBioSQLRoot['dsn']) 72 dsn = 'postgres://postgres@localhost/plone4bio' 54 73 seqrecord_key = FieldProperty(IBioSQLRoot['seqrecord_key']) 55 _v_dbserver = None 74 _v_thread_local = local() 75 76 def __init__(self, *args, **kwargs): 77 if kwargs.has_key('parent'): 78 parent = kwargs['parent'] 79 del(kwargs['parent']) 80 super(BioSQLRoot, self).__init__(*args, **kwargs) 81 """ 82 83 84 Plone4BioSchema = ATContentTypeSchema.copy() + Schema(( 85 StringField("dsn", 86 required = True, 87 widget = StringWidget( 88 label = "dsn", 89 label_msgid = "dsn_label", 90 description = "DSN " 91 "... " 92 "...", 93 description_msgid = "dsn_help", 94 i18n_domain = "plone4bio") 95 ), 96 )) 97 98 class BioSQLRoot(ATCTContent): 99 portal_type='BioSQLRoot' 100 101 implements(IBioSQLRoot, IConstrainTypes) 102 103 security = ClassSecurityInfo() 104 schema = Plone4BioSchema 105 _at_rename_after_creation = True 106 isPrincipiaFolderish = True 107 # dsn = atapi.ATFieldProperty('dsn') 108 dsn = 'postgres://postgres@localhost/plone4bio' 109 seqrecord_key = "version" 110 _v_thread_local = local() 111 112 # XXX 113 def getLocallyAllowedTypes(self): 114 return [] 56 115 57 116 # see CMFPlone/CatalogTool.py 58 117 def refreshCatalog(self, clear=1): 118 return 59 119 def indexObject(obj, path): 60 120 if (base_hasattr(obj, 'indexObject') and … … 66 126 # take different args, and will fail 67 127 pass 128 except: # CatalogError: 129 # import pdb; pdb.set_trace() 130 # obj.indexObject() 131 logger.exception("indexObject %r for %r" % (obj, self)) 68 132 for database in self.values(): 69 133 database.invalidateCache() … … 73 137 portal_catalog.ZopeFindAndApply(self, search_sub=True, apply_func=indexObject) 74 138 139 """ 75 140 def __getattr__(self, name): 76 141 if self.has_key(name): … … 78 143 else: 79 144 raise AttributeError, name 145 """ 80 146 81 147 security.declareProtected(View, "getBioSQLRoot") … … 91 157 if not self.dsn: 92 158 return None 93 if self._v_dbserver is None or not self._v_dbserver.adaptor.conn.is_valid: 159 dbserver = getattr(self._v_thread_local, 'dbserver', None) 160 if dbserver is None or not dbserver.adaptor.conn.is_valid: 94 161 try: 95 162 wrapper = getSAWrapper(self.dsn) … … 97 164 wrapper = createSAWrapper(dsn=self.dsn, name=self.dsn) 98 165 #TODO: manage OperationalError on connection 99 self._v_dbserver = DBServer(wrapper.connection, __import__(drivers[self.dsn.split(':')[0]])) 100 return self._v_dbserver 166 dbserver = DBServer(wrapper.connection, __import__(drivers[self.dsn.split(':')[0]])) 167 self._v_thread_local.dbserver = dbserver 168 return dbserver 101 169 102 170 security.declareProtected(View, "getValues") … … 123 191 logger.exception("getDBServer") 124 192 raise StopIteration 193 if not dbserver: 194 raise StopIteration 125 195 for name in dbserver.keys(): 126 yield name196 yield str(name) 127 197 #try: 128 198 # for name in dbserver.keys(): … … 149 219 yield (k, self[k]) 150 220 221 def __bobo_traverse__(self, REQUEST, name): 222 try: 223 return self[name] 224 except KeyError: 225 pass 226 if hasattr(aq_base(self), name): 227 return getattr(self, name) 228 # webdav 229 """ 230 method = REQUEST.get('REQUEST_METHOD', 'GET').upper() 231 if (method not in ('GET', 'POST') and not 232 isinstance(REQUEST.RESPONSE, xmlrpc.Response) and 233 REQUEST.maybe_webdav_client and not REQUEST.path): 234 return ReflectoNullResource(self, name, REQUEST).__of__(self) 235 """ 236 return ATCTContent.__bobo_traverse__(self, REQUEST, name) 237 151 238 # zope2/lib/python/OFS/ObjectManager.py 152 239 def _getOb(self, id, default=_marker): … … 194 281 setattr(BioSQLRoot, m, getattr(DictMixin, m).im_func) 195 282 283 # XXX: ??? 196 284 bioSQLRootFactory = Factory(BioSQLRoot, title=_(u"Create a new BioSQL Root")) 285 286 atapi.registerType(BioSQLRoot, 'plone4bio.biosql') 287
