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 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.º 3
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.º 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
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())
Ejemplo n.º 7
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()
Ejemplo n.º 8
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 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
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 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.º 15
0
            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:
            found = True
Ejemplo n.º 16
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 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))