def manage_beforeDelete(self, item, container): """ """ #delete objects dynamic properties l_ids = self.getDynamicPropertiesIds() for l_object in self.getCatalogedObjects(self.id): map(l_object.deleteProperty, l_ids) SimpleItem.inheritedAttribute('manage_beforeDelete')(self, item, container)
def _setup_workflow(self): args = {'id': 'collection', 'title': 'mock_collection', 'year': '2011', 'endyear': '2012', 'partofyear': 'wholeyear', 'country': 'http://rod.eionet.eu.int/spatial/2', 'locality': '', 'descr': '', 'dataflow_uris': ['http://rod.eionet.eu.int/obligations/8'], 'dataflow_uris': [], 'allow_collections': True, 'allow_envelopes': True} col = Collection(**args) self.app._setObject('collection', col) self.app._setObject('Templates', Folder('Templates')) template = SimpleItem() template.id = 'StartActivity' template.__call__ = Mock(return_value='Envelope Test Template') self.app.Templates._setOb('StartActivity', template) self.app.Templates.StartActivity.title_or_id = Mock(return_value='Start Activity Template') self.create_process(self, 'process') self.wf.addApplication('StartActivity', 'Templates/StartActivity') self.wf.process.addActivity('AutoBegin', split_mode='xor', join_mode='xor', start_mode=1, application='StartActivity') self.wf.process.begin = 'AutoBegin' self.wf.setProcessMappings('process', '1', '1')
def persistent_load(ref): assert ref == 'ignored' # Return a placeholder object that will be replaced by # removeNonVersionedData(). placeholder = SimpleItem() placeholder.id = "ignored_subobject" return placeholder
def manage_afterAdd(self, item, container): """ manage the add """ SimpleItem.inheritedAttribute('manage_afterAdd')(self, item, container) item.load_roles_list() item.load_languages_list() item.load_stop_words_list() item.load_subjects_list()
def testBoboTraverseTraversalDefault(self): from OFS.SimpleItem import SimpleItem from ZPublisher.interfaces import UseTraversalDefault class BoboTraversableUseTraversalDefault(SimpleItem): """ A BoboTraversable class which may use "UseTraversalDefault" (dependent on "name") to indicate that standard traversal should be used. """ default = 'Default' def __bobo_traverse__(self, request, name): if name == 'normal': return 'Normal' raise UseTraversalDefault bb = BoboTraversableUseTraversalDefault() # normal access -- no traversal default used self.assertEqual(bb.unrestrictedTraverse('normal'), 'Normal') # use traversal default self.assertEqual(bb.unrestrictedTraverse('default'), 'Default') # test traversal default with acqires attribute si = SimpleItem() si.default_acquire = 'Default_Acquire' si.bb = bb self.assertEqual(si.unrestrictedTraverse('bb/default_acquire'), 'Default_Acquire')
def manage_beforeDelete(self, item, container): """ This method is called, when the object is deleted. """ SimpleItem.inheritedAttribute('manage_beforeDelete')(self, item, container) try: self.getPortletsTool()._delObject(ID_REFLIST) except: pass
def test_standard_error_message_is_called(self): from zExceptions import BadRequest from OFS.SimpleItem import SimpleItem # handle_errors should default to True. It is a flag used for # functional doctests. See ZPublisher/Test.py and # ZPublisher/Publish.py. class REQUEST(object): class RESPONSE(object): handle_errors = True class StandardErrorMessage(object): def __init__(self): self.kw = {} def __call__(self, **kw): self.kw.clear() self.kw.update(kw) item = SimpleItem() item.standard_error_message = sem = StandardErrorMessage() try: raise BadRequest("1") except: item.raise_standardErrorMessage(client=item, REQUEST=REQUEST()) self.assertEquals(sem.kw.get('error_type'), 'BadRequest')
def manage_beforeDelete(self, item, container): """ this method is called, when the object is deleted """ if self.meta_type == EEA_GLOSSARY_ELEMENT_METATYPE: self.utSynonymElDel() else: self.utElementSynDel() SimpleItem.inheritedAttribute('manage_beforeDelete')(self, item, container) self.cu_uncatalog_object(self)
def manage_beforeDelete(self, item, container): SimpleItem.manage_beforeDelete(self, item, container) if self is item: # unregister self from catalog on deletion # While building business template, transform tool will be # copied and this transform will be removed from copied one # so that this must not use getToolByName to retrive the tool. tr_tool = self.aq_parent tr_tool._unmapTransform(self)
def __init__(self, id, max_age, number_to_keep, pub_path): SimpleItem.inheritedAttribute('__init__')(self, id, '[VersionCleanUp Helper object]') self.id = id self._description = self.__doc__ self._max_age = self._number_to_keep = self._removed = 0 self._pub_path = pub_path self.set_max_age(max_age) self.set_number_to_keep(number_to_keep) self.set_pub_path(pub_path)
def __setstate__(self, *args, **kwargs): """ When an instance of SAWrapper is unpickled, perform the normal 'wakeup', but also ensure that the instance is in the module registry of instances. """ # Don't use 'super' when old-style classes are involved. SimpleItem.__setstate__(self, *args, **kwargs) register_sa_wrapper(self.id, self._wrapper)
def manage_afterAdd(self, item, container): """ """ #create objects dynamic properties l_dp_dict = {} lang = self.gl_get_selected_language() for dp in self.getDynamicProperties(): l_dp_dict[dp.id] = dp.defaultvalue for l_object in self.getCatalogedObjects(self.id): l_object.createDynamicProperties(l_dp_dict, lang) SimpleItem.inheritedAttribute('manage_afterAdd')(self, item, container)
def manage_afterAdd(self, item, container): SimpleItem.manage_afterAdd(self, item, container) portal_url = getToolByName(container, 'portal_url') storagePath = portal_url.getPortalPath() + '/pdfs' self.DEFAULT_STORAGE_PATHS = [storagePath] self.DEFAULT_STORAGE_PATH = self.DEFAULT_STORAGE_PATHS[0] if self.storagePath is None: self.storagePath = storagePath if self.storagePaths is None: self.storagePaths = [self.storagePath]
def __init__(self, context, request, previous=[]): SimpleItem.__init__(self, context, request) self.previous = previous self.__name__ = 'dvpdffiles' self.site = _getPortal(request, context) self.global_settings = GlobalSettings(self.site) self.storage_type = self.global_settings.storage_type self.__dir = Directory( os.path.join(self.global_settings.storage_location, *previous), self.__name__) DirectoryResource.__init__(self, self.__dir, request)
def __init__(self, context, request, previous=[]): SimpleItem.__init__(self, context, request) self.previous = previous self.__name__ = 'dvpdffiles' self.site = api.portal.get() self.global_settings = GlobalSettings(self.site) self.storage_type = self.global_settings.storage_type self.__dir = Directory( os.path.join(self.global_settings.storage_location, *previous), self.__name__) DirectoryResource.__init__(self, self.__dir, request)
def _makeOne(self, id='date'): index = self._getTargetClass()(id) class DummyZCatalog(SimpleItem): id = 'DummyZCatalog' # Build pseudo catalog and REQUEST environment catalog = makerequest(DummyZCatalog()) indexes = SimpleItem() indexes = indexes.__of__(catalog) index = index.__of__(indexes) return index
def test_delitem(self): om = self._makeOne() si1 = SimpleItem('1') si2 = SimpleItem('2') om['1'] = si1 om['2'] = si2 self.assertTrue('1' in om) self.assertTrue('2' in om) del om['1'] self.assertFalse('1' in om) self.assertTrue('2' in om) om._delObject('2') self.assertFalse('2' in om)
def test_getsetitem(self): om = self._makeOne() si1 = SimpleItem('1') si2 = SimpleItem('2') om['1'] = si1 self.assertTrue('1' in om) self.assertTrue(si1 in om.objectValues()) self.assertTrue('1' in om.objectIds()) om['2'] = si2 self.assertTrue('2' in om) self.assertTrue(si2 in om.objectValues()) self.assertTrue('2' in om.objectIds()) self.assertRaises(BadRequest, om._setObject, '1', si2) self.assertRaises(BadRequest, om.__setitem__, '1', si2)
def _makeOne(self, *args, **kw): index = self._getTargetClass()(*args, **kw) class DummyZCatalog(SimpleItem): id = 'DummyZCatalog' # Build pseudo catalog and REQUEST environment catalog = makerequest(DummyZCatalog()) indexes = SimpleItem() indexes = indexes.__of__(catalog) index = index.__of__(indexes) return index
def _makeOne(self, id, extra=None): klass = self._getTargetClass() index = klass(id, extra=extra) class DummyZCatalog(SimpleItem): id = 'DummyZCatalog' # Build pseudo catalog and REQUEST environment catalog = makerequest(DummyZCatalog()) indexes = SimpleItem() indexes = indexes.__of__(catalog) index = index.__of__(indexes) return index
def test_iterator(self): om = self._makeOne() si1 = SimpleItem('1') si2 = SimpleItem('2') om['1'] = si1 om['2'] = si2 iterator = iter(om) self.assertTrue(hasattr(iterator, '__iter__')) if PY2: self.assertTrue(hasattr(iterator, 'next')) else: self.assertTrue(hasattr(iterator, '__next__')) result = [i for i in iterator] self.assertTrue('1' in result) self.assertTrue('2' in result)
def manage_afterAdd(self, item, container) : """ """ SimpleItem.manage_afterAdd(self, item, container) self.locationCode = "" self.cacheDuration = 60 * 60 * CACHE_DURATION_IN_HOURS self.numDaysInPortlet = 3 self.portletType = PORTLET_MULTIPLE self.languageCode = "es" self.cache = { "date" : 0, "data" : {"error" : "No data"}, }
def test__init__userid_in_request_form_for_manager(self): # should allow for privileged users context = makerequest(SimpleItem('foo')) context.portal_membership = DummyPortalMembership(True) context.REQUEST.form['userid'] = 'bob' adapter = AccountPanelSchemaAdapter(context) self.assertEqual('bob', adapter.context)
def test_withTwo(self): parent = Folder() parent._setObject('plugins', DummyPluginRegistry()) scriptable_plugin = self._makeOne().__of__(parent) faux_method = SimpleItem('faux_method') two_method = SimpleItem('two_method') scriptable_plugin._setObject('faux_method', faux_method) scriptable_plugin._setObject('two_method', two_method) scriptable_plugin.manage_updateInterfaces(['IFaux', 'IFauxTwo']) self.assertEqual(len(scriptable_plugin.__implements__), 4)
def test__init__userid_in_request_form_for_non_manager(self): # disallow for non-privileged users context = makerequest(SimpleItem('foo')) context.portal_membership = DummyPortalMembership(False) context.REQUEST.form['userid'] = 'bob' adapter = AccountPanelSchemaAdapter(context) self.assertEqual('(authenticated)', adapter.context)
def test___getitem___hit(self): om = self._makeOne() si1 = SimpleItem('1') om['1'] = si1 got = om['1'] self.assertTrue(got.aq_self is si1) self.assertTrue(got.aq_parent is om)
def manage_afterAdd(self, item, container): """ Ensure that a new utility id is assigned after creating or copying an instance. """ self._new_utilid() register_sa_wrapper(self.id, self._wrapper) return SimpleItem.manage_afterAdd(self, item, container)
def test_get_hit(self): om = self._makeOne() si1 = SimpleItem('1') om['1'] = si1 got = om.get('1') self.assertTrue(aq_self(got) is si1) self.assertTrue(got.__parent__ is om)
def test_withTwoOnlyOneWired(self): parent = Folder() parent._setObject('plugins', DummyPluginRegistry()) scriptable_plugin = self._makeOne().__of__(parent) faux_method = SimpleItem('faux_method') whatever = SimpleItem('whatever') scriptable_plugin._setObject('faux_method', faux_method) scriptable_plugin._setObject('whatever', whatever) scriptable_plugin.manage_updateInterfaces(['IFaux']) self.assertTrue(IFaux in providedBy(scriptable_plugin))
def test_setObject_set_owner_with_system_user(self): om = self._makeOne() newSecurityManager(None, system) si = SimpleItem('system') self.assertEqual(si.__ac_local_roles__, None) om._setObject('system', si) self.assertEqual(si.__ac_local_roles__, None)
def testRemoveEmptySector(self): from OFS.SimpleItem import SimpleItem survey = self.createSurvey() clientcountry = self.portal.client["nl"] clientcountry["other"] = SimpleItem("other") self.handleSurveyUnpublish(survey, None) self.assertEqual(self.portal.client["nl"].keys(), ["other"])
def test_setObject_set_owner_with_emergency_user(self): om = self._makeOne() newSecurityManager(None, emergency_user) si = SimpleItem('should_fail') self.assertEqual(si.__ac_local_roles__, None) self.assertRaises(EmergencyUserCannotOwn, om._setObject, 'should_fail', si)
def testPublishedSurvey(self): from OFS.SimpleItem import SimpleItem survey = self.createSurvey() clientsector = self.portal.client["nl"]["ict"] clientsector["other"] = SimpleItem("other") self.handleSurveyUnpublish(survey, None) self.assertEqual(self.portal.client["nl"]["ict"].keys(), ["other"])
def _makeOne(self, id, since_field=None, until_field=None, caller=None, extra=None): klass = self._getTargetClass() index = klass(id, since_field, until_field, caller, extra) class DummyZCatalog(SimpleItem): id = 'DummyZCatalog' # Build pseudo catalog and REQUEST environment catalog = makerequest(DummyZCatalog()) indexes = SimpleItem() indexes = indexes.__of__(catalog) index = index.__of__(indexes) return index
def test_setObject_no_set_owner_with_anonymous_user(self): om = self._makeOne() newSecurityManager(None, nobody) si = SimpleItem('should_be_okay') self.assertEqual(si.__ac_local_roles__, None) om._setObject('should_be_okay', si, set_owner=0) self.assertEqual(si.__ac_local_roles__, None)
def test_withTwo(self): parent = Folder() parent._setObject('plugins', DummyPluginRegistry()) scriptable_plugin = self._makeOne().__of__(parent) faux_method = SimpleItem('faux_method') two_method = SimpleItem('two_method') scriptable_plugin._setObject('faux_method', faux_method) scriptable_plugin._setObject('two_method', two_method) scriptable_plugin.manage_updateInterfaces(['IFaux', 'IFauxTwo']) self.failUnless(IFaux in providedBy(scriptable_plugin)) self.failUnless(IFauxTwo in providedBy(scriptable_plugin))
def create_cepaa_set(self, idx): col_id = "col%s" %idx env_id = "env%s" %idx proc_id = "proc%s" %idx act_id = "act%s" %idx app_id = "act%s" %idx country = 'http://spatial/%s' %idx dataflow_uris = 'http://obligation/%idx' %idx "create collection, envelope, process, activity, application" col = Collection(col_id, country=country, dataflow_uris=dataflow_uris) self.app._setOb(col_id, col) self.app.Templates.StartActivity = Mock(return_value='Test Application') self.app.Templates.StartActivity.title_or_id = Mock(return_value='Start Activity Template') self.create_process(self, proc_id) self.wf.addApplication(app_id, 'SomeFolder/%s' %app_id) self.app.Applications._setOb(proc_id, Folder(proc_id)) proc = getattr(self.app.Applications, proc_id) app = SimpleItem(app_id) app.id = app_id app.__call__ = Mock(return_value='Test Application') proc._setOb(app_id, app) getattr(self.wf, proc_id).addActivity(act_id, split_mode='xor', join_mode='xor', start_mode=1) getattr(self.wf, proc_id).begin = act_id self.wf.setProcessMappings(proc_id, '1', '1') env = Envelope(process=getattr(self.wf, proc_id), title='FirstEnvelope', authUser='******', year=2012, endyear=2013, partofyear='January', country='http://spatial/1', locality='TestLocality', descr='TestDescription') env._content_registry_ping = Mock() env.id = env_id getattr(self.app, col_id)._setOb(env_id, env) setattr(self, col_id, getattr(self.app, col_id)) setattr(self, env_id, getattr(getattr(self.app, col_id), env_id)) getattr(self, env_id).startInstance(self.app.REQUEST)
def __getattribute__(self, name): try: attr = SimpleItem.__getattribute__(self, 'data').get(name, EMPTY_MARKER) if attr is not EMPTY_MARKER: return attr except AttributeError, e: pass
def _makeOne(self, id='date', precision=1): index = self._getTargetClass()(id) class DummyZCatalog(SimpleItem): id = 'DummyZCatalog' # Build pseudo catalog and REQUEST environment catalog = makerequest(DummyZCatalog()) indexes = SimpleItem() indexes = indexes.__of__(catalog) index = index.__of__(indexes) if precision > 1: index.manage_changeProperties(precision=precision) return index
def test_hasId(self): om = self._makeOne() request = {'id': 'test'} self.assertRaises(KeyError, om.manage_hasId, request) si = SimpleItem('test') om._setObject('test', si) om.manage_hasId(request)
def __setattr__(self, name, value): d = self.__dict__ if name[0] == '_': return SimpleItem.__setattr__(self, name, value) pm = d.get('_property_mapping', {}) d[name] = value if hasattr(self, 'check_%s' % name): value = getattr(self, 'check_%s' % name)(value) mp = pm.get(name, None) if mp and mp != name: setattr(self, mp, value) setattr(self, '_p_changed', 1) else: SimpleItem.__setattr__(self, name, value)
def test_walk_basic(self): from naaya.core.zope2util import ofs_walk fol = Folder('fol').__of__(Folder('root')) self.assertEqual(list(ofs_walk(fol)), []) item = SimpleItem('item') fol._setObject('item', item) self.assertEqual(list(ofs_walk(fol)), [item]) fol2 = Folder('fol2') fol._setObject('fol2', fol2) self.assertEqual(list(ofs_walk(fol)), [item, fol2]) item2 = SimpleItem('item2') fol2._setObject('item2', item2) self.assertEqual(list(ofs_walk(fol)), [item, fol2, item2])
def test_setObject_set_owner_with_faux_user(self): om = self._makeOne() user = FauxUser('user_id', 'user_login').__of__(FauxRoot()) newSecurityManager(None, user) si = SimpleItem('faux_creation') self.assertEqual(si.__ac_local_roles__, None) om._setObject('faux_creation', si) self.assertEqual(si.__ac_local_roles__, {'user_id': ['Owner']})
def test_setObject_no_set_owner_with_faux_user(self): om = self._makeOne() user = FauxUser('user_id', 'user_login').__of__(FauxRoot()) newSecurityManager(None, user) si = SimpleItem('should_be_okay') self.assertEqual(si.__ac_local_roles__, None) om._setObject('should_be_okay', si, set_owner=0) self.assertEqual(si.__ac_local_roles__, None)
def manage_afterAdd(self, item, container): """ Ensure that a new utility id is assigned after creating or copying an instance. """ self._new_utilid() wrapper = self.sa_zope_wrapper() if wrapper: register_sa_wrapper(self.id, wrapper) return SimpleItem.manage_afterAdd(self, item, container)
def test_setObject_checkId_bad(self): om = self._makeOne() si = SimpleItem('111') om._setObject('111', si) si = SimpleItem('2') self.assertRaises(BadRequest, om._setObject, 123, si) self.assertRaises(BadRequest, om._setObject, 'a\x01b', si) self.assertRaises(BadRequest, om._setObject, 'a\\b', si) self.assertRaises(BadRequest, om._setObject, 'a:b', si) self.assertRaises(BadRequest, om._setObject, 'a;b', si) self.assertRaises(BadRequest, om._setObject, '.', si) self.assertRaises(BadRequest, om._setObject, '..', si) self.assertRaises(BadRequest, om._setObject, '_foo', si) self.assertRaises(BadRequest, om._setObject, 'aq_me', si) self.assertRaises(BadRequest, om._setObject, 'bah__', si) self.assertRaises(BadRequest, om._setObject, '111', si) self.assertRaises(BadRequest, om._setObject, 'REQUEST', si) self.assertRaises(BadRequest, om._setObject, '/', si)
def test_stdout(self): # You can pass a stdout arg and it's used by the response. import io out = io.BytesIO() item = makerequest(SimpleItem(), stdout=out) item.REQUEST.RESPONSE.write('aaa') out.seek(0) written = out.read() self.assertTrue(written.startswith('Status: 200 OK\r\n')) self.assertTrue(written.endswith('\naaa'))
def test_stdout(self): # You can pass a stdout arg and it's used by the response. import cStringIO out = cStringIO.StringIO() item = makerequest(SimpleItem(), stdout=out) item.REQUEST.RESPONSE.write('aaa') out.seek(0) written = out.read() self.failUnless(written.startswith('Status: 200 OK\n')) self.failUnless(written.endswith('\naaa'))
def test_manage_propertiesForm_allows_adding(self): from OFS.SimpleItem import SimpleItem def _header(*args, **kw): return 'HEADER' def _footer(*args, **kw): return 'HEADER' container = SimpleItem() container.REQUEST = request = DummyRequest() request.set('manage_page_header', _header) request.set('manage_page_footer', _footer) request.set('BASEPATH1', '/one/two') setattr(request, 'URL1', '/one/two') request._steps = ['one', 'two'] prd = {'ac_permissions': ('a', 'b')} container._getProductRegistryData = prd.get a = self._makeOne('extensible').__of__(container) form_html = a.manage_propertiesForm(request) self.failUnless('value=" Add "' in form_html)
def test_manage_propertiesForm_allows_adding(self): from OFS.SimpleItem import SimpleItem def _header(*args, **kw): return 'HEADER' def _footer(*args, **kw): return 'HEADER' def _main(*args, **kw): return 'MAIN' container = SimpleItem() container.REQUEST = request = DummyRequest() request.set('manage_page_header', _header) request.set('manage_page_footer', _footer) request.set('manage_main', _main) request.set('RESPONSE', None) request.set('BASEPATH1', '/one/two') request.set('URL', '/one/two/manage_propertiesForm') request.set('URL0', '/one') request.set('URL1', '/one/two') setattr(request, 'URL1', '/one/two') request._steps = ['one', 'two'] prd = {'ac_permissions': ('a', 'b')} container._getProductRegistryData = prd.get a = self._makeOne('extensible').__of__(container) # EEK short-term solution until a new Zope release is out from App.special_dtml import DTMLFile DTMLFile.encoding = None form_html = a.manage_propertiesForm(request) self.assertIn('value="Add"', form_html)
def manage_afterAdd(self, item, container): """ this method is called, whenever _setObject in ObjectManager gets called """ SimpleItem.inheritedAttribute('manage_afterAdd')(self, item, container) self.cu_catalog_object(self)
def manage_beforeDelete(self, item, container): """ This method is called, when the object is deleted. """ SimpleItem.inheritedAttribute('manage_beforeDelete')(self, item, container) self.delete_portlet_for_object(item)
def manage_beforeDelete(self, item, container): SimpleItem.manage_beforeDelete(self, item, container) if self is item: # unregister self from catalog on deletion tr_tool = getToolByName(self, 'portal_transforms') tr_tool._unmapTransform(self)
def manage_beforeDelete(self, item, container): """ this method is called, when the object is deleted. """ SimpleItem.inheritedAttribute('manage_beforeDelete')(self, item, container) root_obj = self.utGetROOT() root_obj._delRoles(self.__roles.keys(), None)
def __init__(self, **kw): SimpleItem.__init__(self) SchemaConfigured.__init__(self, **kw) MetadataRepository.__init__(self) # maps roles to paths to objects implementing the role self.roles = self.INTERNAL_STORAGE_CLASS()
def __init__(self, *args, **kwargs): SimpleItem.__init__(self, *args, **kwargs) self.sent = []
def _createObject(self, id): from OFS.SimpleItem import SimpleItem obj = SimpleItem() obj.id = id return obj
def manage_beforeDelete(self, item, container): """ This method is called, when the object is deleted. """ SimpleItem.inheritedAttribute('manage_beforeDelete')(self, item, container) self.uncatalogNyObject(self)