def test_content_category_changed_default_values(self): """While content_category is changed on an element, the default values for fields to_print/confidential/to_sign/signed are reapplied with new content_category default values if it was still the default vlue of the original content_category.""" category_group = self.portal.config['group-1'] category_group.to_be_printed_activated = True category_group.confidentiality_activated = True category_group.signed_activated = True category11 = self.portal.config['group-1']['category-1-1'] category11_id = calculate_category_id(category11) obj = api.content.create( id='file2', type='File', file=self.file, container=self.portal, content_category=category11_id) self.assertFalse(obj.confidential) self.assertFalse(obj.to_sign) self.assertFalse(obj.signed) self.assertIsNone(obj.to_print) # now enable everything on category-1-2 and use it category12 = self.portal.config['group-1']['category-1-2'] category12.to_print = False category12.confidential = True category12.to_sign = True category12.signed = True category12_id = calculate_category_id(category12) adapted_obj = IconifiedCategorization(obj) setattr(adapted_obj, 'content_category', category12_id) notify(ObjectModifiedEvent(obj)) # changed to True on obj an in parent's categorized_elements parent_cat_elements = obj.aq_parent.categorized_elements[obj.UID()] self.assertTrue(obj.confidential) self.assertTrue(parent_cat_elements['confidential']) self.assertTrue(obj.to_sign) self.assertTrue(parent_cat_elements['to_sign']) self.assertTrue(obj.signed) self.assertTrue(parent_cat_elements['signed']) # to_print could not be set to False because not printable self.assertIsNone(obj.to_print) self.assertIsNone(parent_cat_elements['to_print']) # enable conversion and back to category11 category11.to_print = True gsettings = GlobalSettings(self.portal) gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys() # set to_print to False, aka the default value of category12 obj.to_print = False setattr(adapted_obj, 'content_category', category11_id) notify(ObjectModifiedEvent(obj)) self.assertTrue(obj.to_print) self.assertTrue(parent_cat_elements['to_print']) # if original content_category does not exist, it does not fail # but default values are not reapplied obj.content_category = 'unkown_content_category' setattr(adapted_obj, 'content_category', category12_id) notify(ObjectModifiedEvent(obj)) self.assertEqual(obj.content_category, category12_id)
def test_content_category_to_print_on_creation(self): """ """ category_group = self.portal.config['group-1'] category = self.portal.config['group-1']['category-1-1'] content_category_id = calculate_category_id(category) category_group.to_be_printed_activated = True # enable conversion gsettings = GlobalSettings(self.portal) gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys() # set to False category.to_print = False file2 = api.content.create( id='file2', type='File', file=self.file, container=self.portal, content_category=content_category_id) self.assertFalse(file2.to_print) # set to True category.to_print = True file3 = api.content.create( id='file3', type='File', file=self.file, container=self.portal, content_category=content_category_id) self.assertTrue(file3.to_print)
def setup_documentviewer(portal): from collective.documentviewer.settings import GlobalSettings dv_settings = GlobalSettings(portal) dv_settings.auto_layout_file_types = ('pdf', 'ppt', 'word', 'rft') dv_settings.auto_convert = True dv_settings.show_sidebar = False dv_settings.show_search = False
def test_set_values(self): obj = self.portal['file'] view = obj.restrictedTraverse('@@iconified-print') # works only if functionnality enabled and user have Modify portal content category = utils.get_category_object(obj, obj.content_category) group = category.get_category_group() # fails if one of 2 conditions is not fullfilled self.assertTrue(api.user.has_permission(ModifyPortalContent, obj=obj)) group.to_be_printed_activated = False self.assertRaises(Unauthorized, view.set_values, {'to_print': True}) group.to_be_printed_activated = True obj.manage_permission(ModifyPortalContent, roles=[]) self.assertRaises(Unauthorized, view.set_values, {'to_print': True}) obj.manage_permission(ModifyPortalContent, roles=['Manager']) # set to None when format not managed by collective.documentviewer self.assertFalse(obj.to_print, obj.aq_parent.categorized_elements[obj.UID()]['to_print']) view.set_values({'to_print': True}) self.assertIsNone(obj.to_print, obj.aq_parent.categorized_elements[obj.UID()]['to_print']) # will be correctly set if format is managed gsettings = GlobalSettings(self.portal) gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys() view.set_values({'to_print': True}) self.assertTrue(obj.to_print, obj.aq_parent.categorized_elements[obj.UID()]['to_print']) view.set_values({'to_print': False}) self.assertFalse(obj.to_print, obj.aq_parent.categorized_elements[obj.UID()]['to_print'])
def test_sets_can_not_convert_after_conversion(self): fi = self.createFile('test.odp') gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['ppt'] notify(ObjectInitializedEvent(fi)) converter = Converter(fi) self.assertTrue(not converter.can_convert)
def test_sets_filehash(self): fi = self.createFile('test.odp') gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['ppt'] notify(ObjectInitializedEvent(fi)) settings = Settings(fi) self.assertTrue(settings.filehash is not None)
def test_sets_filehash(self): gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['ppt'] fi = self.createFile('test.odp') settings = Settings(fi) self.assertTrue(settings.filehash is not None)
def test_sets_filehash(self): fi = self.createFile('test.odp') gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['ppt'] notify(ObjectInitializedEvent(fi)) settings = Settings(fi) self.assertTrue(settings.filehash is not None)
def test_sets_can_not_convert_after_conversion(self): fi = self.createFile('test.odp') gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['ppt'] notify(ObjectInitializedEvent(fi)) converter = Converter(fi) self.assertTrue(not converter.can_convert)
def test_auto_convert_word(self): gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['word'] fi = self.createFile('test.doc') settings = Settings(fi) self.assertEqual(settings.successfully_converted, True) self.assertEqual(settings.num_pages, 2)
def test_auto_convert_powerpoint(self): fi = self.createFile('test.odp') gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['ppt'] notify(ObjectInitializedEvent(fi)) settings = Settings(fi) self.assertEqual(settings.successfully_converted, True) self.assertEqual(settings.num_pages, 1)
def test_auto_convert_powerpoint(self): fi = self.createFile('test.odp') gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['ppt'] notify(ObjectInitializedEvent(fi)) settings = Settings(fi) self.assertEqual(settings.successfully_converted, True) self.assertEqual(settings.num_pages, 1)
def test_PrintColumn(self): table = self.portal.restrictedTraverse('@@iconifiedcategory') brain = CategorizedContent(self.portal.portal_catalog(UID=self.portal['file'].UID())[0], self.portal) obj = brain.real_object() column = PrintColumn(self.portal, self.portal.REQUEST, table) # not convertible by default as c.documentviewer not enabled self.assertEqual( column.renderCell(brain), u'<a href="#" ' u'class="iconified-action deactivated" ' u'alt="Not convertible to a printable format" ' u'title="Not convertible to a printable format"></a>') self.assertIsNone(brain.to_print) self.assertIsNone(obj.to_print) # enable collective.documentviewer so document is convertible gsettings = GlobalSettings(self.portal) gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys() # enable to_print management in configuration category = utils.get_category_object(obj, obj.content_category) category_group = category.get_category_group(category) category_group.to_be_printed_activated = True category.to_print = False notify(ObjectModifiedEvent(obj)) brain = CategorizedContent(self.portal.portal_catalog(UID=self.portal['file'].UID())[0], self.portal) self.assertEqual(brain.to_print, False) self.assertFalse(obj.to_print) self.assertEqual( column.renderCell(brain), u'<a href="http://nohost/plone/file/@@iconified-print" ' u'class="iconified-action editable" ' u'alt="Should not be printed" ' u'title="Should not be printed"></a>') # set to_print to True obj.to_print = True notify(ObjectModifiedEvent(obj)) brain = CategorizedContent(self.portal.portal_catalog(UID=self.portal['file'].UID())[0], self.portal) self.assertTrue(brain.to_print, False) self.assertTrue(obj.to_print) self.assertEqual( column.renderCell(brain), u'<a href="http://nohost/plone/file/@@iconified-print" ' u'class="iconified-action active editable" ' u'alt="Must be printed" ' u'title="Must be printed"></a>') # if element is not editable, the 'editable' CSS class is not there obj.manage_permission(ModifyPortalContent, roles=[]) notify(ObjectModifiedEvent(obj)) self.assertEqual(column.renderCell(brain), u'<a href="http://nohost/plone/file/@@iconified-print" ' u'class="iconified-action active" ' u'alt="Must be printed" title="Must be printed"></a>')
def configure(context): """ """ if context.readDataFile('ploneintranet.docconv_default.txt') is None: return log.info("document conversion configuration") global_settings = GlobalSettings(getSite()) global_settings.enable_indexation = False global_settings.auto_select_layout = False global_settings.auto_layout_file_types = CONVERTABLE_TYPES.keys() commit() log.info("document conversion configuration: done.")
def test_table_render_when_preview_enabled(self): # enable collective.documentviewer so document is convertible gsettings = GlobalSettings(self.portal) gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys() # initialize collective.documentviewer annotations on file file_obj = self.portal['file'] image_obj = self.portal['image'] notify(ObjectModifiedEvent(file_obj)) notify(ObjectModifiedEvent(image_obj)) view = self.portal.restrictedTraverse('@@iconifiedcategory') result = view() # by default, images are not handled by collective.documentviewer self.assertTrue('<a href="http://nohost/plone/image" ' in result) self.assertTrue('<a href="http://nohost/plone/file/documentviewer#document/p1" ' in result)
def test_saves_with_file_storage(self): fi = self.createFile('test.odp') gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['ppt'] gsettings.storage_type = 'File' _dir = mkdtemp() gsettings.storage_location = _dir notify(ObjectInitializedEvent(fi)) fi_dir = storage.getResourceDirectory(obj=fi) self.assertEqual(len(listdir(fi_dir)), 4) self.assertEqual(len(listdir(join(fi_dir, 'normal'))), 1) self.assertEqual(len(listdir(join(fi_dir, 'small'))), 1) self.assertEqual(len(listdir(join(fi_dir, 'large'))), 1) self.assertEqual(len(listdir(join(fi_dir, 'text'))), 1) shutil.rmtree(fi_dir)
def test_saves_with_file_storage(self): fi = self.createFile('test.odp') gsettings = GlobalSettings(self.portal) gsettings.auto_select_layout = True gsettings.auto_layout_file_types = ['ppt'] gsettings.storage_type = 'File' _dir = mkdtemp() gsettings.storage_location = _dir notify(ObjectInitializedEvent(fi)) fi_dir = storage.getResourceDirectory(obj=fi) self.assertEqual(len(listdir(fi_dir)), 4) self.assertEqual(len(listdir(join(fi_dir, 'normal'))), 1) self.assertEqual(len(listdir(join(fi_dir, 'small'))), 1) self.assertEqual(len(listdir(join(fi_dir, 'large'))), 1) self.assertEqual(len(listdir(join(fi_dir, 'text'))), 1) shutil.rmtree(fi_dir)
def test_is_convertible(self): obj = self.portal['file'] preview_adapter = adapter.CategorizedObjectPreviewAdapter(obj) # convertible relies on the fact that contentType is managed # by collective.documentviewer gsettings.auto_layout_file_types gsettings = GlobalSettings(self.portal) self.assertEqual(gsettings.auto_layout_file_types, ['pdf']) obj.file.contentType = 'application/pdf' self.assertTrue(preview_adapter.is_convertible()) obj.file.contentType = 'application/rtf' self.assertFalse(preview_adapter.is_convertible()) # right enable every file_types in collective.documentviewer gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys() convertables = ( 'application/msword', 'application/pdf', 'application/rtf', 'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.oasis.opendocument.text', # xlsx 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'image/png', 'image/jpeg', 'text/html', ) for convertable in convertables: obj.file.contentType = convertable self.assertTrue(preview_adapter.is_convertible()) not_convertables = ('application/octet-stream', 'text/x-python') for not_convertable in not_convertables: obj.file.contentType = not_convertable self.assertFalse(preview_adapter.is_convertible())
def test_content_category_to_print_only_set_if_convertible_when_conversion_enabled(self): """ """ category_group = self.portal.config['group-1'] category = self.portal.config['group-1']['category-1-1'] content_category_id = calculate_category_id(category) category_group.to_be_printed_activated = True # set to True category.to_print = True file2 = api.content.create( id='file2', type='File', file=self.file, container=self.portal, content_category=content_category_id) # enable conversion gsettings = GlobalSettings(self.portal) gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys() file2.file.contentType = 'text/unknown' notify(ObjectModifiedEvent(file2)) self.assertIsNone(file2.to_print)
def test_status(self): obj = self.portal['file'] preview_adapter = adapter.CategorizedObjectPreviewAdapter(obj) gsettings = GlobalSettings(self.portal) self.assertEqual(gsettings.auto_layout_file_types, ['pdf']) obj.file.contentType = 'application/rtf' self.assertEqual(preview_adapter.status, 'not_convertable') self.assertFalse(preview_adapter.converted) obj.file.contentType = 'application/pdf' self.assertEqual(preview_adapter.status, 'not_converted') self.assertFalse(preview_adapter.converted) ann = IAnnotations(obj)['collective.documentviewer'] ann['filehash'] = '--foobar--' obj.file.contentType = 'application/pdf' self.assertEqual(preview_adapter.status, 'in_progress') self.assertFalse(preview_adapter.converted) queueJob(obj) # not a real PDF actually... self.assertEqual(preview_adapter.status, 'conversion_error') self.assertFalse(preview_adapter.converted) # enable every supported types including txt gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys() obj.file.contentType = 'text/plain' # collective.documentviewer checks if element was modified # or it does not convert again sleep(1) obj.notifyModified() queueJob(obj) self.assertEqual(preview_adapter.status, 'converted') self.assertTrue(preview_adapter.converted)
def castle(context): if not context.readDataFile('castle.cms.install.txt'): return site = context.getSite() # create feed folder folder = utils.recursive_create_path(site, '/feeds') try: if api.content.get_state(obj=folder) != 'published': api.content.transition(obj=folder, transition='publish') except WorkflowException: pass type_ = 'Collection' aspect = ISelectableConstrainTypes(folder, None) if (aspect and (aspect.getConstrainTypesMode() != 1 or [type_] != aspect.getImmediatelyAddableTypes())): aspect.setConstrainTypesMode(1) aspect.setImmediatelyAddableTypes([type_]) if not getattr(folder, 'exclude_from_nav', False): folder.exclude_from_nav = True folder.reindexObject() if 'front-page' not in site: api.content.create(type='Document', id='front-page', container=site) site.setDefaultPage('front-page') front_page = site['front-page'] front_page.title = u'Welcome to Castle' front_page.description = u'Congratulations! You have successfully installed Castle.' # enable syndication by default and modify some of the settings registry = getUtility(IRegistry) settings = registry.forInterface(ISiteSyndicationSettings) settings.allowed = True settings.default_enabled = False settings.show_author_info = False settings.search_rss_enabled = False utils.add_indexes(INDEXES) utils.delete_indexes(REMOVE_INDEXES) utils.add_metadata(METADATA) utils.delete_metadata(REMOVE_METADATA) # add some better defaults for documentviewer settings = DVGlobalSettings(site) settings.auto_layout_file_types = [ 'pdf', 'word', 'excel', 'ppt', 'rft', 'ps', 'photoshop', 'visio', 'palm' ] # delete some records for mosaic tinymce toolbar for action_type in ('plone_app_z3cform_wysiwyg_widget_WysiwygWidget', 'plone_app_z3cform_wysiwyg_widget_WysiwygFieldWidget', 'plone_app_widgets_dx_RichTextWidget', 'plone_app_z3cform_widget_RichTextFieldWidget'): try: data = registry['plone.app.mosaic.widget_actions.%s.actions' % action_type] _removeTinyMCEActions(data) registry['plone.app.mosaic.widget_actions.%s.actions' % action_type] = data except KeyError: pass for key in ( 'plone.app.mosaic.structure_tiles.text.available_actions', 'plone.app.mosaic.app_tiles.plone_app_standardtiles_rawhtml.available_actions' ): try: data = registry[key] _removeTinyMCEActions(data) registry[key] = data except KeyError: pass # password reset timeout interval... portal_password_reset = api.portal.get_tool('portal_password_reset') portal_password_reset.setExpirationTimeout(6) # update default session duration site.acl_users.session.timeout = 1 * 60 * 60 # 1 hr site.acl_users.session.refresh_interval = 5 * 60 # 5 minutes
def _enableAutoConvert(self, enable=True): """Enable collective.documentviewer auto_convert.""" gsettings = GlobalSettings(self.portal) gsettings.auto_convert = enable gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys() return gsettings
def setUp(self): super(TestCategorizedObjectPrintableAdapter, self).setUp() gsettings = GlobalSettings(self.portal) gsettings.auto_layout_file_types = CONVERTABLE_TYPES.keys()