def __call__(self, milestone=None): context = aq_inner(self.context) self.can_edit = api.user.has_permission( 'Modify portal content', obj=context) modified, errors = dexterity_update(context) self.workspace = parent_workspace(context) if self.workspace.is_case: if self.can_edit and milestone is not None \ and milestone != context.milestone: context.milestone = milestone modified = True if modified: api.portal.show_message( _("Your changes have been saved."), request=self.request, type="success", ) context.reindexObject() notify(ObjectModifiedEvent(context)) if errors: api.portal.show_message( _("There was an error."), request=self.request, type="error") return super(TodoView, self).__call__()
def __call__(self, milestone=None): context = aq_inner(self.context) self.can_edit = api.user.has_permission('Modify portal content', obj=context) modified, errors = dexterity_update(context) self.workspace = parent_workspace(context) if self.workspace.is_case: if self.can_edit and milestone is not None \ and milestone != context.milestone: context.milestone = milestone modified = True if modified: api.portal.show_message( _("Your changes have been saved."), request=self.request, type="success", ) context.reindexObject() notify(ObjectModifiedEvent(context)) if errors: api.portal.show_message(_("There was an error."), request=self.request, type="error") return super(TodoView, self).__call__()
def test_sanitize_can_be_switched_off(self): api.portal.set_registry_record( 'ploneintranet.workspace.sanitize_html', False) self.doc1.REQUEST.form = { 'text': html_input } modified, errors = dexterity_update(self.doc1) self.assertEqual(errors, []) self.assertEqual(modified, {IRichText: ['text']}) self.assertEqual(self.doc1.text.raw, html_input)
def test_change_doc_long_title(self): self.doc1.REQUEST.form = dict( title=u"The quick brown fox jumps over the very lazy dog's back " "after having stared at it undecidedly for hours.") modified, errors = dexterity_update(self.doc1) self.assertEqual(errors, []) notify(ObjectModifiedEvent(self.doc1)) self.assertEquals( self.doc1.getId(), 'the-quick-brown-fox-jumps-over-the-very-lazy-dogs-back-after-having' # noqa )
def test_change_doc_title_updates_catalog(self): catalog = api.portal.get_tool('portal_catalog') self.assertEquals(len(catalog(getId='my-document')), 1) self.doc1.REQUEST.form = {'title': u'My totally renamed doc'} modified, errors = dexterity_update(self.doc1) self.assertEqual(errors, []) notify(ObjectModifiedEvent(self.doc1)) self.assertEquals(self.doc1.getId(), 'my-totally-renamed-doc') self.assertEquals(len(catalog(getId='my-document')), 0) self.assertEquals(len(catalog(getId='my-totally-renamed-doc')), 1) self.assertEquals(len(catalog(Title='My totally renamed doc')), 1)
def test_sanitize_in_action(self): self.doc1.REQUEST.form = { 'text': html_input } modified, errors = dexterity_update(self.doc1) self.assertEqual(errors, []) self.assertEqual(modified, {IRichText: ['text']}) # Ignore differences in line breaks, only the semantics matter. self.assertEqual( self.doc1.text.raw.replace('\n', ''), html_cleaned.replace('\n', ''))
def test_multiple_fields_modified(self): self.todo1.REQUEST.form = { 'title': 'Todo 2000', 'description': 'test', 'due': '2015-10-24', } modified, errors = dexterity_update(self.todo1) self.assertEqual(errors, []) self.assertEqual(modified, { IBasic: ['description', 'title', ], ITodo: ['due', ], })
def test_file_title_does_not_change_id(self): file_obj = api.content.create( container=self.workspace, type='File', title=u'My File', ) self.assertEquals(file_obj.getId(), 'my-file') file_obj.REQUEST.form = {'title': u'My süper File'} modified, errors = dexterity_update(file_obj) self.assertEqual(errors, []) notify(ObjectModifiedEvent(file_obj)) self.assertEquals(file_obj.Title(), 'My s\xc3\xbcper File') self.assertEquals(file_obj.getId(), 'my-file')
def edit(self): """ Edit content and return url. Uses dexterity_update to set the appropriate fields after creation. """ modified, errors = dexterity_update(self.context, self.request) if modified and not errors: api.portal.show_message( _("Item edited."), request=self.request, type="success") self.context.reindexObject() notify(ObjectModifiedEvent(self.context)) if errors: api.portal.show_message( _("There was a problem: %s." % errors), request=self.request, type="error", ) return self.context.absolute_url()
def edit(self): """ Edit content and return url. Uses dexterity_update to set the appropriate fields after creation. """ modified, errors = dexterity_update(self.context, self.request) if modified and not errors: api.portal.show_message(_("Item edited."), request=self.request, type="success") notify(ObjectModifiedEvent(self.context)) if errors: api.portal.show_message( _("There was a problem: %s." % errors), request=self.request, type="error", ) return self.context.absolute_url()
def create(self): """ Create content and return url. Uses dexterity_update to set the appropriate fields after creation. """ if not self.validate(): # BBB: do something clever that works with pat-inject # at the moment the @@add_something form is not a complete page # but just some markup, # so we cannot show that one here pass form = self.request.form new = None # BBB: this should be moved to a proper validate function! if self.portal_type == 'ploneintranet.workspace.case': template_id = form.get('template_id') if template_id: title = form.get('title') case_id = idnormalizer.normalize(title) new = create_case_from_template(template_id, case_id) else: api.portal.show_message( _('Please specify which Case Template to use'), request=self.request, type="error", ) else: container = self.context new = api.content.create( container=container, type=self.portal_type, title=self.title, safe_id=True, ) if not new: return self.context.absolute_url() if self.portal_type == 'ploneintranet.workspace.workspacefolder': if 'scenario' in form: if form['scenario'] == '1': external_visibility = 'secret' join_policy = 'admin' participant_policy = 'producers' elif form['scenario'] == '2': external_visibility = 'private' join_policy = 'team' participant_policy = 'moderators' elif form['scenario'] == '3': external_visibility = 'open' join_policy = 'self' participant_policy = 'publishers' else: raise AttributeError new.set_external_visibility(external_visibility) new.join_policy = join_policy new.participant_policy = participant_policy modified, errors = dexterity_update(new) if modified and not errors: api.portal.show_message( _("Item created."), request=self.request, type="success") new.reindexObject() notify(ObjectModifiedEvent(new)) if errors: api.portal.show_message( _("There was a problem: %s." % errors), request=self.request, type="error", ) return new.absolute_url()
def create(self): """ Create content and return url. Uses dexterity_update to set the appropriate fields after creation. """ form = self.request.form new = None if self.portal_type == 'ploneintranet.workspace.case': template_id = form.get('template_id') if template_id: portal = api.portal.get() template_folder = portal.restrictedTraverse(TEMPLATES_FOLDER) if template_folder: src = template_folder.restrictedTraverse(template_id) if src: title = form.get('title') target_id = idnormalizer.normalize(title) target_folder = portal.restrictedTraverse('workspaces') new = api.content.copy( source=src, target=target_folder, id=target_id, safe_id=True, ) else: api.portal.show_message( _('Please specify which Case Template to use'), request=self.request, type="error", ) else: container = self.context new = api.content.create( container=container, type=self.portal_type, title=self.title, safe_id=True, ) if not new: return self.context.absolute_url() if self.portal_type == 'ploneintranet.workspace.workspacefolder': if 'scenario' in form: if form['scenario'] == '1': external_visibility = 'secret' join_policy = 'admin' participant_policy = 'producers' elif form['scenario'] == '2': external_visibility = 'private' join_policy = 'team' participant_policy = 'moderators' elif form['scenario'] == '3': external_visibility = 'open' join_policy = 'self' participant_policy = 'publishers' else: raise AttributeError new.set_external_visibility(external_visibility) new.join_policy = join_policy new.participant_policy = participant_policy modified, errors = dexterity_update(new) if modified and not errors: api.portal.show_message( _("Item created."), request=self.request, type="success") new.reindexObject() notify(ObjectModifiedEvent(new)) if errors: api.portal.show_message( _("There was a problem: %s." % errors), request=self.request, type="error", ) return new.absolute_url()
def test_change_folder_title(self): self.subfolder.REQUEST.form = {'title': u'My fäntästic Folder'} modified, errors = dexterity_update(self.subfolder) self.assertEqual(errors, []) notify(ObjectModifiedEvent(self.subfolder)) self.assertEquals(self.subfolder.getId(), 'my-fantastic-folder')
def test_change_doc_title(self): self.doc1.REQUEST.form = {'title': u'My Døcümént olé'} modified, errors = dexterity_update(self.doc1) self.assertEqual(errors, []) notify(ObjectModifiedEvent(self.doc1)) self.assertEquals(self.doc1.getId(), 'my-document-ole')
def test_not_modified(self): modified, errors = dexterity_update(self.todo1) self.assertEqual(errors, []) self.assertFalse(modified)
def test_set_multiple_tags_utf8(self): """Set multiple tags on an object as a comma separated string and verify that they are saved as a tuple of strings.""" self.request.form['subjects'] = u'a ♥,b,c' utils.dexterity_update(self.doc, self.request) self.assertEqual((u'a ♥', u'b', u'c'), self.doc.subject)
def test_description_modified(self): self.todo1.REQUEST.form = {'description': 'test'} modified, errors = dexterity_update(self.todo1) self.assertEqual(errors, []) self.assertEqual(modified, {IBasic: ['description']})
def update(self, obj): ''' Update the object and returns the modified fields and errors ''' modified, errors = dexterity_update(obj) return modified, errors
def create(self): """ Create content and return url. Uses dexterity_update to set the appropriate fields after creation. """ if not self.validate(): # BBB: do something clever that works with pat-inject # at the moment the @@add_something form is not a complete page # but just some markup, # so we cannot show that one here pass form = self.request.form new = None # BBB: this should be moved to a proper validate function! if self.portal_type == 'ploneintranet.workspace.case': template_id = form.get('template_id') if template_id: title = form.get('title') case_id = idnormalizer.normalize(title) new = create_case_from_template(template_id, case_id) else: api.portal.show_message( _('Please specify which Case Template to use'), request=self.request, type="error", ) else: container = self.context new = api.content.create( container=container, type=self.portal_type, title=self.title, safe_id=True, ) if not new: return self.context.absolute_url() if self.portal_type == 'ploneintranet.workspace.workspacefolder': if 'scenario' in form: if form['scenario'] == '1': external_visibility = 'secret' join_policy = 'admin' participant_policy = 'producers' elif form['scenario'] == '2': external_visibility = 'private' join_policy = 'team' participant_policy = 'moderators' elif form['scenario'] == '3': external_visibility = 'open' join_policy = 'self' participant_policy = 'publishers' else: raise AttributeError new.set_external_visibility(external_visibility) new.join_policy = join_policy new.participant_policy = participant_policy modified, errors = dexterity_update(new) if not errors: api.portal.show_message(_("Item created."), request=self.request, type="success") new.reindexObject() notify(ObjectModifiedEvent(new)) else: api.portal.show_message( _("There was a problem: %s." % errors), request=self.request, type="error", ) return new.absolute_url()