def after_create(self, obj): super(LabelRootBuilder, self).after_create(obj) jar = ILabelJar(obj) for title, color, by_user in self.labels: jar.add(title, color, by_user) if self.session.auto_commit: transaction.commit()
def after_create(self, obj): super(LabelRootBuilder, self).after_create(obj) jar = ILabelJar(obj) for title, color in self.labels: jar.add(title, color) if self.session.auto_commit: transaction.commit()
def setUp(self): """ """ super(TestLabels, self).setUp() self.doc1 = api.content.create(self.portal, 'Document', 'doc1') self.doc2 = api.content.create(self.portal, 'Document', 'doc2') # defined some labels alsoProvides(self.portal, ILabelRoot) adapted = ILabelJar(self.portal) adapted.add('Pers1', 'green', True) # label_id = pers1 adapted.add('Pers2', 'green', True) # label_id = pers2 adapted.add('Pers3', 'green', True) # label_id = pers3 adapted.add('Glob1', 'red', False) # label_id = glob1 adapted.add('Glob2', 'red', False) # label_id = glob2 adapted.add('Glob3', 'red', False) # label_id = glob3 # can label created objects for obj in (self.doc1, self.doc2): alsoProvides(obj, ILabelSupport) self.lab_doc1 = ILabeling(self.doc1) self.lab_doc2 = ILabeling(self.doc2) login(self.portal, TEST_USER_NAME)
def create(self): """Create a new label. """ title = self.request.form.get('title', None) if not title: api.portal.show_message( _(u'lable_title_is_missing', default=u'Please choose a title.'), self.request, 'error') return self._redirect() color = self.request.form.get('color', None) if not color: color = self._get_random_color() jar = ILabelJar(self.context) jar.get(jar.add(title, color)) return self._redirect()
def create(self): """Create a new label. """ title = self.request.form.get('title', None) if not title: api.portal.show_message( _(u'lable_title_is_missing', default=u'Please choose a title.'), self.request, 'error') return self._redirect() color = self.request.form.get('color', None) if not color: color = self._get_random_color() by_user = bool(self.request.form.get('by_user', False)) # received value is 'on' when checked jar = ILabelJar(self.context) jar.get(jar.add(title, color, by_user)) return self._redirect()
def create(self): """Create a new label. """ title = self.request.form.get('title', None) if not title: api.portal.show_message( _(u'lable_title_is_missing', default=u'Please choose a title.'), self.request, 'error') return self._redirect() color = self.request.form.get('color', None) if not color: color = self._get_random_color() by_user = bool(self.request.form.get( 'by_user', False)) # received value is 'on' when checked jar = ILabelJar(self.context) jar.get(jar.add(title, color, by_user)) return self._redirect()
def update_site(self): # add documentation message if 'doc' not in self.portal['messages-config']: add_message( 'doc', 'Documentation', u'<p>Vous pouvez consulter la <a href="http://www.imio.be/' u'support/documentation/topic/cp_app_ged" target="_blank">documentation en ligne de la ' u'dernière version</a>, ainsi que d\'autres documentations liées.</p>', msg_type='significant', can_hide=True, req_roles=['Authenticated'], activate=True) if 'doc2-0' in self.portal['messages-config']: api.content.delete(obj=self.portal['messages-config']['doc2-0']) # update front-page frontpage = self.portal['front-page'] if frontpage.Title() == 'Gestion du courrier 2.0': frontpage.setTitle(_("front_page_title")) frontpage.setDescription(_("front_page_descr")) frontpage.setText(_("front_page_text"), mimetype='text/html') # update portal title self.portal.title = 'Gestion du courrier' # for collective.externaleditor if 'MailingLoopTemplate' not in self.registry[ 'externaleditor.externaleditor_enabled_types']: self.registry['externaleditor.externaleditor_enabled_types'] = [ 'PODTemplate', 'ConfigurablePODTemplate', 'DashboardPODTemplate', 'SubTemplate', 'StyleTemplate', 'dmsommainfile', 'MailingLoopTemplate' ] # documentgenerator api.portal.set_registry_record( 'collective.documentgenerator.browser.controlpanel.' 'IDocumentGeneratorControlPanelSchema.raiseOnError_for_non_managers', True) # ftw.labels if not ILabelRoot.providedBy(self.imf): labels = { self.imf: [('Lu', 'green', True), ('Suivi', 'yellow', True)], self.omf: [], self.portal['tasks']: [] } for folder in labels: if not ILabelRoot.providedBy(folder): alsoProvides(folder, ILabelRoot) adapted = ILabelJar(folder) existing = [dic['title'] for dic in adapted.list()] for title, color, by_user in labels[folder]: if title not in existing: adapted.add(title, color, by_user) self.portal.manage_permission('ftw.labels: Manage Labels Jar', ('Manager', 'Site Administrator'), acquire=0) self.portal.manage_permission('ftw.labels: Change Labels', ('Manager', 'Site Administrator'), acquire=0) self.portal.manage_permission( 'ftw.labels: Change Personal Labels', ('Manager', 'Site Administrator', 'Member'), acquire=0) self.runProfileSteps('imio.dms.mail', steps=['imiodmsmail-mark-copy-im-as-read'], profile='singles') # INextPrevNotNavigable alsoProvides(self.portal['tasks'], INextPrevNotNavigable) # registry api.portal.set_registry_record( name= 'Products.CMFPlone.interfaces.syndication.ISiteSyndicationSettings.' 'search_rss_enabled', value=False) # activing versioning self.portal.portal_diff.setDiffForPortalType( 'task', {'any': "Compound Diff for Dexterity types"}) self.portal.portal_diff.setDiffForPortalType( 'dmsommainfile', {'any': "Compound Diff for Dexterity types"}) # change permission self.portal.manage_permission('imio.dms.mail: Write userid field', (), acquire=0) pf = self.portal.contacts['personnel-folder'] pf.manage_permission('imio.dms.mail: Write userid field', ('Manager', 'Site Administrator'), acquire=0) # ckeditor skin self.portal.portal_properties.ckeditor_properties.skin = 'moono-lisa' # update mailcontent options self.registry[ 'collective.dms.mailcontent.browser.settings.IDmsMailConfig.outgoingmail_edit_irn'] = u'hide' self.registry[ 'collective.dms.mailcontent.browser.settings.IDmsMailConfig.outgoingmail_increment_number'] = True # hide faceted actions paob = self.portal.portal_actions.object_buttons for act in ('faceted.sync', 'faceted.disable', 'faceted.enable', 'faceted.search.disable', 'faceted.search.enable', 'faceted.actions.disable', 'faceted.actions.enable'): if act in paob: paob[act].visible = False
class TestLabeling(MockTestCase): layer = ADAPTERS_ZCML_LAYER def setUp(self): super(TestLabeling, self).setUp() Labeling.user_id = lambda x: TEST_USER_ID # needed to avoid plone.api.portal.get error self.root = self.providing_stub([ILabelRoot, IAttributeAnnotatable]) self.document = self.providing_stub( [ILabelSupport, IAttributeAnnotatable]) self.set_parent(self.document, self.root) self.replay() self.jar = ILabelJar(self.root) def test_adapter(self): self.assertTrue( queryAdapter(self.document, ILabeling), 'The labeling adapter is not registered for ILabeling') def test_available_labels(self): self.jar.add('Question', '#00FF00', False) self.jar.add('Read', 'red', True) labeling = ILabeling(self.document) self.assertEqual([[{ 'label_id': 'read', 'title': 'Read', 'color': 'red', 'active': False, 'by_user': True }], [{ 'label_id': 'question', 'title': 'Question', 'color': '#00FF00', 'active': False, 'by_user': False }]], list(labeling.available_labels())) def test_available_labels_empty(self): labeling = ILabeling(self.document) self.assertEqual([[], []], labeling.available_labels()) def test_available_label(self): self.jar.add('Question', '#00FF00', False) self.jar.add('Read', 'red', True) labeling = ILabeling(self.document) labeling.update(['question']) labeling.pers_update('read', True) self.assertEqual([[{ 'label_id': 'read', 'title': 'Read', 'color': 'red', 'active': True, 'by_user': True }], [{ 'label_id': 'question', 'title': 'Question', 'color': '#00FF00', 'active': True, 'by_user': False }]], list(labeling.available_labels())) def test_update__enable_labels(self): self.jar.add('Bug', 'red', False) self.jar.add('Question', 'green', True) self.jar.add('Feature', 'purple', True) labeling = ILabeling(self.document) self.assertEqual([], labeling.active_labels()) labeling.update(['bug']) labeling.pers_update('feature', True) self.assertItemsEqual(['Bug', 'Feature'], label_titles(labeling.active_labels())) def test_update__disable_labels(self): self.jar.add('Bug', 'red', False) self.jar.add('Question', 'green', False) self.jar.add('Feature', 'purple', True) labeling = ILabeling(self.document) labeling.update(['bug', 'question']) labeling.pers_update('feature', True) self.assertItemsEqual(['Bug', 'Feature', 'Question'], label_titles(labeling.active_labels())) labeling.update(['bug']) labeling.pers_update('feature', False) self.assertItemsEqual(['Bug'], label_titles(labeling.active_labels())) labeling.update([]) self.assertEqual([], labeling.active_labels()) def test_update_raises_LookupError_when_label_not_in_jar(self): self.assertEqual(0, len(self.jar.list())) self.jar.add('Question', '', False) labeling = ILabeling(self.document) with self.assertRaises(LookupError) as cm: labeling.update(['something']) self.assertEqual( 'Cannot activate label: the label' ' "something" is not in the label jar. ' 'Following labels ids are available: question', str(cm.exception)) def test_active_labels(self): self.jar.add('Question', '', False) self.jar.add('Bug', '', False) self.jar.add('Duplicate', '', True) labeling = ILabeling(self.document) labeling.update(['bug']) labeling.pers_update('duplicate', True) self.assertListEqual([{ 'label_id': 'bug', 'title': 'Bug', 'color': '', 'by_user': False }, { 'label_id': 'duplicate', 'title': 'Duplicate', 'color': '', 'by_user': True }], labeling.active_labels()) def test_active_labels_is_sorted(self): self.jar.add('Zeta-0', '', False) self.jar.add('zeta-1', '', False) self.jar.add('alpha-0', '', False) self.jar.add('\xc3\x84lpha-1', '', False) self.jar.add('Alpha-2', '', False) labeling = ILabeling(self.document) labeling.update([ 'zeta-0', 'zeta-1', 'alpha-0', 'alpha-1', 'alpha-2', ]) self.assertEqual( ['alpha-0', '\xc3\x84lpha-1', 'Alpha-2', 'Zeta-0', 'zeta-1'], [label.get('title') for label in labeling.active_labels()]) def test_active_labels_filters_deleted_labels(self): self.jar.add('Question', 'blue', False) self.jar.add('Bug', 'red', False) labeling = ILabeling(self.document) labeling.update(['question', 'bug']) self.jar.remove('bug') self.assertEqual([{ 'label_id': 'question', 'title': 'Question', 'color': 'blue', 'by_user': False }], list(labeling.active_labels()))
class TestLabeling(MockTestCase): layer = ADAPTERS_ZCML_LAYER def setUp(self): super(TestLabeling, self).setUp() self.root = self.providing_stub([ILabelRoot, IAttributeAnnotatable]) self.document = self.providing_stub([ILabelSupport, IAttributeAnnotatable]) self.set_parent(self.document, self.root) self.replay() self.jar = ILabelJar(self.root) def test_adapter(self): self.assertTrue( queryAdapter(self.document, ILabeling), 'The labeling adapter is not registered for ILabeling') def test_available_labels(self): self.jar.add('Question', '#00FF00') labeling = ILabeling(self.document) self.assertEqual( [{'label_id': 'question', 'title': 'Question', 'color': '#00FF00', 'active': False}], list(labeling.available_labels())) def test_available_labels_empty(self): labeling = ILabeling(self.document) self.assertEqual([], list(labeling.available_labels())) def test_available_label(self): self.jar.add('Question', '#00FF00') labeling = ILabeling(self.document) labeling.update(['question']) self.assertEqual( [{'label_id': 'question', 'title': 'Question', 'color': '#00FF00', 'active': True}], list(labeling.available_labels())) def test_update__enable_labels(self): self.jar.add('Bug', 'red') self.jar.add('Question', 'green') self.jar.add('Feature', 'purple') labeling = ILabeling(self.document) self.assertEqual([], labeling.active_labels()) labeling.update(['bug', 'feature']) self.assertItemsEqual(['Bug', 'Feature'], label_titles(labeling.active_labels())) def test_update__disable_labels(self): self.jar.add('Bug', 'red') self.jar.add('Question', 'green') self.jar.add('Feature', 'purple') labeling = ILabeling(self.document) labeling.update(['bug', 'question', 'feature']) self.assertItemsEqual(['Bug', 'Feature', 'Question'], label_titles(labeling.active_labels())) labeling.update(['bug']) self.assertItemsEqual(['Bug'], label_titles(labeling.active_labels())) labeling.update([]) self.assertEqual([], labeling.active_labels()) def test_update_raises_LookupError_when_label_not_in_jar(self): self.assertEqual(0, len(self.jar.list())) self.jar.add('Question', '') labeling = ILabeling(self.document) with self.assertRaises(LookupError) as cm: labeling.update(['something']) self.assertEqual( 'Cannot activate label: the label' ' "something" is not in the label jar. ' 'Following labels ids are available: question', str(cm.exception)) def test_active_labels(self): self.jar.add('Question', '') self.jar.add('Bug', '') self.jar.add('Duplicate', '') labeling = ILabeling(self.document) labeling.update(['bug']) self.assertEqual( [{'label_id': 'bug', 'title': 'Bug', 'color': ''}], labeling.active_labels()) def test_active_labels_is_sorted(self): self.jar.add('Zeta-0', '') self.jar.add('zeta-1', '') self.jar.add('alpha-0', '') self.jar.add('\xc3\x84lpha-1', '') self.jar.add('Alpha-2', '') labeling = ILabeling(self.document) labeling.update([ 'zeta-0', 'zeta-1', 'alpha-0', 'alpha-1', 'alpha-2', ]) self.assertEqual( ['alpha-0', '\xc3\x84lpha-1', 'Alpha-2', 'Zeta-0', 'zeta-1'], [label.get('title') for label in labeling.active_labels()]) def test_active_labels_filters_deleted_labels(self): self.jar.add('Question', 'blue') self.jar.add('Bug', 'red') labeling = ILabeling(self.document) labeling.update(['question', 'bug']) self.jar.remove('bug') self.assertEqual( [{'label_id': 'question', 'title': 'Question', 'color': 'blue'}], list(labeling.active_labels()))