Ejemplo n.º 1
0
def setupVarious(context):
    site = context.getSite()
    if context.readDataFile(
            'collective.ckeditortemplates_various.txt') is None:
        return

    if not site.get(FOLDER):
        types = getToolByName(site, 'portal_types')
        types.getTypeInfo('cktemplatefolder').global_allow = True
        container = api.content.create(site,
                                       "cktemplatefolder",
                                       id=FOLDER,
                                       title=FOLDER)
        excl = IExcludeFromNavigation(container)
        excl.exclude_from_nav = True
        types.getTypeInfo('cktemplatefolder').global_allow = False
        container.reindexObject()
        catalog = api.portal.get_tool(name='portal_catalog')
        catalog.uncatalog_object(container.absolute_url_path())
    else:
        catalog = api.portal.get_tool(name='portal_catalog')
        portal_types = ['cktemplatefolder']
        for portal_type in portal_types:
            brains = catalog(portal_type=portal_type)
            for brain in brains:
                catalog.uncatalog_object(brain.getObject().absolute_url_path())
Ejemplo n.º 2
0
def _createObject(context, event):
    parent = context.aq_parent
    id = context.getId()
    object_Ids = []
    catalog = getToolByName(context, 'portal_catalog')
    brains = catalog.unrestrictedSearchResults(object_provides = ISticker.__identifier__)
    for brain in brains:
        object_Ids.append(brain.id)
    
    title = str(idnormalizer.normalize(context.title))
    temp_new_id = title
    new_id = temp_new_id.replace("-","")
    test = ''
    if new_id in object_Ids:
        test = filter(lambda name: new_id in name, object_Ids)
        if '-' not in (max(test)):
            new_id = new_id + '-1'
        if '-' in (max(test)):
            new_id = new_id +'-' +str(int(max(test).split('-')[-1])+1) 

    parent.manage_renameObject(id, new_id )
    new_title = title
    context.setTitle(context.title)


    behavior = IExcludeFromNavigation(context)
    behavior.exclude_from_nav = True

    context.reindexObject()
    return
Ejemplo n.º 3
0
def modifyobject(context, event):
    parent = context.aq_parent
    id = context.getId()
    object_Ids = []
    catalog = getToolByName(context, 'portal_catalog')
    path = '/'.join(context.aq_parent.getPhysicalPath())
    brains = catalog.unrestrictedSearchResults(path={'query': path, 'depth' : 1})
    for brain in brains:
        object_Ids.append(brain.id)
    
    email1 = str(idnormalizer.normalize(context.email1))
    new_id = email1.replace('-','_')
    
    test = ''
    num = 0
    if new_id in object_Ids:
        test = filter(lambda name: new_id in name, object_Ids)
        new_id = new_id +'_' + str(len(test))

    parent.manage_renameObject(id, new_id )
    context.setTitle(new_id)

    #exclude from navigation code
    behavior = IExcludeFromNavigation(context)
    behavior.exclude_from_nav = True

    context.reindexObject()
    return
Ejemplo n.º 4
0
def _createObject(context, event):
    parent = context.aq_parent
    id = context.getId()
    object_Ids = []
    catalog = getToolByName(context, 'portal_catalog')
    brains = catalog.unrestrictedSearchResults(
        object_provides=ISignature.__identifier__)
    for brain in brains:
        object_Ids.append(brain.id)

    last_name = str(idnormalizer.normalize(context.last_name))
    first_name = str(idnormalizer.normalize(context.first_name))
    temp_new_id = last_name + '_' + first_name
    new_id = temp_new_id.replace("-", "")
    test = ''
    if new_id in object_Ids:
        test = filter(lambda name: new_id in name, object_Ids)
        if '-' not in (max(test)):
            new_id = new_id + '-1'
        if '-' in (max(test)):
            new_id = new_id + '-' + str(int(max(test).split('-')[-1]) + 1)

    parent.manage_renameObject(id, new_id)
    new_title = last_name + ' ' + first_name
    context.setTitle(new_title)

    #exclude from navigation code
    behavior = IExcludeFromNavigation(context)
    behavior.exclude_from_nav = True

    context.reindexObject()
    return
