def update(self): fti = self.context.fti self.fti_id = fti.getId() self.sql_id_column = fti.sql_id_column and fti.sql_id_column or 'id' self.factory_utility = queryUtility(IFactory, name=fti.factory) self.sqlfti = ISQLTypeSettings(fti) self.sql_folder_id = getattr(self.sqlfti, 'sql_folder_id', self.fti_id) self.sqlschema = self.context.fti.lookupSchema() connection = queryUtility(ISQLConnectionsUtility, name=self.fti_id, default=None) if connection == None and self.portal_type: fti = queryUtility(IDexterityFTI, name=self.fti_id, default=None) if not fti: return None updateConnectionsForFti(fti) connection = queryUtility(ISQLConnectionsUtility, name=self.fti_id, default=None) self.connection = connection self.fieldnames = self.connection.fieldnames portal_obj = getToolByName(self.context, 'portal_url') self.portal_url = portal_obj() portal = portal_obj.getPortalObject() self.catalog = getToolByName(portal, "portal_catalog") super(SQLItemListingForm, self).update()
def _unrestrictedGetObject(self): parent = aq_parent(self) if (aq_get(parent, 'REQUEST', None) is None and _GLOBALREQUEST_INSTALLED and _REQUESTCONTAINER_EXISTS): request = getRequest() if request is not None: # path should be absolute, starting at the physical root parent = self.getPhysicalRoot() request_container = RequestContainer(REQUEST=request) parent = aq_base(parent).__of__(request_container) try: return parent.unrestrictedTraverse(self.getPath()) except: connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) if connection == None and self.portal_type: fti = queryUtility(IDexterityFTI, name=self.portal_type, default=None) if not fti: return None updateConnectionsForFti(fti) connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) return connection.getVirtualItem(self.sql_id, context=parent)
def getObject(self, REQUEST=None): path = self.getPath().split('/') if not path: return None parent = aq_parent(self) if (aq_get(parent, 'REQUEST', None) is None and _GLOBALREQUEST_INSTALLED and _REQUESTCONTAINER_EXISTS): request = getRequest() if request is not None: # path should be absolute, starting at the physical root parent = self.getPhysicalRoot() request_container = RequestContainer(REQUEST=request) parent = aq_base(parent).__of__(request_container) if len(path) > 1: try: parent = parent.unrestrictedTraverse(path[:-1]) except: if path[:-2] == 'data-'+self.portal_type: parent = queryMultiAdapter((None, ICollectiveBehaviorSQLLayer), IBrowserView, name='data-'+name, default=None) try: return parent.restrictedTraverse(path[-1]) except: connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) if connection == None and self.portal_type: fti = queryUtility(IDexterityFTI, name=self.portal_type, default=None) if not fti: return None updateConnectionsForFti(fti) connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) return connection.getVirtualItem(self.sql_id, context=parent)
def create(self, data): LOG.info('create: ' + str(self.portal_type)) fti = getUtility(IDexterityFTI, name=self.portal_type) container = aq_inner(self.context) options = {} options['portal_type'] = self.portal_type options['sql_id'] = str(data.get('ISQLContent.sql_id')) content = createObject(fti.factory, **options) # Note: The factory may have done this already, but we want to be sure # that the created type has the right portal type. It is possible # to re-define a type through the web that uses the factory from an # existing type, but wants a unique portal_type! if hasattr(content, '_setPortalTypeName'): content._setPortalTypeName(fti.getId()) # Acquisition wrap temporarily to satisfy things like vocabularies # depending on tools if IAcquirer.providedBy(content): content = content.__of__(container) # Don't set empty data in SQL DB: for k, v in data.items(): if not v: del data[k] connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) if connection == None and self.portal_type: fti = queryUtility(IDexterityFTI, name=self.portal_type, default=None) if not fti: return None updateConnectionsForFti(fti) connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) if options.get('sql_id'): for name in connection.fieldnames.keys(): for k, v in data.items(): if name == k or '.' + name in k: del data[k] form.applyChanges(self, content, data) for group in self.groups: form.applyChanges(group, content, data) return aq_base(content)
def resolve_path(self, path): obj = base_resolve_path(self, path) if obj == None: parent = base_resolve_path(self, '/'.join(path.split('/')[:-1])) try: obj = parent.restrictedTraverse(path[-1]) except: connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) if connection == None and self.portal_type: fti = queryUtility(IDexterityFTI, name=self.portal_type, default=None) if not fti: return None updateConnectionsForFti(fti) connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) obj = connection.getVirtualItem(self.sql_id, context=parent) return obj
def create(self, data): LOG.info('create: '+str(self.portal_type)) fti = getUtility(IDexterityFTI, name=self.portal_type) container = aq_inner(self.context) options = {} options['portal_type'] = self.portal_type options['sql_id'] = str(data.get('ISQLContent.sql_id')) content = createObject(fti.factory, **options) # Note: The factory may have done this already, but we want to be sure # that the created type has the right portal type. It is possible # to re-define a type through the web that uses the factory from an # existing type, but wants a unique portal_type! if hasattr(content, '_setPortalTypeName'): content._setPortalTypeName(fti.getId()) # Acquisition wrap temporarily to satisfy things like vocabularies # depending on tools if IAcquirer.providedBy(content): content = content.__of__(container) # Don't set empty data in SQL DB: for k,v in data.items(): if not v: del data[k] connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) if connection == None and self.portal_type: fti = queryUtility(IDexterityFTI, name=self.portal_type, default=None) if not fti: return None updateConnectionsForFti(fti) connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) if options.get('sql_id'): for name in connection.fieldnames.keys(): for k,v in data.items(): if name == k or '.'+name in k: del data[k] form.applyChanges(self, content, data) for group in self.groups: form.applyChanges(group, content, data) return aq_base(content)
def connection(self): connection = None if self.sql_connection and self.sql_table: try: connection = getUtility(ISQLConnectionsUtility, name=self.context.id) except: connection = updateConnectionsForFti(self.context) if not getattr(connection, 'name', None): return None return connection
def getObject(self, REQUEST=None): path = self.getPath().split('/') if not path: return None parent = aq_parent(self) if (aq_get(parent, 'REQUEST', None) is None and _GLOBALREQUEST_INSTALLED and _REQUESTCONTAINER_EXISTS): request = getRequest() if request is not None: # path should be absolute, starting at the physical root parent = self.getPhysicalRoot() request_container = RequestContainer(REQUEST=request) parent = aq_base(parent).__of__(request_container) if len(path) > 1: try: parent = parent.unrestrictedTraverse(path[:-1]) except: if path[:-2] == 'data-' + self.portal_type: parent = queryMultiAdapter((None, ICollectiveBehaviorSQLLayer), IBrowserView, name='data-' + name, default=None) try: return parent.restrictedTraverse(path[-1]) except: connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) if connection == None and self.portal_type: fti = queryUtility(IDexterityFTI, name=self.portal_type, default=None) if not fti: return None updateConnectionsForFti(fti) connection = queryUtility(ISQLConnectionsUtility, name=self.portal_type, default=None) return connection.getVirtualItem(self.sql_id, context=parent)
def update(self): fti = self.context.fti self.fti_id = fti.getId() self.sql_id_column = fti.sql_id_column and fti.sql_id_column or 'id' self.factory_utility = queryUtility(IFactory, name=fti.factory) self.sqlfti = ISQLTypeSettings(fti) self.sql_folder_id = getattr(self.sqlfti, 'sql_folder_id', self.fti_id) self.sqlschema = self.context.fti.lookupSchema() connection = queryUtility(ISQLConnectionsUtility, name=self.fti_id, default=None) if connection == None and self.portal_type: fti = queryUtility(IDexterityFTI, name=self.fti_id, default=None) if not fti: return None updateConnectionsForFti(fti) connection = queryUtility(ISQLConnectionsUtility, name=self.fti_id, default=None) self.connection = connection self.fieldnames = self.connection.fieldnames portal_obj = getToolByName( self.context, 'portal_url') self.portal_url = portal_obj() portal = portal_obj.getPortalObject() self.catalog = getToolByName(portal, "portal_catalog") super(SQLItemListingForm, self).update()
def _set_sql_id_column(self, value): if not value: value = '' updateConnectionsForFti(self.context) self.context.sql_id_column = value