def post_install(context):
    """Post install script."""
    if context.readDataFile('collectivemessagesviewlet_default.txt') is None:
        return
    site = api.portal.get()
    if not site.get(FOLDER):
        container = _createObjectByType(
            'MessagesConfig',
            container=site,
            id=FOLDER,
            title=_('Messages viewlet settings', context=site))
        excl = IExcludeFromNavigation(container)
        excl.exclude_from_nav = True
Ejemplo n.º 6
0
def to1003(context):
    setup = getToolByName(context, 'portal_setup')
    setup.runAllImportStepsFromProfile('profile-wcc.document.upgrades:to1003')

    catalog = getToolByName(context, 'portal_catalog')

    for brain in catalog(portal_type=['wcc.document.document'],
                                    Language='all'):
        obj = brain.getObject()
        obj.reindexObject()
        adapted = IExcludeFromNavigation(obj)
        adapted.exclude_from_nav = False
        obj.reindexObject()
def update_content_folder(context):
    setup = getToolByName(context, 'portal_setup')
    setup.runAllImportStepsFromProfile(PROFILE)
    site = api.portal.get()
    types = getToolByName(site, 'portal_types')
    types.getTypeInfo('cktemplatefolder').global_allow = True
    container = install_folder(site)
    excl = IExcludeFromNavigation(container)
    excl.exclude_from_nav = True
    types.getTypeInfo('cktemplatefolder').global_allow = False
    container.reindexObject()
    catalog = api.portal.get_tool(name='portal_catalog')
    catalog.uncatalog_object(container.absolute_url_path())
def post_install(context):
    """Post install script."""
    if context.readDataFile("collectivemessagesviewlet_default.txt") is None:
        return
    site = context.getSite()

    if not site.get(FOLDER):
        types = getToolByName(site, "portal_types")
        types.getTypeInfo("MessagesConfig").global_allow = True
        container = api.content.create(
            site, "MessagesConfig", id=FOLDER, title=_("Messages viewlet settings", context=site)
        )
        excl = IExcludeFromNavigation(container)
        excl.exclude_from_nav = True
        types.getTypeInfo("MessagesConfig").global_allow = False
Ejemplo n.º 9
0
def to1004(context):
    setup = getToolByName(context, 'portal_setup')
    setup.runAllImportStepsFromProfile('profile-wcc.churches.upgrades:to1004')

    catalog = getToolByName(context, 'portal_catalog')

    for brain in catalog(portal_type=['wcc.churches.churchmember',
                                    'wcc.churches.churchfamily',
                                    'wcc.churches.churchbody'],
                                    Language='all'):
        obj = brain.getObject()
        obj.reindexObject()
        adapted = IExcludeFromNavigation(obj)
        adapted.exclude_from_nav = False
        obj.reindexObject()
def translation_folderish(obj, lang, title):
    translated_obj = api_lng.translate(obj, lang)
    translate_title = translate(_(title), target_language=lang)
    normalizer = getUtility(IIDNormalizer)
    new_id = normalizer.normalize(translate_title)
    translated_obj.title = translate_title
    if translated_obj.id != new_id:
        api.content.rename(translated_obj, new_id=new_id)
    try:
        nav = IExcludeFromNavigation(translated_obj)
    except:
        pass
    if nav:
        nav.exclude_from_nav = True
    translated_obj.reindexObject()
    return translated_obj
Ejemplo n.º 11
0
    def setUpLanguage(self, code, name):
        """
        Create the language folders on top of the site
        """
        doneSomething = False
        folderId = "%s" % code if code != 'id' else 'id-id'
        folder = getattr(self.context, folderId, None)
        wftool = getToolByName(self.context, 'portal_workflow')
        if folder is None:
            _createObjectByType(
                self.folder_type,
                self.context,
                folderId)

            folder = getattr(self.context, folderId)
            ILanguage(folder).set_language(code)
            folder.setTitle(name)
            state = wftool.getInfoFor(folder, 'review_state', None)
            # This assumes a direct 'publish' transition from the initial state
            # We are going to check if its private and has publish action for the out of the box case
            # otherwise don't do anything
            available_transitions = [t['id'] for t in wftool.getTransitionsFor(folder)]
            if state != 'published' and 'publish' in available_transitions:
                wftool.doActionFor(folder, 'publish')

            # Exclude folder from navigation (if applicable)
            adapter = IExcludeFromNavigation(folder, None)
            if adapter is not None:
                adapter.exclude_from_nav = True

            # We've modified the object; reindex.
            notify(modified(folder))

            doneSomething = True
            LOG.info("Added '%s' folder: %s" % (code, folderId))
        self.folders[code] = folder
        if not INavigationRoot.providedBy(folder):
            alsoProvides(folder, INavigationRoot)
            doneSomething = True
            LOG.info("INavigationRoot setup on folder '%s'" % code)
        return doneSomething
Ejemplo n.º 12
0
    def handleCreate(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = _("Please correct errors.")
            return

        lang_id = data['language']
        fti = data['fti']

        folder = createContentInContainer(
            self.context,
            fti.getId(),
            id=lang_id,
        )

        # It's important that we don't set the title in the call
        # above, because we don't want to have the id chosen based on
        # the title.
        folder.title = data['title']
        folder.description = data.get('description')
        folder.language = lang_id

        # It's a navigation root!
        alsoProvides(folder, INavigationRoot)

        # Exclude folder from navigation (if applicable)
        adapter = IExcludeFromNavigation(folder, None)
        if adapter is not None:
            adapter.exclude_from_nav = True

        # We've modified the object; reindex.
        notify(modified(folder))

        IStatusMessage(self.request).addStatusMessage(
            _(u"${fti_name} created.",
              mapping={
                  'fti_name': translate(fti.Title(), context=self.request)
              }), "info")

        self.request.response.redirect(data['next_url'])
Ejemplo n.º 13
0
    def handleCreate(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = _("Please correct errors.")
            return

        lang_id = data['language']
        fti = data['fti']

        folder = createContentInContainer(
            self.context, fti.getId(), id=lang_id,
        )

        # It's important that we don't set the title in the call
        # above, because we don't want to have the id chosen based on
        # the title.
        folder.title = data['title']
        folder.description = data.get('description')
        folder.language = lang_id

        # It's a navigation root!
        alsoProvides(folder, INavigationRoot)

        # Exclude folder from navigation (if applicable)
        adapter = IExcludeFromNavigation(folder, None)
        if adapter is not None:
            adapter.exclude_from_nav = True

        # We've modified the object; reindex.
        notify(modified(folder))

        IStatusMessage(self.request).addStatusMessage(
            _(u"${fti_name} created.", mapping={
                'fti_name': translate(fti.Title(), context=self.request)
            }), "info")

        self.request.response.redirect(data['next_url'])
Ejemplo n.º 14
0
def updateHistoryContainer(obj):
    obj.unindexObject()
    obj.setLayout("collective_history_view")
    if IExcludeFromNavigation.providedBy(obj):
        obj.exclude_from_nav = True
    else:
        obj.setExcludeFromNav(True)

    aspect = ISelectableConstrainTypes(obj)
    addable = aspect.getImmediatelyAddableTypes()
    if "collective.history.useraction" not in addable:
        aspect.setConstrainTypesMode(1)  # select manually
        types = ["collective.history.useraction"]
        if IDexterityContainer.providedBy(obj):
            #bypass check for available types
            obj.immediately_addable_types = types
        else:
            aspect.setImmediatelyAddableTypes(types)
Ejemplo n.º 15
0
def updateContainer(container, layout, ptypes):
    container.unindexObject()
    container.setLayout(layout)
    if IExcludeFromNavigation.providedBy(container):
        container.exclude_from_nav = True
    else:
        container.setExcludeFromNav(True)

    aspect = ISelectableConstrainTypes(container)
    addable = aspect.getImmediatelyAddableTypes()
    for ptype in ptypes:
        if ptype not in addable:
            aspect.setConstrainTypesMode(1)  # select manually
        if IDexterityContainer.providedBy(container):
            #bypass check for available types
            container.immediately_addable_types = ptypes
        else:
            aspect.setImmediatelyAddableTypes(ptypes)
Ejemplo n.º 16
0
 def test_exclude_from_nav_behavior(self):
     self.assertFalse(IExcludeFromNavigation.providedBy(self.compromisso))
Ejemplo n.º 17
0
    def setUpLanguage(self, code, name):
        """Create the language folders on top of the site
        """
        doneSomething = False

        if code == 'id':
            folderId = 'id-id'
        else:
            folderId = str(code)

        folder = getattr(self.context, folderId, None)
        wftool = getToolByName(self.context, 'portal_workflow')

        assets_folder_id = translate(_('assets_folder_id',
                                       default='assets'),
                                     domain='plone',
                                     target_language=folderId)
        assets_folder_title = translate(_('assets_folder_title',
                                          default=u'Assets'),
                                        domain='plone',
                                        target_language=folderId)

        if folder is None:
            _createObjectByType(self.folder_type, self.context, folderId)
            _createObjectByType(self.folder_type_language_independent,
                                self.context[folderId], assets_folder_id)

            folder = self.context[folderId]

            ILanguage(folder).set_language(code)
            folder.setTitle(name)

            ILanguage(folder[assets_folder_id]).set_language(code)
            folder[assets_folder_id].setTitle(assets_folder_title)

            # This assumes a direct 'publish' transition from the initial state
            # We are going to check if its private and has publish action for
            # the out of the box case otherwise don't do anything
            state = wftool.getInfoFor(folder, 'review_state', None)
            available_transitions = [t['id'] for t in
                                     wftool.getTransitionsFor(folder)]
            if state != 'published' and 'publish' in available_transitions:
                wftool.doActionFor(folder, 'publish')

            state = wftool.getInfoFor(folder[assets_folder_id],
                                      'review_state', None)
            available_transitions = [t['id'] for t in
                                     wftool.getTransitionsFor(folder[assets_folder_id])]  # noqa
            if state != 'published' and 'publish' in available_transitions:
                wftool.doActionFor(folder[assets_folder_id], 'publish')

            # Exclude folder from navigation (if applicable)
            adapter = IExcludeFromNavigation(folder, None)
            if adapter is not None:
                adapter.exclude_from_nav = True

            adapter = IExcludeFromNavigation(folder[assets_folder_id], None)
            if adapter is not None:
                adapter.exclude_from_nav = True

            # We've modified the object; reindex.
            notify(modified(folder))
            notify(modified(folder[assets_folder_id]))

            doneSomething = True
            logger.info(u"Added '%s' folder: %s" % (code, folderId))

        self.folders[code] = folder
        if not INavigationRoot.providedBy(folder):
            alsoProvides(folder, INavigationRoot)

            doneSomething = True
            logger.info(u"INavigationRoot setup on folder '%s'" % code)

        return doneSomething
 def test_exclude_from_navigation_behavior(self):
     self.assertTrue(IExcludeFromNavigation.providedBy(self.m1))
Ejemplo n.º 19
0
 def test_exclude_from_nav_behavior(self):
     self.assertFalse(IExcludeFromNavigation.providedBy(self.compromisso))
 def test_behaviors(self):
     """Validate that the required behaviors are available."""
     self.assertTrue(INameFromTitle.providedBy(self.ct))
     self.assertTrue(IExcludeFromNavigation.providedBy(self.ct))
def post_install(context):
    """Post install script"""
    # creation of taxonomies

    language_tool = api.portal.get_tool("portal_languages")
    langs = language_tool.supported_langs
    current_lang = api.portal.get_default_language()[:2]

    taxonomies_collection = ["I am", "I search"]
    data_iam = {
        "taxonomy": "iam",
        "field_title": translate(_("I am"), target_language=current_lang),
        "field_description": "",
        "default_language": "fr",
    }

    data_isearch = {
        "taxonomy": "isearch",
        "field_title": translate(_("I search"), target_language=current_lang),
        "field_description": "",
        "default_language": "fr",
    }

    faced_config = {
        "I am": "/faceted/config/iam_folder_{0}.xml",
        "I search": "/faceted/config/isearch_folder_{0}.xml",
    }

    provided_interfaces = {"I am": IIAmFolder, "I search": IISearchFolder}

    # install taxonomy
    portal = api.portal.get()
    sm = portal.getSiteManager()
    iam_item = "collective.taxonomy.iam"
    isearch_item = "collective.taxonomy.isearch"
    utility_iam = sm.queryUtility(ITaxonomy, name=iam_item)
    utility_isearch = sm.queryUtility(ITaxonomy, name=isearch_item)

    # stop installation if already
    if utility_iam and utility_isearch:
        enable_taxonomies_content_type()
        return

    create_taxonomy_object(data_iam)
    create_taxonomy_object(data_isearch)

    # remove taxonomy test
    item = "collective.taxonomy.test"
    utility = sm.queryUtility(ITaxonomy, name=item)
    if utility:
        utility.unregisterBehavior()
        sm.unregisterUtility(utility, ITaxonomy, name=item)
        sm.unregisterUtility(utility, IVocabularyFactory, name=item)
        sm.unregisterUtility(utility, ITranslationDomain, name=item)

    enable_taxonomies_content_type()
    # creation of two collections by language

    container = api.portal.get().get(current_lang)
    if container is None:
        container = api.portal.get()
    for taxonomy_collection in taxonomies_collection:
        title = taxonomy_collection
        translate_title = translate(_(title), target_language=current_lang)
        normalizer = getUtility(IIDNormalizer)
        new_id = normalizer.normalize(translate_title)
        if normalizer.normalize(title) not in container:
            new_obj = api.content.create(type="Folder",
                                         title=translate_title,
                                         container=container)
            alsoProvides(new_obj, provided_interfaces[taxonomy_collection])
            if new_obj.id != new_id:
                api.content.rename(new_obj, new_id=new_id)
            try:
                nav = IExcludeFromNavigation(new_obj)
            except:
                pass
            if nav:
                nav.exclude_from_nav = True
            new_obj.reindexObject()
            _activate_dashboard_navigation(
                new_obj,
                faced_config[taxonomy_collection].format(current_lang))
            for lang in langs:
                if lang != current_lang:
                    translated_obj = translation_folderish(
                        new_obj, lang, title)
                    alsoProvides(translated_obj,
                                 provided_interfaces[taxonomy_collection])
                    _activate_dashboard_navigation(
                        translated_obj,
                        faced_config[taxonomy_collection].format(lang))
Ejemplo n.º 22
0
 def test_can_be_excluded_from_navigation(self):
     self.assertTrue(IExcludeFromNavigation.providedBy(self.blog))
     self.assertTrue(hasattr(self.blog, 'exclude_from_nav'))
Ejemplo n.º 23
0
    def setUpLanguage(self, code, name):
        """Create the language folders on top of the site
        """
        doneSomething = False

        if code == 'id':
            folderId = 'id-id'
        else:
            folderId = str(code)

        folder = getattr(self.context, folderId, None)
        wftool = getToolByName(self.context, 'portal_workflow')

        assets_folder_id = translate(_('assets_folder_id', default='assets'),
                                     domain='plone',
                                     target_language=folderId)
        assets_folder_title = translate(_('assets_folder_title',
                                          default=u'Assets'),
                                        domain='plone',
                                        target_language=folderId)

        if folder is None:
            _createObjectByType(self.folder_type, self.context, folderId)
            _createObjectByType(self.folder_type_language_independent,
                                self.context[folderId], assets_folder_id)

            folder = self.context[folderId]

            ILanguage(folder).set_language(code)
            folder.setTitle(name)

            ILanguage(folder[assets_folder_id]).set_language(code)
            folder[assets_folder_id].setTitle(assets_folder_title)

            # This assumes a direct 'publish' transition from the initial state
            # We are going to check if its private and has publish action for
            # the out of the box case otherwise don't do anything
            state = wftool.getInfoFor(folder, 'review_state', None)
            available_transitions = [
                t['id'] for t in wftool.getTransitionsFor(folder)
            ]
            if state != 'published' and 'publish' in available_transitions:
                wftool.doActionFor(folder, 'publish')

            state = wftool.getInfoFor(folder[assets_folder_id], 'review_state',
                                      None)
            available_transitions = [
                t['id']
                for t in wftool.getTransitionsFor(folder[assets_folder_id])
            ]  # noqa
            if state != 'published' and 'publish' in available_transitions:
                wftool.doActionFor(folder[assets_folder_id], 'publish')

            # Exclude folder from navigation (if applicable)
            adapter = IExcludeFromNavigation(folder, None)
            if adapter is not None:
                adapter.exclude_from_nav = True

            adapter = IExcludeFromNavigation(folder[assets_folder_id], None)
            if adapter is not None:
                adapter.exclude_from_nav = True

            # We've modified the object; reindex.
            notify(modified(folder))
            notify(modified(folder[assets_folder_id]))

            doneSomething = True
            logger.info(u"Added '%s' folder: %s" % (code, folderId))

        self.folders[code] = folder
        if not INavigationRoot.providedBy(folder):
            alsoProvides(folder, INavigationRoot)

            doneSomething = True
            logger.info(u"INavigationRoot setup on folder '%s'" % code)

        return doneSomething
Ejemplo n.º 24
0
 def test_exclude_from_navigation_behavior(self):
     from plone.app.dexterity.behaviors.exclfromnav import IExcludeFromNavigation
     self.assertTrue(IExcludeFromNavigation.providedBy(self.journal))
Ejemplo n.º 25
0
                    status = 'edited'
            except Exception, e:
                status = 'failed'
                trace = traceback.format_exc()
                try:
                    messages.append(
                        "Failed to push event: \n"
                        "%s\n"
                        "%s\n" % (
                            trace,
                            pformat(data)))
                except Exception, e:
                    # handle case where repr(data) can failed
                    messages.append(trace)
        if event is not None:
            nav = IExcludeFromNavigation(event)
            nav.exclude_from_nav = False
            event.reindexObject()
        return messages, status, event


def find_root(parent):
    found = False
    while not found:
        try:
            current = parent
            parent = aq_parent(parent)
            if parent is None:
                parent = current
                raise Exception("stop")
        except:
 def test_exclude_from_nav_behavior(self):
     self.assertFalse(IExcludeFromNavigation.providedBy(self.agendadiaria))
Ejemplo n.º 27
0
 def test_exclude_from_nav(self):
     self.assertTrue(IExcludeFromNavigation.providedBy(self.agenda))
Ejemplo n.º 28
0
    def masschange(self, action):
        # already passed (updateWidget called twice
        self.logs, ilogs = [], []
        if self.status != '':
            return
        data, errors = self.extractData()
        if errors:
            self.status = "Please correct errors"
            return
        portal_types = getToolByName(self.context, 'portal_types')

        keywords = []
        for k in 'keywords', 'local_keywords', 'manual_keywords':
            d = data.get(k, None)
            if d:
                [keywords.append(i) for i in d if i not in keywords]
        keywords.sort()

        ctbrs = data['contributors']
        if isinstance(ctbrs, basestring):
            ctbrs = [a.strip() for a in ctbrs.splitlines() if a.strip()]
        if isinstance(ctbrs, (list, tuple)):
            ctbrs = [a for a in ctbrs if a.strip()]

        rights = data['rights']
        if isinstance(rights, basestring) and rights.strip():
            rights = rights.strip()
        else:
            rights = None

        overwrite = data['overwrite']
        exclude_from_nav = data['exclude_from_nav']
        allow_discussion = data['allow_discussion']
        for item in data['selected_obj_paths']:
            changed = False
            if allow_discussion is not None:
                try:
                    ifc = IAllowDiscussion(item)
                    ifc.allow_discussion = allow_discussion
                    changed = True
                except TypeError:
                    # does not handle for now AT based content
                    # try at
                    try:
                        done = False
                        try:
                            item.allowDiscussion(allow_discussion)
                            done = True
                        except ConflictError:
                            raise
                        except Exception:
                            pass
                        try:
                            item.editIsDiscussable(allow_discussion)
                            done = True
                        except ConflictError:
                            raise
                        except Exception:
                            pass
                        if done:
                            item.reindexObject()
                            changed = True
                    except AttributeError:
                        pass
            if exclude_from_nav is not None:
                try:
                    ifc = IExcludeFromNavigation(item)
                    ifc.exclude_from_nav = exclude_from_nav
                    changed = True
                except TypeError:
                    # does not handle for now AT based content
                    # try at
                    try:
                        item.setExcludeFromNav(exclude_from_nav)
                        item.reindexObject()
                        changed = True
                    except AttributeError:
                        pass
            if (ctbrs or rights) and (data['handle_rights'] or data['handle_contributors']):
                try:
                    ownership = IOwnership(item)
                    if rights and data['handle_rights']:
                        ownership.rights = rights
                        changed = True
                    if ctbrs and data['handle_contributors']:
                        if ownership.contributors and not overwrite:
                            for i in ownership.contributors:
                                if i not in ctbrs:
                                    ctbrs.insert(0, i)
                        ownership.contributors = tuple(ctbrs)
                        changed = True
                except TypeError:
                    # does not handle for now AT based content
                    if ctbrs and data['handle_contributors']:
                        # try at
                        try:
                            if item.Contributors() and not overwrite:
                                for i in item.Contributors():
                                    if i not in ctbrs:
                                        ctbrs.insert(0, i)
                            item.setContributors(tuple(ctbrs))
                            changed = True
                        except AttributeError:
                            pass
                    if rights and data['handle_rights']:
                        try:
                            item.Rights
                            item.setRights(rights)
                            changed = True
                        except AttributeError:
                            pass
            ppath = '/'.join(item.getPhysicalPath())
            if data['related_obj_paths'] and data['handle_related']:
                # item support related items
                related = []
                # archetypes
                try:
                    related = item.getRelatedItems()

                    def additem(xxx, related):
                        changed = False
                        xxx = [x for x in xxx if x not in related]
                        if xxx:
                            item.setRelatedItems(related + xxx)
                            changed = True
                        return changed
                except ConflictError:
                    raise
                except Exception:
                    additem = None
                # dexterity
                if not additem:
                    try:
                        related = BIRelatedItems(item).relatedItems

                        def additem(xxx, related):
                            changed = False
                            xxx = [x for x in xxx if x not in related]
                            if True or xxx:
                                intids = component.getUtility(IIntIds)
                                BIRelatedItems(item).relatedItems = (
                                    [RelationValue(intids.getId(obj))
                                     for obj in (related + xxx)])
                                changed = True
                            return changed
                    except ConflictError:
                        raise
                    except Exception:
                        additem = None
                if additem is not None:
                    changed = additem(data['related_obj_paths'], related)
            try:
                oldk = [a for a in self.context.Subject()]
            except ConflictError:
                raise
            except Exception:
                oldk = []
            oldk.sort()
            if (keywords != oldk) and data['handle_keywords']:
                try:
                    try:
                        if item.Subject() and not overwrite:
                            for val in item.Subject():
                                if val not in keywords:
                                    keywords.insert(0, val)
                        item.setSubject(keywords)
                        changed = True
                    except AttributeError:
                        if item.subject and not overwrite:
                            for val in item.subject:
                                if val not in keywords:
                                    keywords.insert(0, val)
                        item.subject = keywords
                        changed = True
                except ConflictError:
                    raise
                except Exception:
                    trace = traceback.format_exc()
                    msg = ('<li>%s %s: cant change keywords '
                           '<br/><pre>%s</pre>\n</li>') % (
                              ppath, keywords, trace)
                    logger.error(msg)
                    ilogs.append(msg)

            if data['handle_text_replace']:
                if self.replace_text(
                        item=item,
                        mode=data['text_replace_mode'],
                        fields=data['text_replace_fields'],
                        destination=data['text_replace_destination'],
                        source=data['text_replace_source']):
                    changed = True

            if data['handle_views']:
                view = data['view']
                if view and view in portal_types[item.portal_type].view_methods:
                    item.setLayout(view)
                    changed = True

            if data['handle_richtext_format']:
                format = data['richtext_format']
                if format:
                    field = item.getField('text')
                    field.set(item, item.getRawText(), mimetype=format)
                    changed = True

            if changed:
                ilogs.append('<li><a href="%s" target="_new">%s</a> changed</li>\n' % (
                    ppath, item.absolute_url()))
                item.reindexObject()
        if ilogs:
            ilogs.insert(0, u"<strong>MassChange complete</strong>")
            ilogs.insert(0, u"<ul>")
            ilogs.append('</ul>')
        self.logs.extend(ilogs)
        self.logs = '\n'.join(self.logs)
Ejemplo n.º 29
0
 def test_exclude_from_nav_default(self):
     behavior = IExcludeFromNavigation(self.agenda)
     self.assertFalse(behavior.exclude_from_nav)
Ejemplo n.º 30
0
 def test_exclude_from_nav(self):
     self.assertTrue(IExcludeFromNavigation.providedBy(self.agenda))
Ejemplo n.º 31
0
 def test_exclude_from_nav_behavior(self):
     self.assertFalse(IExcludeFromNavigation.providedBy(self.agendadiaria))
 def test_exclude_from_navigation_behavior(self):
     self.assertTrue(IExcludeFromNavigation.providedBy(self.office))
Ejemplo n.º 33
0
 def test_exclude_from_navigation_behavior(self):
     from plone.app.dexterity.behaviors.exclfromnav import IExcludeFromNavigation
     self.assertTrue(IExcludeFromNavigation.providedBy(self.infographic))